Ejemplo n.º 1
0
        public static void LambdaSerializer__Passes_through()
        {
            // Arrange
            var property1 = A.Dummy<string>();
            var property2 = A.Dummy<string>();
            var property3 = A.Dummy<string>();

            var expected = "{"
                           + Environment.NewLine
                           + Invariant($"  \"property1\": \"{property1}\",") + Environment.NewLine
                           + Invariant($"  \"property2\": \"{property2}\",") + Environment.NewLine
                           + Invariant($"  \"property3\": \"{property3}\",") + Environment.NewLine
                           + "  \"property4\": null" + Environment.NewLine
                           + "}";

            var test = new TestObjectForLambda { Property1 = property1, Property2 = property2, Property3 = property3, };
            var backingSerializer = new ObcJsonSerializer();
            var serializer = new ObcLambdaBackedSerializer(
                backingSerializer.SerializeToString,
                backingSerializer.Deserialize,
                backingSerializer.SerializeToBytes,
                backingSerializer.Deserialize);

            // Act
            var stringOut = serializer.SerializeToString(test);
            var stringRoundTrip = serializer.Deserialize(stringOut, test.GetType());
            var bytesOut = serializer.SerializeToBytes(stringRoundTrip);
            var bytesRoundTrip = serializer.Deserialize(bytesOut, stringRoundTrip.GetType());
            var actual = backingSerializer.SerializeToString(bytesRoundTrip);

            // Assert
            actual.Should().Be(expected);
            stringOut.Should().Be(expected);
        }
        public static void ObcJsonSerializer___With_type_Compact___Uses_compact()
        {
            // Arrange
            var property1 = A.Dummy <string>();
            var property2 = A.Dummy <string>();
            var property3 = A.Dummy <string>();

            var expected = "{"
                           + Invariant($"\"property1\":\"{property1}\",")
                           + Invariant($"\"property2\":\"{property2}\",")
                           + Invariant($"\"property3\":\"{property3}\",")
                           + "\"property4\":null"
                           + "}";

            var test = new TestObject {
                Property1 = property1, Property2 = property2, Property3 = property3,
            };
            var serializer = new ObcJsonSerializer <CompactFormatJsonSerializationConfiguration <NullJsonSerializationConfiguration> >();

            // Act
            var actual = serializer.SerializeToString(test);

            // Assert
            actual.Should().Be(expected);
        }
Ejemplo n.º 3
0
        public static void Serialize___Should_serialize_anonymous_object_using_same_settings_as_non_anonymous_object___When_called()
        {
            // Arrange
            var serializer = new ObcJsonSerializer(typeof(AttemptOnUnregisteredTypeJsonSerializationConfiguration <TypesToRegisterJsonSerializationConfiguration <TestBaseModel> >).ToJsonSerializationConfigurationType());

            var model = new
            {
                AnonymousProperty = new TestBaseModel[]
                {
                    new TestDerivedModel
                    {
                        DateTimeProperty = new DateTime(2020, 4, 8, 13, 43, 52, 101, DateTimeKind.Utc),
                        TestEnum         = TestEnum.Second,
                    },
                },
            };

            var expected = "{\r\n  \"anonymousProperty\": [\r\n    {\r\n      \"dateTimeProperty\": \"2020-04-08T13:43:52.1010000Z\",\r\n      \"testEnum\": \"second\",\r\n      \"$concreteType\": \"OBeautifulCode.Serialization.Json.Test.AnonymousObjectsTest+TestDerivedModel, OBeautifulCode.Serialization.Json.Test\"\r\n    }\r\n  ]\r\n}";

            // Act
            var actual = serializer.SerializeToString(model);

            // Assert
            actual.AsTest().Must().BeEqualTo(expected);
        }
