PageRenderTime 6ms CodeModel.GetById 2ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/Source/Bifrost.Specs/Serialization/for_SerializerContractResolver/when_serializing_saga_containing_properties_with_conflicting_names_using_contract_resolver.cs

#
C# | 51 lines | 44 code | 7 blank | 0 comment | 2 complexity | 1e5d8fe01a7fbd86e131caabff171d1f MD5 | raw file
 1using System;
 2using System.IO;
 3using System.Linq;
 4using Bifrost.Fakes.Sagas;
 5using Bifrost.Sagas;
 6using Machine.Specifications;
 7using Newtonsoft.Json;
 8
 9namespace Bifrost.Specs.Serialization.for_SerializerContractResolver
10{
11    public class when_serializing_saga_containing_properties_with_conflicting_names_using_contract_resolver: given.a_serializer_contract_resolver_that_ignores_saga_properties
12    {
13        static string[] saga_properties;
14        static SimpleSagaWithConflictingPropertyNames saga;
15        static string saga_as_json;
16
17        static Guid saga_id = Guid.NewGuid();
18        static Guid conflicting_id = Guid.NewGuid();
19
20
21
22        Establish context = () =>
23                                {
24                                    saga = new SimpleSagaWithConflictingPropertyNames
25                                               {
26                                                   Id = saga_id,
27                                                   SomeOtherThing = new SomeOtherThing() {Id = conflicting_id.ToString()}
28                                               };
29                                    saga_properties = typeof(ISaga).GetProperties().Select(t => t.Name).ToArray();
30                                };
31
32        Because of = () =>
33                         {
34                             using (var stringWriter = new StringWriter())
35                             {
36                                 var serializer = new JsonSerializer
37                                                      {
38                                                          TypeNameHandling = TypeNameHandling.Auto,
39                                                          ContractResolver = contract_resolver
40                                                      };
41                                 serializer.Serialize(stringWriter, saga);
42                                 saga_as_json = stringWriter.ToString();
43                             }
44                         };
45
46        It should_ignore_non_conflicting_properties = () => saga_properties.Where(s => s != "Id").Any(saga_as_json.Contains).ShouldBeFalse();
47        It should_ignore_base_conflicting_property_and_include_on_child = () => saga_properties.Where(s => s == "Id").Any(saga_as_json.Contains).ShouldBeTrue();
48        It should_not_include_guid_property_from_isaga = () => saga_as_json.ShouldContain(conflicting_id.ToString());
49        It should_include_string_property_from_implementation = () => saga_as_json.ShouldContain(conflicting_id.ToString());
50    }
51}