コード例 #1
0
        public static void JsonSerializationConfiguration()
        {
            // Arrange, Act
            var actual = Record.Exception(() => SerializationConfigurationManager.GetOrAddSerializationConfiguration(typeof(TypesToRegisterJsonSerializationConfiguration <string>).ToJsonSerializationConfigurationType()));

            // Assert
            actual.Should().BeOfType <InvalidOperationException>();
            actual.Message.Should().Contain("attempting to register the following type which cannot be registered: string");
        }
コード例 #2
0
        public static void JsonConfigurationBase___With_contract_override___Works()
        {
            // Arrange & Act
            var actual = SerializationConfigurationManager.ConfigureWithReturn <DefaultTestConfiguration>();

            // Assert
            actual.Should().NotBeNull();
            actual.BuildJsonSerializerSettings(SerializationDirection.Serialize).ContractResolver.Should().BeOfType <DefaultContractResolver>();
            actual.BuildJsonSerializerSettings(SerializationDirection.Deserialize).ContractResolver.Should().BeOfType <DefaultContractResolver>();
        }
コード例 #3
0
        public static void JsonConfigurationBase___With_null_implementation___Works()
        {
            // Arrange & Act
            var actual = SerializationConfigurationManager.ConfigureWithReturn <NullJsonConfiguration>();

            // Assert
            actual.Should().NotBeNull();
            actual.BuildJsonSerializerSettings(SerializationDirection.Serialize).ContractResolver.GetType().FullName.Should().Be("Naos.Serialization.Json.CamelStrictConstructorContractResolver");   // this type is not public so we can't use nameof()
            actual.BuildJsonSerializerSettings(SerializationDirection.Deserialize).ContractResolver.GetType().FullName.Should().Be("Naos.Serialization.Json.CamelStrictConstructorContractResolver"); // this type is not public so we can't use nameof()
        }
コード例 #4
0
        public static void JsonSerializationConfigurationBase___With_contract_override___Works()
        {
            // Arrange & Act
            var actual = (DefaultTestConfiguration)SerializationConfigurationManager.GetOrAddSerializationConfiguration(typeof(DefaultTestConfiguration).ToJsonSerializationConfigurationType());

            // Assert
            actual.Should().NotBeNull();
            actual.BuildJsonSerializerSettings(SerializationDirection.Serialize, actual).ContractResolver.Should().BeOfType <DefaultContractResolver>();
            actual.BuildJsonSerializerSettings(SerializationDirection.Deserialize, actual).ContractResolver.Should().BeOfType <DefaultContractResolver>();
        }
コード例 #5
0
        public static void JsonSerializationConfigurationBase___With_null_implementation___Works()
        {
            // Arrange & Act
            var actual = (NullJsonSerializationConfiguration)SerializationConfigurationManager.GetOrAddSerializationConfiguration(typeof(NullJsonSerializationConfiguration).ToJsonSerializationConfigurationType());

            // Assert
            actual.Should().NotBeNull();
            actual.BuildJsonSerializerSettings(SerializationDirection.Serialize, actual).ContractResolver.GetType().FullName.Should().Be("OBeautifulCode.Serialization.Json.CamelStrictConstructorContractResolver");   // this type is not public so we can't use nameof()
            actual.BuildJsonSerializerSettings(SerializationDirection.Deserialize, actual).ContractResolver.GetType().FullName.Should().Be("OBeautifulCode.Serialization.Json.CamelStrictConstructorContractResolver"); // this type is not public so we can't use nameof()
        }
コード例 #6
0
        public static void ElementTypeOfArrayIsOnlyTypeDiscovered()
        {
            // Arrange, Act
            var configured = SerializationConfigurationManager.GetOrAddSerializationConfiguration(typeof(TypesToRegisterJsonSerializationConfiguration <TypeWithObjectArray>).ToJsonSerializationConfigurationType());

            // Assert
            configured.IsRegisteredType(typeof(TypeWithObjectArray)).Should().BeTrue();
            configured.IsRegisteredType(typeof(TypeWithObjectArrayElementType)).Should().BeTrue();
            configured.IsRegisteredType(typeof(TypeWithObjectArrayElementType[])).Should().BeFalse();
        }
コード例 #7
0
        public static void AllTrackedTypeContainers___Post_registration___Returns_fully_loaded_set()
        {
            // Arrange
            var testType   = typeof(TestTracking);
            var configType = typeof(TypesToRegisterBsonSerializationConfiguration <TestTracking>);

            // Act
            var config = SerializationConfigurationManager.GetOrAddSerializationConfiguration(configType.ToBsonSerializationConfigurationType());

            // Assert
            config.IsRegisteredType(testType).Should().BeTrue();
        }
コード例 #8
0
        public static void AllTrackedTypeContainers___Post_registration___Returns_fully_loaded_set()
        {
            // Arrange
            var testType   = typeof(TestTracking);
            var configType = typeof(GenericDiscoveryBsonConfiguration <TestTracking>);

            // Act
            var config = SerializationConfigurationManager.ConfigureWithReturn <BsonConfigurationBase>(configType);

            // Assert
            config.RegisteredTypeToDetailsMap.Keys.Should().Contain(testType);
        }