Ejemplo n.º 4
0
        public void TestConfigStreamBuilding()
        {
            var localStreamName = "MyStream";
            var x = new SqlServerStreamConfig(
                localStreamName,
                StreamAccessKinds.Read,
                TimeSpan.FromSeconds(30),
                TimeSpan.FromSeconds(30),
                new SerializerRepresentation(
                    SerializationKind.Bson,
                    typeof(SqlServerBsonSerializationConfiguration).ToRepresentation().RemoveAssemblyVersions()),
                SerializationFormat.String,
                new[]
            {
                new SqlServerLocator("localhost", "MyDatabase", "user", "password"),
            });
            var serializer = new ObcJsonSerializer(typeof(SqlServerJsonSerializationConfiguration).ToJsonSerializationConfigurationType());
            var output     = serializer.SerializeToString(x);

            var stream = Config.GetByName <SqlServerStreamConfig>(
                localStreamName,
                new SerializerRepresentation(
                    SerializationKind.Json,
                    typeof(SqlServerJsonSerializationConfiguration).ToRepresentation()),
                SerializerFactory.Instance)
                         .ToStream(SerializerFactory.Instance);

            stream.MustForTest().NotBeNull().And().BeOfType <SqlStream>();
        }
Ejemplo n.º 5
0
        public static void LogConfigurationTimeSliced___Can___Deserialize()
        {
            // Arrange
            var input = @"
                 {
                     ""timeSlicePerFile"": ""00:01:00"",
                     ""fileNamePrefix"": ""Log"",
                     ""logFileDirectoryPath"": ""D:\\Logs"",
                     ""createDirectoryStructureIfMissing"": true,
                     ""logInclusionKindToOriginsMap"": {
                          ""String"": null,
                          ""Object"": null,
                          ""Exception"": null,
                     },
                     ""logItemPropertiesToIncludeInLogMessage"": ""default""
                 }";

            var serializer = new ObcJsonSerializer <LoggingJsonSerializationConfiguration>();

            // Act
            var result = serializer.Deserialize <LogWriterConfigBase>(input);

            // Assert
            var typed = (TimeSlicedFilesLogConfig)result;

            typed.LogFileDirectoryPath.Should().Be("D:\\Logs");
            typed.TimeSlicePerFile.Should().Be(TimeSpan.FromMinutes(1));
            typed.FileNamePrefix.Should().Be("Log");
            typed.CreateDirectoryStructureIfMissing.Should().BeTrue();
            typed.LogInclusionKindToOriginsMapFriendlyString.Should().Be("String=NULL,Object=NULL,Exception=NULL");
        }
Ejemplo n.º 6
0
        public static void Presence_of_concreteType_token_does_not_interfere_with_normal_deserialization()
        {
            // Arrange
            var expectedId            = "year-field";
            var expectedDecimalPlaces = 5;
            var expectedTitle         = "my-title";

            var year = new YearField(expectedId)
            {
                NumberOfDecimalPlaces = expectedDecimalPlaces,
                Title = expectedTitle,
            };

            var serializer = new ObcJsonSerializer(typeof(TypesToRegisterJsonSerializationConfiguration <Field>).ToJsonSerializationConfigurationType());

            var jsonWithConcreteType = serializer.SerializeToString(year);

            var settings = new NullJsonSerializationConfiguration().BuildJsonSerializerSettings(SerializationDirection.Deserialize, (JsonSerializationConfigurationBase)serializer.SerializationConfiguration);

            settings.Converters = new JsonConverter[0];

            // Act
            var actual = JsonConvert.DeserializeObject <YearField>(jsonWithConcreteType, settings);

            // Assert
            typeof(YearField).IsAssignableTo(typeof(Field)).Should().BeTrue();
            jsonWithConcreteType.Should().Contain("$concreteType");
            actual.Id.Should().Be(expectedId);
            actual.NumberOfDecimalPlaces.Should().Be(expectedDecimalPlaces);
            actual.Title.Should().Be(expectedTitle);
        }
        public static void ObcJsonSerializer___With_type_Default___Uses_default()
        {
            // Arrange
            var property1 = A.Dummy <string>();
            var property2 = A.Dummy <string>();
            var property3 = A.Dummy <string>();

            var expected = "{"
                           + Environment.NewLine
                           + Invariant($"  \"property1\": \"{property1}\",") + Environment.NewLine
                           + Invariant($"  \"property2\": \"{property2}\",") + Environment.NewLine
                           + Invariant($"  \"property3\": \"{property3}\",") + Environment.NewLine
                           + "  \"property4\": null" + Environment.NewLine
                           + "}";

            var test = new TestObject {
                Property1 = property1, Property2 = property2, Property3 = property3,
            };
            var serializer = new ObcJsonSerializer();

            // Act
            var actual = serializer.SerializeToString(test);

            // Assert
            actual.Should().Be(expected);
        }
