MSpec Json.NET deserialization test does not work in ReSharper, but passes in NCrunch

I have the following two unit tests: one using MSTest and one using machine specifications. As far as I can see, they should behave the same. However, while the former runs in both NCrunch test runners and ReSharper, the latter does not work in ReSharper.

using Machine.Specifications;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;

public class TestModel
{
    public string Name { get; set; }
    public int Number { get; set; }
}

// MSTest
[TestClass]
public class DeserializationTest
{
    [TestMethod]
    public void Deserialized_object_is_the_same_type_as_the_original()
    {
        TestModel testModel = new TestModel() {Name = "John", Number = 42};
        string serialized = JsonConvert.SerializeObject(testModel, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Objects });

        object deserialized = JsonConvert.DeserializeObject(serialized, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Objects });

        // This passes in both test runners
        Assert.IsInstanceOfType(deserialized, typeof(TestModel));
    }
}

// MSpec
public class When_an_object_is_deserialized
{
    static TestModel testModel;
    static string serialized;
    static object deserialized;

    Establish context = () =>
    {
        testModel = new TestModel() { Name = "John", Number = 42 };
        serialized = JsonConvert.SerializeObject(testModel, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Objects });
    };

    Because of = () => deserialized = JsonConvert.DeserializeObject(serialized, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Objects });

    // This passes in NCrunch but fails in ReSharper.
    It should_be_the_same_type_as_the_original = () => Assert.IsInstanceOfType(deserialized, typeof(TestModel));
}

Error message: Assert.IsInstanceOfType failed. Expected type:<UnitTestProject2.TestModel>. Actual type:<UnitTestProject2.TestModel>.Oddly enough, the following:

It should_be_the_same_type_as_the_original = () => Assert.IsTrue(testModel.GetType() == typeof(TestModel));

I am doing deserialization in this way because the actual code in question should be able to process objects of a type unknown before execution. I suppose there is something strange about Json.NET doing such deserialization, but why do the two test runners behave differently? I am using ReSharper 9.1 in Visual Studio 2013.

+4
2

, - NCrunch ReSharper. , , , - , ReSharper NCrunch.

MSpec , deserialized :

deserialized  Cannot fetch the value of field 'deserialized' because information about the containing class is unavailable.   object

, , , , , , . , , . , , , , . , JSON , , , , , .

-, MSpec. NCruch, , - ( ), , , . , - NCrunch , .

- Fusion Log Viewer (fuslogvw.exe) , , .

UPDATE , , JSON . :

*** Assembly Binder Log Entry  (05/06/2015 @ 02:01:38) ***

The operation was successful.
Bind result: hr = 0x0. The operation completed successfully.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
Running under executable  C:\Users\Tim\AppData\Local\JetBrains\Installations\ReSharperPlatformVs12_001\JetBrains.ReSharper.TaskRunner.CLR45.x64.exe
--- A detailed error log follows. 

LOG: IJW explicit bind. File path:c:\users\tim\VS-Projects\StackOverflow\StackOverflow.30643046\bin\Debug\StackOverflow.30643046.dll.
LOG: IJW assembly bind returned a different path: C:\Users\Tim\AppData\Local\Temp\k3dpwn5u.uii\Machine Specifications Runner\assembly\dl3\6c41c492\c7eea8ec_279fd001\StackOverflow.30643046.dll. Use the file provided.

:

*** Assembly Binder Log Entry  (05/06/2015 @ 02:01:38) ***

The operation was successful.
Bind result: hr = 0x0. The operation completed successfully.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
Running under executable  C:\Users\Tim\AppData\Local\JetBrains\Installations\ReSharperPlatformVs12_001\JetBrains.ReSharper.TaskRunner.CLR45.x64.exe
--- A detailed error log follows. 

WRN: The same assembly was loaded into multiple contexts of an application domain:
WRN: Context: Default | Domain ID: 2 | Assembly Name: StackOverflow.30643046, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
WRN: Context: Neither | Domain ID: 2 | Assembly Name: StackOverflow.30643046, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
WRN: This might lead to runtime failures.
WRN: It is recommended to inspect your application on whether this is intentional or not.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.


*** Assembly Binder Log Entry  (05/06/2015 @ 02:04:41) ***

The operation was successful.
Bind result: hr = 0x0. The operation completed successfully.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
Running under executable  C:\Users\Tim\AppData\Local\JetBrains\Installations\ReSharperPlatformVs12_001\JetBrains.ReSharper.TaskRunner.CLR45.x64.exe
--- A detailed error log follows. 

WRN: The same assembly was loaded into multiple contexts of an application domain:
WRN: Context: Default | Domain ID: 2 | Assembly Name: StackOverflow.30643046, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
WRN: Context: Neither | Domain ID: 2 | Assembly Name: StackOverflow.30643046, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
WRN: This might lead to runtime failures.
WRN: It is recommended to inspect your application on whether this is intentional or not.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.


*** Assembly Binder Log Entry  (05/06/2015 @ 02:04:42) ***

The operation was successful.
Bind result: hr = 0x0. The operation completed successfully.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
Running under executable  C:\Users\Tim\AppData\Local\JetBrains\Installations\ReSharperPlatformVs12_001\JetBrains.ReSharper.TaskRunner.CLR45.x64.exe
--- A detailed error log follows. 

WRN: The same assembly was loaded into multiple contexts of an application domain:
WRN: Context: Default | Domain ID: 2 | Assembly Name: StackOverflow.30643046, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
WRN: Context: Neither | Domain ID: 2 | Assembly Name: StackOverflow.30643046, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
WRN: This might lead to runtime failures.
WRN: It is recommended to inspect your application on whether this is intentional or not.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.

, ReSharper unit test " " .

, " ". - , JSON .

2015-06-11

this MSpec, : [machine.specifications] -

+3

@tim-long, ( MSpe# 278) MSpec. ReSharper ( "on").

TypeNameHandling.Objects Json.NET , , TestModel, - MSpec . " : < UnitTestProject2.TestModel > . : < UnitTestProject2.TestModel > ". . # 279, , .

, # 279 .

+3

All Articles