Unit test runs perfectly fine with NUnit but fails when run from TestExplorer

Hello all,
I have a TestProject, Harmony.Tests. In there, I have a method AddApplicationEvent()
which calls another method Send(InvokeRequestMessage requestMessage) which calls a webservice (OperationHandlerBrokerWebService). 
The code snippet looks like this. This is not the complete code but a part where we are calling the web service. It fails on the underlined Italic line of code.
OperationHandlerBrokerWebService brokerService = new OperationHandlerBrokerWebService();
brokerService.UseDefaultCredentials = true;
brokerService.Url = address;
brokerService.Timeout = timeoutInMilliseconds;
byte[] serializedResponseMessage = brokerService.InvokeOperationHandler(serializedRequestMessage);
The same test works and passed fine when I ran it with NUnit, but failed with following exception when I tried to run it from TestExplorer. 
Test Name: AddApplicationEvent
Test FullName: N4S.Harmony.Tests.CaseManagement.HarmonyFacadeTests.AddApplicationEvent
Test Source: d:\TFS\TMW\Dev\TMWOnline\Harmony\N4S.Harmony.Tests\CaseManagement\HarmonyFacadeTests.cs : line 665
Test Outcome: Failed
Test Duration: 0:00:00.296
Result Message:
SetUp : Message returned System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentException: Invalid token for impersonation - it cannot be duplicated.
at System.Security.Principal.WindowsIdentity.CreateFromToken(IntPtr userToken)
at System.Security.Principal.WindowsIdentity..ctor(SerializationInfo info)
at System.Security.Principal.WindowsIdentity..ctor(SerializationInfo info, StreamingContext context)
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle._SerializationInvoke(Object target, SignatureStruct& declaringTypeSig, SerializationInfo info, StreamingContext context)
at System.Reflection.RuntimeConstructorInfo.SerializationInvoke(Object target, SerializationInfo info, StreamingContext context)
at System.Runtime.Serialization.ObjectManager.CompleteISerializableObject(Object obj, SerializationInfo info, StreamingContext context)
at System.Runtime.Serialization.ObjectManager.FixupSpecialObject(ObjectHolder holder)
at System.Runtime.Serialization.ObjectManager.DoFixups()
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream)
at N4S.Forms.OperationHandlerBroker.AMessage.DeserializeMessage(Byte[] serializedMessage)
at N4S.Forms.OperationHandlerBroker.WebServiceServer.BrokerService.InvokeOperationHandler(Byte[] serializedInvokeRequestMessage)
--- End of inner exception stack trace ---
expected: <0>
but was: <1>
Result StackTrace:
at N4S.Harmony.Tests.TestHelper.InvokeOperation(OperationHandler handler, OperationHandlerInput input, Boolean expectedToWork) in d:\TFS\TMW\Dev\TMWOnline\Harmony\N4S.Harmony.Tests\TestHelper.cs:line 136
at N4S.Harmony.Tests.TestHelper.LoginAsUser(String username, String password) in d:\TFS\TMW\Dev\TMWOnline\Harmony\N4S.Harmony.Tests\TestHelper.cs:line 394
at N4S.Harmony.Tests.TestHelper.Login(TestUserName requestedUser) in d:\TFS\TMW\Dev\TMWOnline\Harmony\N4S.Harmony.Tests\TestHelper.cs:line 377
at N4S.Harmony.Tests.TestHelper.LoginAsAdvisor() in d:\TFS\TMW\Dev\TMWOnline\Harmony\N4S.Harmony.Tests\TestHelper.cs:line 230
at N4S.Harmony.Tests.CaseManagement.HarmonyFacadeTests.Login() in d:\TFS\TMW\Dev\TMWOnline\Harmony\N4S.Harmony.Tests\CaseManagement\HarmonyFacadeTests.cs:line 76
at N4S.Harmony.Tests.CaseManagement.HarmonyFacadeTests.SetupTest() in d:\TFS\TMW\Dev\TMWOnline\Harmony\N4S.Harmony.Tests\CaseManagement\HarmonyFacadeTests.cs:line 67
I am not sure what causing the issue. I checked the Credentials, Windows Identity during both the test run and there is no difference. Please advise !!
Thanks,
Deepak