Ejemplo n.º 8
0
        public static void Serializer_deserialize_partial_InheritedTypes()
        {
            var serializedValue = "[" + Environment.NewLine +
                                  "  {" + Environment.NewLine +
                                  "    \"diet\": {\r\n    \"maxCalories\": 50000,\r\n    \"$concreteType\": \"OBeautifulCode.Serialization.Json.Test.JsonSerializationConfigurationTest+LowCalorie, OBeautifulCode.Serialization.Json.Test\"\r\n  }," + Environment.NewLine +
                                  "    \"int32\": 5" + Environment.NewLine +
                                  "  }," + Environment.NewLine +
                                  "  {" + Environment.NewLine +
                                  "    \"int32\": 55," + Environment.NewLine +
                                  "    \"float\": 3.56" + Environment.NewLine +
                                  "  }" + Environment.NewLine +
                                  "]";

            var result = new ObcJsonSerializer(typeof(BaseInterfaceJsonSerializationConfiguration).ToJsonSerializationConfigurationType()).Deserialize <IBaseInterface[]>(serializedValue);

            result.Length.Should().Be(2);

            result[0].Diet.Should().BeOfType <LowCalorie>();
            ((LowCalorie)result[0].Diet).MaxCalories.Should().Be(50000);
            (result[0] as InheritedType3).Should().NotBeNull();
            (result[0] as InheritedType3).Int32.Should().Be(5);
            (result[0] as InheritedType3).Float.Should().Be(default(float));
            result[1].Diet.Should().BeNull();
            (result[1] as InheritedType3).Should().NotBeNull();
            (result[1] as InheritedType3).Int32.Should().Be(55);
            Math.Round((result[1] as InheritedType3).Float, 2).Should().Be(Math.Round(3.56, 2));
        }
Ejemplo n.º 9
0
        public static void Serializer_deserialize_empty_json_into_the_only_child_type_that_has_a_default_constructor()
        {
            var atkinsJson = "{}";

            var atkins = new ObcJsonSerializer(typeof(DietJsonSerializationConfiguration).ToJsonSerializationConfigurationType()).Deserialize <Diet>(atkinsJson) as Atkins;

            atkins.Should().NotBeNull();
        }
        public static void SerializeObject_without_type_serializes_to_json_using_MinimalSerializerSettings()
        {
            // If Minimal is being used then the null Nickname property won't be serialized
            var dog = new Dog(5, "spud", FurColor.Brindle);

            var json = new ObcJsonSerializer(typeof(MinimalFormatJsonSerializationConfiguration <AnimalJsonSerializationConfiguration>).ToJsonSerializationConfigurationType()).SerializeToString(dog);

            json.Should().Be("{\"name\":\"spud\",\"furColor\":\"brindle\",\"dogTag\":\"my name is spud\",\"age\":5}");
        }
Ejemplo n.º 11
0
        public static void TestBase()
        {
            var serializer = new ObcJsonSerializer(typeof(TypesToRegisterJsonSerializationConfiguration <TestBase>).ToJsonSerializationConfigurationType());
            var tasks      = Enumerable.Range(1, 100).Select(_ => A.Dummy <TestBase>())
                             .Select(_ => new Task(() => serializer.SerializeToString(_))).ToArray();

            Parallel.ForEach(tasks, _ => _.Start());
            Task.WaitAll(tasks);
        }
