예제 #1
0
        public static void RegisterClassMapsTypeFullyAutomatic___Type_with_invalid_constraints___Throws()
        {
            // Arrange
            var    configuration = new BsonSerializationConfigurationTestAutoConstrainedType().Setup(typeof(TestMapping), new[] { "monkey" });
            Action action        = () => configuration.RunAutomaticallyBuildBsonClassMapOnSetupTypeAndConstrainedProperties();

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

            // Assert
            exception.Should().NotBeNull();
            exception.Should().BeOfType <ArgumentException>();
            exception.Message.Should().Be("'constrainedPropertyDoesNotExistOnType' is true");
        }
예제 #2
0
        public static void RegisterClassMapsTypeFullyAutomatic___Constrained_null_type___Throws()
        {
            // Arrange
            var    configuration = new BsonSerializationConfigurationTestAutoConstrainedType().Setup(null, new[] { "monkeys" });
            Action action        = () => configuration.RunAutomaticallyBuildBsonClassMapOnSetupTypeAndConstrainedProperties();

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

            // Assert
            exception.Should().NotBeNull();
            exception.Should().BeOfType <ArgumentNullException>();
            exception.Message.Should().Contain("type");
        }
예제 #3
0
        public static void RegisterClassMapsTypeFullyAutomatic___Type_with_valid_constraints___Works()
        {
            // Arrange
            var constraints         = new[] { nameof(TestMapping.GuidProperty), nameof(TestMapping.StringIntMap) };
            var expectedMemberNames = constraints.ToList();
            var configuration       = new BsonSerializationConfigurationTestAutoConstrainedType().Setup(typeof(TestMapping), constraints);

            // Act
            var classMap = configuration.RunAutomaticallyBuildBsonClassMapOnSetupTypeAndConstrainedProperties();

            // Assert
            classMap.Should().NotBeNull();

            classMap.IdMemberMap.Should().BeNull();

            var actualMemberNames = classMap.DeclaredMemberMaps.Select(_ => _.MemberName).OrderBy(_ => _).ToList();

            actualMemberNames.Should().Equal(expectedMemberNames);
        }
예제 #4
0
        public static void RegisterClassMapsTypeFullyAutomatic___Type_with_id_member___Works()
        {
            // Arrange
            var type                = typeof(TestWithId);
            var configuration       = new BsonSerializationConfigurationTestAutoConstrainedType().Setup(type);
            var expectedMemberNames = type.GetMembersToAutomap().Select(_ => _.Name).OrderBy(_ => _).ToList();

            // Act
            var classMap = configuration.RunAutomaticallyBuildBsonClassMapOnSetupTypeAndConstrainedProperties();

            // Assert
            classMap.Should().NotBeNull();

            classMap.IdMemberMap.MemberType.Should().Be(typeof(string));
            classMap.IdMemberMap.MemberName.Should().Be(nameof(TestWithId.Id));

            var actualMemberNames = classMap.DeclaredMemberMaps.Select(_ => _.MemberName).OrderBy(_ => _).ToList();

            actualMemberNames.Should().Equal(expectedMemberNames);
        }