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"); }
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>(); }
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() }
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>(); }
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() }
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(); }
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(); }
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); }
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); }
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'."); }
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[])); }
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."); }
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); }
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(); }
public static void Configure___Valid_type_as_generic___Works() { SerializationConfigurationManager.Configure <TestConfigure>(); TestConfigure.Configured.Should().BeTrue(); }
public static void Configure___Valid_type_as_generic___Works() { SerializationConfigurationManager.GetOrAddSerializationConfiguration(typeof(TestConfigure).ToBsonSerializationConfigurationType()); TestConfigure.Configured.Should().BeTrue(); }