Ejemplo n.º 12
0
        public static void File_exists__Gets_deserialized()
        {
            // Arrange
            var expected = new Contains
            {
                Property = new DerivedProperty
                {
                    PropertyOnBase    = "propBase",
                    PropertyOnDerived = "propDerived",
                },
            };

            var configurationSerializerRepresentation = new SerializerRepresentation(SerializationKind.Json, typeof(PropertyJsonConfig).ToRepresentation());
            var serializer   = new ObcJsonSerializer(typeof(PropertyJsonConfig).ToJsonSerializationConfigurationType());
            var expectedJson = serializer.SerializeToString(expected);

            // Act - Method specified serialization.
            Config.Reset();
            var actualViaParameterMethodSpecific     = Config.Get(expected.GetType(), configurationSerializerRepresentation);
            var actualJsonViaParameterMethodSpecific = serializer.SerializeToString(actualViaParameterMethodSpecific);
            var actualViaGenericMethodSpecific       = Config.Get(expected.GetType(), configurationSerializerRepresentation);
            var actualJsonViaGenericMethodSpecific   = serializer.SerializeToString(actualViaGenericMethodSpecific);

            // Act - Default via type parameter.
            var exceptionGet = Record.Exception(() =>
            {
                Config.Reset();
                return(Config.Get(expected.GetType()));
            });

            // Act - Default via generic call.
            var exceptionGetGeneric = Record.Exception(() =>
            {
                Config.Reset();
                return(Config.Get <Contains>());
            });

            // Act - Global specified
            Config.Reset();
            Config.SetSerialization(configurationSerializerRepresentation);
            var actualViaParameterGlobal     = Config.Get(expected.GetType());
            var actualJsonViaParameterGlobal = serializer.SerializeToString(actualViaParameterGlobal);
            var actualViaGenericGlobal       = Config.Get <Contains>();
            var actualJsonViaGenericGlobal   = serializer.SerializeToString(actualViaGenericGlobal);

            // Assert
            exceptionGet.Should().NotBeNull();
            exceptionGet.InnerException.Should().NotBeNull();
            exceptionGet.InnerException.Message.Should().StartWith("Could not create an instance of type Naos.Configuration.Test.IBase. Type is an interface or abstract class and cannot be instantiated.");
            exceptionGetGeneric.Should().NotBeNull();
            exceptionGetGeneric.Message.Should().StartWith("Could not create an instance of type Naos.Configuration.Test.IBase. Type is an interface or abstract class and cannot be instantiated.");
            actualJsonViaParameterMethodSpecific.Should().Be(expectedJson);
            actualJsonViaGenericMethodSpecific.Should().Be(expectedJson);
            actualJsonViaParameterGlobal.Should().Be(expectedJson);
            actualJsonViaGenericGlobal.Should().Be(expectedJson);
        }
        public static void RootFirstWorks()
        {
            var middleSerializer = new ObcJsonSerializer(typeof(ConfigMiddle).ToJsonSerializationConfigurationType());

            middleSerializer.SerializeToString(null);

            var topSerializer = new ObcJsonSerializer(typeof(ConfigTop).ToJsonSerializationConfigurationType());

            topSerializer.SerializeToString(null);
        }
Ejemplo n.º 14
0
        public static void Serializer_serializes_TwoWay_bindable_type_that_embeds_a_OneWay_bindable_type_using_specified_serializer()
        {
            var whale = new Whale("willy", new LowCalorie(50000));

            var expectedWhaleJson = Invariant($"{{\r\n  \"name\": \"willy\",\r\n  \"diet\": {{\r\n    \"maxCalories\": 50000,\r\n    \"$concreteType\": \"OBeautifulCode.Serialization.Json.Test.JsonSerializationConfigurationTest+LowCalorie, OBeautifulCode.Serialization.Json.Test\"\r\n  }},\r\n  \"$concreteType\": \"OBeautifulCode.Serialization.Json.Test.JsonSerializationConfigurationTest+Whale, OBeautifulCode.Serialization.Json.Test\"\r\n}}");

            var actualWhaleJson = new ObcJsonSerializer(typeof(SeaCreatureJsonSerializationConfiguration).ToJsonSerializationConfigurationType()).SerializeToString(whale);

            actualWhaleJson.Should().Be(expectedWhaleJson);
        }