コード例 #9
0
        public static void Configure___Provided_with_dependent_configs___Configures_dependents()
        {
            void Action() => SerializationConfigurationManager.GetOrAddSerializationConfiguration(typeof(DependsOnCustomThrowsConfig).ToBsonSerializationConfigurationType());

            // Act
            var exception = Record.Exception(Action);

            // Assert
            exception.Should().NotBeNull();
            exception.Should().BeOfType <ArgumentException>();
            exception.Message.Should().Be(CustomThrowsConfig.ExceptionMessage);
        }
コード例 #10
0
        public static void Configure___Type_does_not_have_default_constructor___Throws()
        {
            // Arrange
            Action action = () => SerializationConfigurationManager.Configure(typeof(TestConfigureParameterConstructor));

            // Act
            var exception = Record.Exception(action);

            // Assert
            exception.Should().NotBeNull();
            exception.Should().BeOfType <ArgumentException>();
            exception.Message.Should().Be("Parameter 'typeHasParameterLessConstructor' is not true.  Parameter value is 'False'.");
        }
コード例 #11
0
        public static void ElementTypeOfArrayIsOnlyTypeDiscovered()
        {
            // Arrange
            var config = typeof(NullDiscoverySerializationConfiguration <TypeWithObjectArray>);

            // Act
            var configured = SerializationConfigurationManager.ConfigureWithReturn <NullDiscoverySerializationConfiguration <TypeWithObjectArray> >(config);

            // Assert
            configured.RegisteredTypeToDetailsMap.Keys.Should().Contain(typeof(TypeWithObjectArray));
            configured.RegisteredTypeToDetailsMap.Keys.Should().Contain(typeof(TypeWithObjectArrayElementType));
            configured.RegisteredTypeToDetailsMap.Keys.Should().NotContain(typeof(TypeWithObjectArrayElementType[]));
        }
コード例 #12
0
        public static void Configure___Type_not_BsonConfigurationBase___Throws()
        {
            // Arrange
            Action action = () => SerializationConfigurationManager.Configure(typeof(string));

            // Act
            var exception = Record.Exception(action);

            // Assert
            exception.Should().NotBeNull();
            exception.Should().BeOfType <ArgumentException>();
            exception.Message.Should().Be("Parameter 'typeMustBeSubclassOfSerializationConfigurationBase' is not true.  Parameter value is 'False'.");
        }
        public static void SerializationConfigurationManagerDoesNotAllow()
        {
            // Arrange
            var    config = typeof(SameInheritorJsonConfig);
            Action action = () => SerializationConfigurationManager
                            .Configure(config);

            // Act
            var exception = Record.Exception(action);

            // Assert
            exception.Should().NotBeNull();
            exception.Should().BeOfType <InvalidOperationException>();
            exception.Message.Should().Be("Configuration Naos.Serialization.Test.SameInheritorJsonConfig has DependentConfigurationTypes (Naos.Serialization.Test.SameInheritorBsonConfigA) that do not share the same first layer of inheritance Naos.Serialization.Json.JsonConfigurationBase.");
        }
コード例 #14
0
        public static void Configure___Override_collections___All_types_get_registered_as_expected()
        {
            var expectedTypes = new[]
            {
                typeof(TestConfigureActionBaseFromSub), typeof(TestConfigureActionInheritedSub),
                typeof(TestConfigureActionSingle),
                typeof(TestConfigureActionFromInterface),
                typeof(TestConfigureActionBaseFromAuto), typeof(TestConfigureActionInheritedAuto), typeof(TestConfigureActionFromAuto),
            };

            var configType = typeof(TestVariousTypeOverloadsConfig);

            // Act
            var config = SerializationConfigurationManager.ConfigureWithReturn <SerializationConfigurationBase>(configType);

            // Assert
            config.RegisteredTypeToDetailsMap.Keys.Intersect(expectedTypes).Should().BeEquivalentTo(expectedTypes);
        }
コード例 #15
0
        public static void Configure___Override_collections___All_types_get_registered_as_expected()
        {
            var expectedTypes = new[]
            {
                typeof(TestConfigureActionBaseFromSub),
                typeof(TestConfigureActionInheritedSub),
                typeof(TestConfigureActionSingle),
                typeof(TestConfigureActionFromInterface),
                typeof(TestConfigureActionBaseFromAuto),
                typeof(TestConfigureActionInheritedAuto),
                typeof(TestConfigureActionFromAuto),
            };

            var configType = typeof(TestVariousTypeOverloadsConfig);

            // Act
            var config = SerializationConfigurationManager.GetOrAddSerializationConfiguration(configType.ToBsonSerializationConfigurationType());

            // Assert
            expectedTypes.Select(_ => config.IsRegisteredType(_)).AsTest().Must().Each().BeTrue();
        }
コード例 #16
0
 public static void Configure___Valid_type_as_generic___Works()
 {
     SerializationConfigurationManager.Configure <TestConfigure>();
     TestConfigure.Configured.Should().BeTrue();
 }
コード例 #17
0
 public static void Configure___Valid_type_as_generic___Works()
 {
     SerializationConfigurationManager.GetOrAddSerializationConfiguration(typeof(TestConfigure).ToBsonSerializationConfigurationType());
     TestConfigure.Configured.Should().BeTrue();
 }