Hi Tina,
Thanks for your reply. 
I do have NUnit adapter installed. I even noticed that the test runs fine with NUnit GUI and also if I run it through Resharper Test Explorer window. 
As you can see in the image above the same test is passed when I ran it from Resharper Unit Test Explorer window but fails when I ran it from Test Explorer window. I also captured the information on fiddler. 
There was a significant difference in the Header Content length. Also under the User-Agent property the protocol versions are different. 
Not sure why VSTest ExecutionEngine is picking a different version.
The UnitTest in question is calling a webservice method which in turn calls a method from another referenced project. 
Web Service class
using System;
using System.Web.Services;
using N4S.Forms.OperationHandlerBroker.Server;
using NLog;
namespace N4S.Forms.OperationHandlerBroker.WebServiceServer
/// <summary>
/// The operaton-handler broker service.
/// </summary>
[WebService(Description = "The N4S Forms Operation-Handler Broker Web-Service.", Name = "OperationHandlerBrokerWebService",
Namespace = "N4S.Forms.OperationHandlerBroker.WebServiceServer")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class BrokerService : WebService
{ /// <summary>
/// Calls <see cref="HandleRequest"/>. Updates performance-counters.
/// </summary>
/// <param name="serializedInvokeRequestMessage">the binary-serialized <see cref="InvokeRequestMessage"/></param>
/// <returns>the binary-serialized response message</returns>
[WebMethod(BufferResponse = true, CacheDuration = 0, Description = "Invokes the requested operation-handler and returns a binary-serialized response-message.", EnableSession = false)]
public byte[] InvokeOperationHandler(byte[] serializedInvokeRequestMessage)
logger.Trace(Strings.TraceMethodEntered);
PerformanceMonitor.RecordRequestStarted();
InvokeRequestMessage requestMessage = (InvokeRequestMessage) AMessage.DeserializeMessage(serializedInvokeRequestMessage);
InvokeResponseMessage responseMessage;
try
responseMessage = HandleRequest(requestMessage);
PerformanceMonitor.RecordSuccessfulRequest();
catch (Exception)
PerformanceMonitor.RecordFailedRequest();
throw;
finally
PerformanceMonitor.RecordRequestEnded();
logger.Trace(Strings.TraceMethodExiting);
return AMessage.SerializeMessage(responseMessage);
UnitTest snippet
OperationHandlerBrokerWebService brokerService = new OperationHandlerBrokerWebService();
brokerService.UseDefaultCredentials = true;
byte[] serializedResponseMessage = brokerService.InvokeOperationHandler(serializedRequestMessage);
Please advise.
Thanks,
Deepak

Similar Messages

  • Can test connection successfully via ODBC adminstrator but fail when I try

    I've loaded the ODBC 10.2 drivers successfully and can successfully setup and test conections via the ODBC Administrator. However, when I try to connect via MS Access I get the following error:
    unable to connect
    sqlstate im004
    [microsoft] [ODBC driver manager] [driver's sqlallochandle on sql_handle_env failed
    Any ideas?
    paul                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    Clear the cache and the cookies from sites that cause problems.
    "Clear the Cache":
    *Tools > Options > Advanced > Network > Cached Web Content: "Clear Now"
    "Remove Cookies" from sites causing problems:
    *Tools > Options > Privacy > Cookies: "Show Cookies"
    *https://support.mozilla.org/kb/how-clear-firefox-cache
    *https://support.mozilla.org/kb/Deleting+cookies

  • Stored procedure runs fine from SSMS but fails when called from the C# app

    I'm using SS Express 2012 so I doubt I have all possible debugging capabilities at my disposal, although I'm still trying to figure this out myself.
    The compiled C# application has logging to insure that the the SP is being invoked, the appropriate line of code is  definitely being reached. The logging always reports 'success' suggesting that the SP was successfully executed (and no exception is thrown
    to the C# app), but the indexes aren't getting rebuilt (I have a fragmentation query proving they are not rebuilt). Yet it runs successfully if I
        (1) set a breakpoint in the C# app and step through the code line by line OR
        (2) run the SP from the SSMS GUI.
    The fragmentation query confirms sucess for both 1 and 2.
    -I can't rely on the GUI because I want to run this overnight immediately after the C# app is finished inserting new records.
    - The SP loops through all the tables, and all the indexes in each table, checking for fragmentation and rebuilding any indexes over 7% fragmented.
    ALTER Procedure [dbo].[usp_RebuildIndexes]
    AS
    Declare @fetch_TableName NVARCHAR(256)
    DECLARE Cursor_Tables CURSOR FOR
    SELECT Name FROM sysobjects WHERE xtype ='U'
    OPEN Cursor_Tables
    While 1 = 1 -- Begin to Loop through all tables
    BEGIN
    FETCH NEXT FROM Cursor_Tables INTO @fetch_TableName -- fetches the next table
    if @@FETCH_STATUS <> 0 break
    print '---------' + @fetch_TableName
    Declare @fetch_indexName NVARCHAR(256) -- loops through al indexes of the current table
    DECLARE Cursor_Indexes CURSOR FOR -- Looking for indexes fragmented more than 7 percent.
    SELECT name as indexName
    FROM sys.dm_db_index_physical_stats (DB_ID(DB_Name()), OBJECT_ID(@fetch_TableName), NULL, NULL, NULL) AS a
    JOIN sys.indexes AS b ON a.object_id = b.object_id AND a.index_id = b.index_id
    Where Name is not null and avg_fragmentation_in_percent > 7
    OPEN Cursor_Indexes
    WHILE 1= 1 -- Begin to Loop through all Indexes
    BEGIN
    FETCH NEXT FROM [Cursor_Indexes] INTO @fetch_indexName
    if @@FETCH_STATUS <> 0 break
    Declare @SqL nvarchar(2000) = N'ALTER INDEX ' + @fetch_indexName + ' ON ' + DB_Name() + '.dbo.' + @fetch_TableName + ' Rebuild'
    print @Sql
    Begin TRy
    Execute sp_executeSQL @sql
    End Try
    Begin Catch
    Declare @err nvarchar(2000) = ERROR_MESSAGE();
    throw 51000, @err, 1
    End Catch
    End -- Ends looping through all indexes
    CLOSE [Cursor_Indexes]
    DEALLOCATE [Cursor_Indexes]
    End -- Ends looping through all tables
    CLOSE Cursor_Tables
    DEALLOCATE Cursor_Tables
    foreach (objDB DB in oUserPrefs.DBs) {
    report += DB.Real_Name;
    if (DB.cn == null) DB.cn = sqlCn(DB.Real_Name, SystemInformation.ComputerName);
    try {
    if (DB.cn.State != ConnectionState.Open) DB.cn.Open();
    } catch (Exception ex) {
    report += " - Failed because can't open a connection.\r\n";
    continue;
    DB.OpenedAConnection = true;
    DataTable dt = null;
    try {
    dt = oParam.fillDt("dbo.usp_RebuildIndexes", DB.cn, null);
    } catch (Exception ex) {
    report += " -failed because " + ex.Message + "\r\n\r\n";
    continue;
    report += " - success.\r\n";
    DB.LastTimeRebuiltIndexes = DateTime.Now;

    Your proc is a bit of a mess and hard to read. This should get you what you need though. I added a little logic in the middle that determines if the index should be reorged, or rebuilt.
    You were right that my script was too messy and I used your code/logic to rewrite mine. Thanks! I tried it this morning and it worked fine, but I will have to see how it runs overnight to be sure.
    Here's the weird thing. My original code should have worked. In fact I'm actually using it in 3 c-sharp apps each of which has 3 to 7  Express 2012 databases (about 10 million records per database). For about a month it's been working fine on two of the
    apps. Furthermore this morning I used a commercial file-comparison tool to verify that the 3rd app has been running an identical version of the SP. So I'm at a total loss as to what went wrong in the 3rd app.
    Here's my rewrite.
    Alter Procedure [dbo].[usp_RebuildIndexes]
    As
    Declare @Messages Table(Msg nvarchar(2000))
    Declare @IndexName nvarchar(256), @TableName NVARCHAR(256)
    DECLARE Cursor_Indexes CURSOR FAST_FORWARD FOR -- GEt a list of all indexes for all tables.
    select idxs.name as indexName, o.Name as TableName
    from sys.indexes idxs
    inner join sysobjects o on idxs.object_id = o.id
    inner join sys.dm_db_index_physical_stats (DB_ID(), NULL, NULL,NULL,NULL) as stats
    on stats.object_id = idxs.object_id and stats.index_id = idxs.index_id
    where xtype = 'u' and idxs.name is not null And avg_fragmentation_in_percent > 7
    OPEN Cursor_Indexes
    While 1 = 1
    BEGIN
    FETCH NEXT FROM Cursor_Indexes INTO @IndexName, @TableName
    if @@FETCH_STATUS <> 0 break
    Declare @SqL nvarchar(2000) = N'ALTER INDEX ' + @IndexName + ' ON ' + DB_Name() + '.dbo.' + @TableName + ' Rebuild'
    insert @Messages(Msg)VALUES(@sql)
    Execute sp_executeSQL @sql
    End
    CLOSE [Cursor_Indexes]
    DEALLOCATE [Cursor_Indexes]
    Select * From @Messages

  • ORA-01843: not a valid month . Receive this error when running report in reporting services but not when running query in BIDS

    sql server 2008 r2
    RS2008 r2
    I can execute the query in BIDS 2008 with out a problem and I can run on our RS2005 server without a problem
    But when I deploy report and run on our RS2008 server I get the error
    An error has occurred during report processing. (rsProcessingAborted)
    Query execution failed for dataset 'NIR'. (rsErrorExecutingCommand)
    ORA-01843: not a valid month 
    QUERY:
    select * from NIR_QUARTERLY where birth_date between :PARAM1 and :PARAM2
    order by PT_CODE

    CAUSE
    The problem is caused by not using VALID dates values in the dataset.
    - This data problem was masked in the original version as the Predicate(s) used can change between versions of Oracle
    - Oracle does *not* guarantee the same explain plan or the specific order of predicates used between versions of Oracle
    Reviewing the  EXPLAIN PLAN for both versions revealed in this case:
    1) The table was partitioned
    2) The EXPLAIN PLANS were not the same due to how the partitions were accessed
    3) If the same query was used against a non-partitioned table using the same data, the following error would always occur
       ORA-01843: not a valid month
    4) The problem string value was in this case found to include the string value of  '0000-00-00'
      The ORA-01843 occurred when using the TO_DATE function against '0000-00-00'
    There is *no* Year= '0000' Month= '00' or day = '00' -- therefore the  ORA-01843: not a valid month
    --Prashanth

  • Hi! Just got my new ihpone 4 yesterday, but i'm having issues in texting a specific contact. sending sms or iMessages works perfectly fine with all my contacts apart from 1,which is even using my same network, though i can call it and receive sms from it.

    Hi! Just got my new ihpone 4 yesterday, but i'm having issues in texting a specific contact. sending sms or iMessages works perfectly fine with all my contacts apart from 1,which is even using my same network, though i can call it and receive sms from it. What could the problem be?

    My Quad is as quiet with 10.4.5 as it was on arrival Jan 31, with 10.4.2
    Altivec Fractal Carbon gives the CPU too much chance to cool down. I've got other ways to drive the CPU to sustained 100% load. Yes, the fans speed up, but it's still pretty quiet. I've run it at 100% for hours.
    I like the idea of taking things gradually. If you can wait a few days before making big changes, it can make things much easier. 3-4 weeks is very conservative, but great if you have that much patience.
    My Quad has been up full-time since I got it. Works perfectly.
    Quad G5 2.5Ghz 4.5GB 2x250G, PB 15" 1.5Ghz,80G,1.5G   Mac OS X (10.4.5)  

  • Running windows 7 with plenty of memory.when i use the smart brush program is fine but when i start to use detail smart brush program shuts down,PLEASE ADVISE

    running windows 7 with plenty of memory.when i use the smart brush program is fine but when i start to use detail smart brush program shuts down,PLEASE ADVISE what corrective actions need done
    thank you

    You should post that on the Boot Camp  forum, that is where all the Boot Camp and Windows guys hang out.
    Good luck.

  • I have a production mobile Flex app that uses RemoteObject calls for all data access, and it's working well, except for a new remote call I just added that only fails when running with a release build.  The same call works fine when running on the device

    I have a production mobile Flex app that uses RemoteObject calls for all data access, and it's working well, except for a new remote call I just added that only fails when running with a release build. The same call works fine when running on the device (iPhone) using debug build. When running with a release build, the result handler is never called (nor is the fault handler called). Viewing the BlazeDS logs in debug mode, the call is received and send back with data. I've narrowed it down to what seems to be a data size issue.
    I have targeted one specific data call that returns in the String value a string length of 44kb, which fails in the release build (result or fault handler never called), but the result handler is called as expected in debug build. When I do not populate the String value (in server side Java code) on the object (just set it empty string), the result handler is then called, and the object is returned (release build).
    The custom object being returned in the call is a very a simple object, with getters/setters for simple types boolean, int, String, and one org.23c.dom.Document type. This same object type is used on other other RemoteObject calls (different data) and works fine (release and debug builds). I originally was returning as a Document, but, just to make sure this wasn't the problem, changed the value to be returned to a String, just to rule out XML/Dom issues in serialization.
    I don't understand 1) why the release build vs. debug build behavior is different for a RemoteObject call, 2) why the calls work in debug build when sending over a somewhat large (but, not unreasonable) amount of data in a String object, but not in release build.
    I have't tried to find out exactly where the failure point in size is, but, not sure that's even relevant, since 44kb isn't an unreasonable size to expect.
    By turning on the Debug mode in BlazeDS, I can see the object and it's attributes being serialized and everything looks good there. The calls are received and processed appropriately in BlazeDS for both debug and release build testing.
    Anyone have an idea on other things to try to debug/resolve this?
    Platform testing is BlazeDS 4, Flashbuilder 4.7, Websphere 8 server, iPhone (iOS 7.1.2). Tried using multiple Flex SDK's 4.12 to the latest 4.13, with no change in behavior.
    Thanks!

    After a week's worth of debugging, I found the issue.
    The Java type returned from the call was defined as ArrayList.  Changing it to List resolved the problem.
    I'm not sure why ArrayList isn't a valid return type, I've been looking at the Adobe docs, and still can't see why this isn't valid.  And, why it works in Debug mode and not in Release build is even stranger.  Maybe someone can shed some light on the logic here to me.

  • LSMW Fails when run in B/G but works fine in Front end..why?

    Hi All,
    i am trying to run a batch process by LSMW, my files are accurate, no problem with them, everything works fine but it fails when run in BG..works absolutely fine in front end. whats the diff with running in B/G?
    same thing happens when i am trying to execute an RFC thru SAP JCO, it works when debugger is on (i guess switching on debugger is similar to running in B/G) but it doesnt work when debugger is off. but when i execute that RFC directly in se37 from SAP gui it works fine..fails when connected to JCO..
    i am not having this issue with r/3 4.6c or mySAP ECC.6.0  i have this issue only in r/3 4.7.
    has anyone faced the similar situtaion? pls help.
    thanks.
    p.s if this may help. the RFC and LSMW error both are pertaining to change in address of US employees.( infotype 0006)

    Applying  SAP note 928273 Solved this issue.

  • I recently got my moms friend old iphone5 that he had for like a month. Everything is fine with it but it wont let me update any of my apps because it asks for his apple ID password. Is there anything i can do to change/fix that?

    I recently got my moms friends old iphone5 that he had for like a month. Everything is fine with it but it wont let me update any of my apps because it asks for his apple ID password. Is there anything i can do to change/fix that?

    sabrinabriii wrote:
    I recently got my moms friends old iphone5 that he had for like a month. Everything is fine with it but it wont let me update any of my apps because it asks for his apple ID password. Is there anything i can do to change/fix that?
    You should remove his AppleID and restore it as new.

  • I'm having an intermittent problem with my midi controllers triggering Mainstage 3. I'm using a PreSonus Firebox audio interface. It's been working fine for months, but now when I first turn on the computer in the morning , I'm not able to trigger Ma

    I’m having an intermittent problem with my midi controllers triggering Mainstage 3.
    I’m using a PreSonus Firebox audio interface.
    It’s been working fine for months, but now when I first turn on the computer in the morning , I’m not able to trigger MainStage from the keyboard.  I tried different midi controllers, different keyboards, different midi cords, and check midi preferences.  The audio interface is working fine and is recogonized, but the midi doesn’twork.  I re-started the computer several times and then finally it miraculously starts working again.
      I’ve been having to this every day now.  Any help or ideas is very much appreciated.

    I Had the same problem with a FireStudio. Try unplugging the FireWire plug and the power plug. Wait for a few seconds, then plug both back in. The light on my FireStudio was flashing blue/red which means "not connecting." I did what I just described, and everything works again. Hope it works for you.

  • Hi! I am having a problem with my dictation. It works fine with Greek but it does not work at all with English. Anyone knows why?

    hi! I am having a problem with my dictation. It works fine with Greek but it does not work at all with English. Anyone knows why?

    Have you changed the system voice to an English one in system preferences?

  • I just installed mongolian cyrillic keyboard and it's working just fine with safari but i can't type on Word with it. please help me?

    i just installed mongolian cyrillic keyboard and it's working just fine with safari but i can't type on Word with it. please help me?

    PS Here is a source for a keyboard.  Try it if you have not done so already
    http://m10lmac.blogspot.com/2012/12/new-mongolian-keyboard-layout.html
    For questions about why Word doesn't do something, try
    http://answers.microsoft.com/en-us/mac/forum/macword

  • My imsg is not working with only one person and her imsg is working perfectly fine with her friends

    My imsg is not working with only one person and her imsg is working perfectly fine with her friends

    See this thread:
    https://discussions.apple.com/thread/5306216?tstart=0
    From Apple:
    MacBook Air (Mid 2013): FaceTime HD Camera might not work after OS X 10.8.5 update
    Yes, a fix is coming soon.

  • What do you do when photos appear on iPhoto fine with preview, but show up back with an explanation point when selected?

    What do you do when photos appear on iPhoto fine with preview, but show up back with an explanation point when selected?

    The ! turns up when iPhoto loses the connection between the thumbnail in the iPhoto Window and the file it represents.
    What version of iPhoto? Assuming 09 or later...
    Option 1
    Back Up and try rebuild the library: hold down the command and option (or alt) keys while launching iPhoto. Use the resulting dialogue to rebuild. Choose to Rebuild iPhoto Library Database from automatic backup.
    If that fails:
    Option 2
    Download iPhoto Library Manager and use its rebuild function. This will create a new library based on data in the albumdata.xml file. Not everything will be brought over - no slideshows, books or calendars, for instance - but it should get all your albums and keywords back.
    Because this process creates an entirely new library and leaves your old one untouched, it is non-destructive, and if you're not happy with the results you can simply return to your old one. .
    Regards
    TD

  • HT1689 I updated my phone to the iOS7 and now when i try to use the keyboard, i can't see myself typing and it goes very slowly. I am confused to why this happened. It worked perfectly fine with iOS6. Any suggestions?

    I updated my phone to the iOS7 and now when i try to use the keyboard, i can't see myself typing and it goes very slowly. I am confused to why this happened. It worked perfectly fine with iOS6. Any suggestions?

    Hi imobl,
    Thanks for your response, I forgot to add that the five 3uk sims we have in use, I have tried all of them none of them are recongnised non of them have pin codes, I even purchased four more sims Tmobile (original carrier) Vodaphone, 3 and giffgaff.

Maybe you are looking for