Ejemplo n.º 15
0
        public static void Serializer_deserialize_into_concrete_type_where_multiple_inherited_types_have_the_same_properties_and_abstract_type_is_marked_TwoWay_bindable()
        {
            var salmonJson = "{\r\n  \"color\": \"brown\",\r\n  \"size\": \"medium\",\r\n  \"$concreteType\": \"OBeautifulCode.Serialization.Json.Test.JsonSerializationConfigurationTest+Salmon, OBeautifulCode.Serialization.Json.Test\"\r\n}";

            var salmon = new ObcJsonSerializer(typeof(SeaCreatureJsonSerializationConfiguration).ToJsonSerializationConfigurationType()).Deserialize <Salmon>(salmonJson);

            salmon.Should().NotBeNull();
            salmon.Color.Should().Be("brown");
            salmon.Size.Should().Be(SeaCreatureSize.Medium);
        }
Ejemplo n.º 16
0
        public static void Serializer_deserialize_camel_cased_properties()
        {
            var serializedValue = "{" + Environment.NewLine +
                                  "  \"testName\": \"there\"" + Environment.NewLine +
                                  "}";

            var result = new ObcJsonSerializer().Deserialize <CamelCasedPropertyTest>(serializedValue);

            result.TestName.Should().Be("there");
        }
Ejemplo n.º 17
0
        public static void Serializer_deserialize_type_where_constructor_does_not_throw_exception_when_another_candidate_has_constructor_that_does_throw_exception()
        {
            var sometimesThrowsJson = "{\"triggerNumber\":123456}";

            var doesNotThrow =
                new ObcJsonSerializer(typeof(TypesToRegisterJsonSerializationConfiguration <SometimesThrows>).ToJsonSerializationConfigurationType()).Deserialize <SometimesThrows>(sometimesThrowsJson) as DoesNotThrow;

            doesNotThrow.Should().NotBeNull();
            doesNotThrow.TriggerNumber.Should().Be(123456);
        }
Ejemplo n.º 18
0
        public static void Serializer_deserialize_type_where_constructor_parameter_is_different_type_than_corresponding_property_but_is_assignable_from_that_property_type()
        {
            var familyJson = "{\"firstNames\": [\"joe\",\"jane\",\"jackie\"]}";

            var family             = new ObcJsonSerializer(typeof(TypesToRegisterJsonSerializationConfiguration <Family>).ToJsonSerializationConfigurationType()).Deserialize <Family>(familyJson);
            var expectedFirstNames = new[] { "joe", "jane", "jackie" };

            family.Should().NotBeNull();
            expectedFirstNames.Should().BeEquivalentTo(family.FirstNames);
        }
        public static void DeserializeObject_with_type_deserialize_json_using_MinimalSerializerSettings()
        {
            // If Minimal is being used then empty JSON string will deserialize into NoLighting
            // otherwise, out-of-the-box json.net will create an anonymous object
            var lightingJson = "{}";

            var lighting = new ObcJsonSerializer(typeof(MinimalFormatJsonSerializationConfiguration <LightingJsonSerializationConfiguration>).ToJsonSerializationConfigurationType()).Deserialize(lightingJson, typeof(Lighting)) as NoLighting;

            lighting.Should().NotBeNull();
        }
Ejemplo n.º 20
0
        public static void Serializer_deserialize_camel_cased_enumerations()
        {
            var serializedValue = "{" + Environment.NewLine +
                                  "  \"value\": \"secondOption\"" + Environment.NewLine +
                                  "}";

            var result = new ObcJsonSerializer().Deserialize <CamelCasedEnumTest>(serializedValue);

            result.Value.Should().Be(TestEnum.SecondOption);
        }
