Ejemplo n.º 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");
        }
Ejemplo n.º 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");
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }