PageRenderTime 42ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/Source/Bifrost.Specs/Serialization/for_Serializer/when_deserializing_type_with_an_interface_property_and_json_contains_type_reference.cs

#
C# | 22 lines | 17 code | 5 blank | 0 comment | 0 complexity | 0eb5ae8c3869343f5784a596f46fb08a MD5 | raw file
Possible License(s): CC-BY-SA-3.0
  1. using System;
  2. using Machine.Specifications;
  3. namespace Bifrost.Specs.Serialization.for_Serializer
  4. {
  5. public class when_deserializing_type_with_an_interface_property_and_json_contains_type_reference : given.a_serializer
  6. {
  7. const string json = "{\"Something\":{\"$type\":\"Bifrost.Specs.Serialization.for_Serializer.SomethingImplementation, Bifrost.Specs\",\"SomeValue\":\"Something\"}}";
  8. static ClassToSerialize instance;
  9. Establish context = () =>
  10. {
  11. container_mock.Setup(c => c.Get<ClassToSerialize>()).Returns(new ClassToSerialize());
  12. container_mock.Setup(c => c.Get(Moq.It.IsAny<Type>())).Returns((Type t) => Activator.CreateInstance(t));
  13. };
  14. Because of = () => instance = serializer.FromJson<ClassToSerialize>(json);
  15. It should_have_the_property_instance_set_to_instance_of_SomethingImplementation = () => instance.Something.ShouldBeOfType<SomethingImplementation>();
  16. }
  17. }