Ejemplo n.º 21
0
        public static void Serializer_serializes_OneWay_bindable_type_that_embeds_a_TwoWay_bindable_type_using_specified_serializer()
        {
            var seafoodDiet = new SeafoodDiet(new Salmon(SeaCreatureSize.Medium, "red"), 345);

            var expectedSeafoodDietJson = Invariant($"{{\r\n  \"seaCreature\": {{\r\n    \"color\": \"red\",\r\n    \"size\": \"medium\",\r\n    \"$concreteType\": \"OBeautifulCode.Serialization.Json.Test.JsonSerializationConfigurationTest+Salmon, OBeautifulCode.Serialization.Json.Test\"\r\n  }},\r\n  \"amount\": 345,\r\n  \"$concreteType\": \"OBeautifulCode.Serialization.Json.Test.JsonSerializationConfigurationTest+SeafoodDiet, OBeautifulCode.Serialization.Json.Test\"\r\n}}");

            var actualSeafoodDietJson = new ObcJsonSerializer(typeof(SeaCreatureJsonSerializationConfiguration).ToJsonSerializationConfigurationType()).SerializeToString(seafoodDiet);

            actualSeafoodDietJson.Should().Be(expectedSeafoodDietJson);
        }
Ejemplo n.º 22
0
        public static void Serializer_serializes_TwoWay_bindable_type_that_embeds_a_TwoWay_bindable_type_using_specified_serializer()
        {
            var tuna  = new Tuna(SeaCreatureSize.Medium, "black");
            var shark = new Shark("sammy", tuna);

            var expectedSharkJson = Invariant($"{{\r\n  \"name\": \"sammy\",\r\n  \"likesToEat\": {{\r\n    \"color\": \"black\",\r\n    \"size\": \"medium\",\r\n    \"$concreteType\": \"OBeautifulCode.Serialization.Json.Test.JsonSerializationConfigurationTest+Tuna, OBeautifulCode.Serialization.Json.Test\"\r\n  }},\r\n  \"$concreteType\": \"OBeautifulCode.Serialization.Json.Test.JsonSerializationConfigurationTest+Shark, OBeautifulCode.Serialization.Json.Test\"\r\n}}");

            var actualSharkJson = new ObcJsonSerializer(typeof(SeaCreatureJsonSerializationConfiguration).ToJsonSerializationConfigurationType()).SerializeToString(shark);

            actualSharkJson.Should().Be(expectedSharkJson);
        }
Ejemplo n.º 23
0
        public static void Serializer_serializes_object_where_constructor_parameter_is_different_type_than_corresponding_property_but_is_assignable_to_the_property_type()
        {
            var friends = new Friends(new List <string> {
                "betty", "bob", "bailey"
            });
            var expectedFriendsJson = "{\r\n  \"firstNames\": [\r\n    \"betty\",\r\n    \"bob\",\r\n    \"bailey\"\r\n  ]\r\n}";

            var actualFriendsJson = new ObcJsonSerializer(typeof(TypesToRegisterJsonSerializationConfiguration <Friends>).ToJsonSerializationConfigurationType()).SerializeToString(friends);

            expectedFriendsJson.Should().Be(actualFriendsJson);
        }
Ejemplo n.º 24
0
        public static void Serializer_serializes_object_where_constructor_parameter_is_different_type_than_corresponding_property_but_is_assignable_from_that_property_type()
        {
            var family = new Family(new List <string> {
                "joe", "jane", "jackie"
            });
            var expectedFamilyJson = "{\r\n  \"firstNames\": [\r\n    \"joe\",\r\n    \"jane\",\r\n    \"jackie\"\r\n  ]\r\n}";

            var actualFamilyJson = new ObcJsonSerializer(typeof(TypesToRegisterJsonSerializationConfiguration <Family>).ToJsonSerializationConfigurationType()).SerializeToString(family);

            expectedFamilyJson.Should().Be(actualFamilyJson);
        }
        public static void SerializeObject_without_type_serializes_to_json_using_DefaultSerializerSettings()
        {
            // If Default is being used then there should be new lines
            var dog = new Dog(5, "spud", FurColor.Brindle);

            var json = new ObcJsonSerializer(typeof(AnimalJsonSerializationConfiguration).ToJsonSerializationConfigurationType()).SerializeToString(dog);

            var expected = Invariant($"{{\r\n  \"name\": \"spud\",\r\n  \"furColor\": \"brindle\",\r\n  \"dogTag\": \"my name is spud\",\r\n  \"nickname\": null,\r\n  \"age\": 5,\r\n  \"$concreteType\": \"OBeautifulCode.Serialization.Json.Test.Dog, OBeautifulCode.Serialization.Json.Test\"\r\n}}");

            json.Should().Be(expected);
        }
        public static void DeserializeObject_without_type_deserialize_json_into_JObject_using_MinimalSerializerSettings()
        {
            var dogJson = "{\"name\":\"Barney\",\"furColor\":\"brindle\",\"age\":10}";

            var dog = new ObcJsonSerializer <MinimalFormatJsonSerializationConfiguration <NullJsonSerializationConfiguration> >().Deserialize <dynamic>(dogJson) as JObject;

            dog.Properties().Count().Should().Be(3);
            dog["name"].ToString().Should().Be("Barney");
            dog["age"].ToString().Should().Be("10");
            dog["furColor"].ToString().Should().Be("brindle");
        }
Ejemplo n.º 27
0
        public static void Serializer_deserialize_inherited_types_when_null_property_is_not_included_in_json()
        {
            var json = "{\"float\":.2,\"int32\":50}";

            var inheritedType3 = new ObcJsonSerializer(typeof(BaseInterfaceJsonSerializationConfiguration).ToJsonSerializationConfigurationType()).Deserialize <IBaseInterface>(json) as InheritedType3;

            inheritedType3.Should().NotBeNull();
            inheritedType3.Int32.Should().Be(50);
            inheritedType3.Float.Should().Be(.2f);
            inheritedType3.Diet.Should().BeNull();
        }
Ejemplo n.º 28
0
        public static void Serializer_deserialize_to_type_having_all_constructor_parameters_in_json_when_another_types_constructor_has_all_the_same_parameters_but_one_additional_one_which_is_not_in_the_json()
        {
            var dogJson = "{\"name\":\"Barney\",\"furColor\":\"brindle\",\"age\":10}";

            var dog = new ObcJsonSerializer(typeof(AnimalJsonSerializationConfiguration).ToJsonSerializationConfigurationType()).Deserialize <Animal>(dogJson) as Dog;

            dog.Should().NotBeNull();
            dog.Name.Should().Be("Barney");
            dog.Age.Should().Be(10);
            dog.FurColor.Should().Be(FurColor.Brindle);
            dog.DogTag.Should().Be("my name is Barney");
        }
Ejemplo n.º 29
0
        public static void Serializer_serializes_and_deserialize_SecureString_types()
        {
            var serializedValue = "{" + Environment.NewLine +
                                  "  \"secure\": \"Password\"" + Environment.NewLine +
                                  "}";

            var deserialized = new ObcJsonSerializer().Deserialize <SecureStringTest>(serializedValue);

            var result = new ObcJsonSerializer().SerializeToString(deserialized);

            result.Should().Be(serializedValue);
        }
Ejemplo n.º 30
0
        public static void Serializer_deserialize_TwoWay_bindable_type_into_abstract_type_when_concrete_type_embeds_a_OneWay_bindable_type_using_specified_serializer()
        {
            var whaleJson = "{\r\n  \"name\": \"willy\",\r\n  \"diet\": {\r\n    \"maxCalories\": 50000\r\n  },\r\n  \"$concreteType\": \"OBeautifulCode.Serialization.Json.Test.JsonSerializationConfigurationTest+Whale, OBeautifulCode.Serialization.Json.Test\"\r\n}";

            var whale = new ObcJsonSerializer(typeof(SeaCreatureJsonSerializationConfiguration).ToJsonSerializationConfigurationType()).Deserialize <SeaCreature>(whaleJson) as Whale;

            whale.Should().NotBeNull();
            whale.Name.Should().Be("willy");
            whale.Diet.Should().NotBeNull();
            whale.Diet.Should().BeOfType <LowCalorie>();
            ((LowCalorie)whale.Diet).MaxCalories.Should().Be(50000);
        }