コード例 #1
0
        When_asserting_properties_are_decorated_with_attribute_and_they_are_not_it_should_throw_with_descriptive_message()
        {
            //-------------------------------------------------------------------------------------------------------------------
            // Arrange
            //-------------------------------------------------------------------------------------------------------------------
            var propertyInfoSelector = new PropertyInfoSelector(typeof(ClassWithPropertiesThatAreNotDecoratedWithDummyAttribute));

            //-------------------------------------------------------------------------------------------------------------------
            // Act
            //-------------------------------------------------------------------------------------------------------------------
            Action act = () =>
                         propertyInfoSelector.Should()
                         .BeDecoratedWith <DummyPropertyAttribute>("because we want to test the error {0}", "message");

            //-------------------------------------------------------------------------------------------------------------------
            // Assert
            //-------------------------------------------------------------------------------------------------------------------
            act.ShouldThrow <AssertFailedException>()
            .WithMessage("Expected all selected properties to be decorated with" +
                         " FluentAssertions.Specs.DummyPropertyAttribute because we want to test the error message," +
                         " but the following properties are not:\r\n" +
                         "String FluentAssertions.Specs.ClassWithPropertiesThatAreNotDecoratedWithDummyAttribute.PublicProperty\r\n" +
                         "String FluentAssertions.Specs.ClassWithPropertiesThatAreNotDecoratedWithDummyAttribute.InternalProperty\r\n" +
                         "String FluentAssertions.Specs.ClassWithPropertiesThatAreNotDecoratedWithDummyAttribute.ProtectedProperty");
        }
コード例 #2
0
        When_asserting_properties_are_not_decorated_with_attribute_and_they_are_it_should_throw_with_descriptive_message()
        {
            //-------------------------------------------------------------------------------------------------------------------
            // Arrange
            //-------------------------------------------------------------------------------------------------------------------
            var propertyInfoSelector = new PropertyInfoSelector(typeof(ClassWithAllPropertiesDecoratedWithDummyAttribute));

            //-------------------------------------------------------------------------------------------------------------------
            // Act
            //-------------------------------------------------------------------------------------------------------------------
            Action act = () =>
                         propertyInfoSelector.Should()
                         .NotBeDecoratedWith <DummyPropertyAttribute>("because we want to test the error {0}", "message");

            //-------------------------------------------------------------------------------------------------------------------
            // Assert
            //-------------------------------------------------------------------------------------------------------------------
            act.Should().Throw <XunitException>()
            .WithMessage("Expected all selected properties not to be decorated*" +
                         "DummyPropertyAttribute*" +
                         "because we want to test the error message*" +
                         "ClassWithAllPropertiesDecoratedWithDummyAttribute.PublicProperty*" +
                         "ClassWithAllPropertiesDecoratedWithDummyAttribute.InternalProperty*" +
                         "ClassWithAllPropertiesDecoratedWithDummyAttribute.ProtectedProperty*");
        }
コード例 #3
0
            public void When_read_only_properties_are_expected_to_not_be_writable_it_should_not_throw()
            {
                // Arrange
                var propertyInfoSelector = new PropertyInfoSelector(typeof(ClassWithOnlyReadOnlyProperties));

                // Act
                Action action = () => propertyInfoSelector.Should().NotBeWritable();

                // Assert
                action.Should().NotThrow();
            }
コード例 #4
0
            public void When_asserting_properties_are_not_virtual_but_virtual_properties_are_found_it_should_throw()
            {
                // Arrange
                var propertyInfoSelector = new PropertyInfoSelector(typeof(ClassWithAllPropertiesVirtual));

                // Act
                Action act = () =>
                             propertyInfoSelector.Should().NotBeVirtual();

                // Assert
                act.Should().Throw <XunitException>();
            }
コード例 #5
0
            public void When_asserting_properties_are_not_virtual_and_they_are_not_it_should_succeed()
            {
                // Arrange
                var propertyInfoSelector = new PropertyInfoSelector(typeof(ClassWithNonVirtualPublicProperties));

                // Act
                Action act = () =>
                             propertyInfoSelector.Should().NotBeVirtual();

                // Assert
                act.Should().NotThrow();
            }
コード例 #6
0
            public void When_asserting_properties_are_not_decorated_with_attribute_and_they_are_not_it_should_succeed()
            {
                // Arrange
                var propertyInfoSelector = new PropertyInfoSelector(typeof(ClassWithPropertiesThatAreNotDecoratedWithDummyAttribute));

                // Act
                Action act = () =>
                             propertyInfoSelector.Should().NotBeDecoratedWith <DummyPropertyAttribute>();

                // Assert
                act.Should().NotThrow();
            }
コード例 #7
0
        public void When_property_info_selector_is_null_then_should_should_throw()
        {
            // Arrange
            PropertyInfoSelector propertyInfoSelector = null;

            // Act
            Action act = () => propertyInfoSelector.Should();

            // Assert
            act.Should().ThrowExactly <ArgumentNullException>()
            .WithParameterName("propertyInfoSelector");
        }
コード例 #8
0
            public void When_asserting_properties_are_not_decorated_with_attribute_and_they_are_it_should_throw()
            {
                // Arrange
                var propertyInfoSelector = new PropertyInfoSelector(typeof(ClassWithAllPropertiesDecoratedWithDummyAttribute))
                                           .ThatArePublicOrInternal;

                // Act
                Action act = () =>
                             propertyInfoSelector.Should().NotBeDecoratedWith <DummyPropertyAttribute>();

                // Assert
                act.Should().Throw <XunitException>();
            }
コード例 #9
0
        public void When_writeable_properties_are_expected_to_be_writable_it_should_not_throw()
        {
            //-------------------------------------------------------------------------------------------------------------------
            // Arrange
            //-------------------------------------------------------------------------------------------------------------------
            var propertyInfoSelector = new PropertyInfoSelector(typeof(ClassWithOnlyWritableProperties));

            //-------------------------------------------------------------------------------------------------------------------
            // Act
            //-------------------------------------------------------------------------------------------------------------------
            Action action = () => propertyInfoSelector.Should().BeWritable();

            //-------------------------------------------------------------------------------------------------------------------
            // Assert
            //-------------------------------------------------------------------------------------------------------------------
            action.ShouldNotThrow();
        }
コード例 #10
0
            public void When_a_writable_property_is_expected_to_be_read_only_it_should_throw_with_descriptive_message()
            {
                // Arrange
                var propertyInfoSelector = new PropertyInfoSelector(typeof(ClassWithWritableProperties));

                // Act
                Action action = () => propertyInfoSelector.Should().NotBeWritable("because we want to test the error {0}", "message");

                // Assert
                action
                .Should().Throw <XunitException>()
                .WithMessage(
                    "Expected selected properties to not have a setter because we want to test the error message, " +
                    "but the following properties do:*" +
                    "String FluentAssertions*ClassWithWritableProperties.ReadWriteProperty*" +
                    "String FluentAssertions*ClassWithWritableProperties.ReadWriteProperty2");
            }
コード例 #11
0
        public void When_asserting_properties_are_virtual_but_non_virtual_properties_are_found_it_should_throw()
        {
            //-------------------------------------------------------------------------------------------------------------------
            // Arrange
            //-------------------------------------------------------------------------------------------------------------------
            var propertyInfoSelector = new PropertyInfoSelector(typeof(ClassWithNonVirtualPublicProperties));

            //-------------------------------------------------------------------------------------------------------------------
            // Act
            //-------------------------------------------------------------------------------------------------------------------
            Action act = () =>
                propertyInfoSelector.Should().BeVirtual();

            //-------------------------------------------------------------------------------------------------------------------
            // Assert
            //-------------------------------------------------------------------------------------------------------------------
            act.ShouldThrow<AssertFailedException>();
        }
コード例 #12
0
        public void When_asserting_properties_are_decorated_with_attribute_and_they_are_it_should_succeed()
        {
            //-------------------------------------------------------------------------------------------------------------------
            // Arrange
            //-------------------------------------------------------------------------------------------------------------------
            var propertyInfoSelector = new PropertyInfoSelector(typeof(ClassWithAllPropertiesDecoratedWithDummyAttribute));

            //-------------------------------------------------------------------------------------------------------------------
            // Act
            //-------------------------------------------------------------------------------------------------------------------
            Action act = () =>
                propertyInfoSelector.Should().BeDecoratedWith<DummyPropertyAttribute>();

            //-------------------------------------------------------------------------------------------------------------------
            // Assert
            //-------------------------------------------------------------------------------------------------------------------
            act.ShouldNotThrow();
        }
コード例 #13
0
            When_asserting_properties_are_not_virtual_but_virtual_properties_are_found_it_should_throw_with_descriptive_message()
            {
                // Arrange
                var propertyInfoSelector = new PropertyInfoSelector(typeof(ClassWithAllPropertiesVirtual));

                // Act
                Action act = () =>
                             propertyInfoSelector.Should().NotBeVirtual("we want to test the error {0}", "message");

                // Assert
                act.Should().Throw <XunitException>()
                .WithMessage("Expected all selected properties" +
                             " not to be virtual because we want to test the error message," +
                             " but the following properties are virtual*" +
                             "*ClassWithAllPropertiesVirtual.PublicVirtualProperty" +
                             "*ClassWithAllPropertiesVirtual.InternalVirtualProperty" +
                             "*ClassWithAllPropertiesVirtual.ProtectedVirtualProperty");
            }
コード例 #14
0
            When_asserting_properties_are_virtual_but_non_virtual_properties_are_found_it_should_throw_with_descriptive_message()
            {
                // Arrange
                var propertyInfoSelector = new PropertyInfoSelector(typeof(ClassWithNonVirtualPublicProperties));

                // Act
                Action act = () =>
                             propertyInfoSelector.Should().BeVirtual("we want to test the error {0}", "message");

                // Assert
                act.Should().Throw <XunitException>()
                .WithMessage("Expected all selected properties" +
                             " to be virtual because we want to test the error message," +
                             " but the following properties are not virtual:*" +
                             "String FluentAssertions*ClassWithNonVirtualPublicProperties.PublicNonVirtualProperty*" +
                             "String FluentAssertions*ClassWithNonVirtualPublicProperties.InternalNonVirtualProperty*" +
                             "String FluentAssertions*ClassWithNonVirtualPublicProperties.ProtectedNonVirtualProperty");
            }
コード例 #15
0
        public void When_asserting_properties_are_virtual_and_they_are_it_should_succeed()
        {
            //-------------------------------------------------------------------------------------------------------------------
            // Arrange
            //-------------------------------------------------------------------------------------------------------------------
            var propertyInfoSelector = new PropertyInfoSelector(typeof(ClassWithAllPropertiesVirtual));

            //-------------------------------------------------------------------------------------------------------------------
            // Act
            //-------------------------------------------------------------------------------------------------------------------
            Action act = () =>
                propertyInfoSelector.Should().BeVirtual();

            //-------------------------------------------------------------------------------------------------------------------
            // Assert
            //-------------------------------------------------------------------------------------------------------------------
            act.ShouldNotThrow();
        }
コード例 #16
0
        public void When_asserting_properties_are_decorated_with_attribute_and_they_are_it_should_succeed()
        {
            //-------------------------------------------------------------------------------------------------------------------
            // Arrange
            //-------------------------------------------------------------------------------------------------------------------
            var propertyInfoSelector = new PropertyInfoSelector(typeof(ClassWithAllPropertiesDecoratedWithDummyAttribute));

            //-------------------------------------------------------------------------------------------------------------------
            // Act
            //-------------------------------------------------------------------------------------------------------------------
            Action act = () =>
                         propertyInfoSelector.Should().BeDecoratedWith <DummyPropertyAttribute>();

            //-------------------------------------------------------------------------------------------------------------------
            // Assert
            //-------------------------------------------------------------------------------------------------------------------
            act.ShouldNotThrow();
        }
コード例 #17
0
        public void When_asserting_properties_are_virtual_but_non_virtual_properties_are_found_it_should_throw()
        {
            //-------------------------------------------------------------------------------------------------------------------
            // Arrange
            //-------------------------------------------------------------------------------------------------------------------
            var propertyInfoSelector = new PropertyInfoSelector(typeof(ClassWithNonVirtualPublicProperties));

            //-------------------------------------------------------------------------------------------------------------------
            // Act
            //-------------------------------------------------------------------------------------------------------------------
            Action act = () =>
                         propertyInfoSelector.Should().BeVirtual();

            //-------------------------------------------------------------------------------------------------------------------
            // Assert
            //-------------------------------------------------------------------------------------------------------------------
            act.ShouldThrow <AssertFailedException>();
        }
コード例 #18
0
        public void When_asserting_properties_are_virtual_and_they_are_it_should_succeed()
        {
            //-------------------------------------------------------------------------------------------------------------------
            // Arrange
            //-------------------------------------------------------------------------------------------------------------------
            var propertyInfoSelector = new PropertyInfoSelector(typeof(ClassWithAllPropertiesVirtual));

            //-------------------------------------------------------------------------------------------------------------------
            // Act
            //-------------------------------------------------------------------------------------------------------------------
            Action act = () =>
                         propertyInfoSelector.Should().BeVirtual();

            //-------------------------------------------------------------------------------------------------------------------
            // Assert
            //-------------------------------------------------------------------------------------------------------------------
            act.ShouldNotThrow();
        }
コード例 #19
0
        public void When_asserting_properties_are_decorated_with_attribute_and_they_are_not_it_should_throw()
        {
            //-------------------------------------------------------------------------------------------------------------------
            // Arrange
            //-------------------------------------------------------------------------------------------------------------------
            var propertyInfoSelector = new PropertyInfoSelector(typeof(ClassWithPropertiesThatAreNotDecoratedWithDummyAttribute))
                .ThatArePublicOrInternal;

            //-------------------------------------------------------------------------------------------------------------------
            // Act
            //-------------------------------------------------------------------------------------------------------------------
            Action act = () =>
                propertyInfoSelector.Should().BeDecoratedWith<DummyPropertyAttribute>();

            //-------------------------------------------------------------------------------------------------------------------
            // Assert
            //-------------------------------------------------------------------------------------------------------------------
            act.ShouldThrow<AssertFailedException>();
        }
コード例 #20
0
        public void When_asserting_properties_are_decorated_with_attribute_and_they_are_not_it_should_throw()
        {
            //-------------------------------------------------------------------------------------------------------------------
            // Arrange
            //-------------------------------------------------------------------------------------------------------------------
            var propertyInfoSelector = new PropertyInfoSelector(typeof(ClassWithPropertiesThatAreNotDecoratedWithDummyAttribute))
                                       .ThatArePublicOrInternal;

            //-------------------------------------------------------------------------------------------------------------------
            // Act
            //-------------------------------------------------------------------------------------------------------------------
            Action act = () =>
                         propertyInfoSelector.Should().BeDecoratedWith <DummyPropertyAttribute>();

            //-------------------------------------------------------------------------------------------------------------------
            // Assert
            //-------------------------------------------------------------------------------------------------------------------
            act.ShouldThrow <AssertFailedException>();
        }
コード例 #21
0
        public void When_a_read_only_property_is_expected_to_be_writable_it_should_throw_with_descriptive_message()
        {
            //-------------------------------------------------------------------------------------------------------------------
            // Arrange
            //-------------------------------------------------------------------------------------------------------------------
            var propertyInfoSelector = new PropertyInfoSelector(typeof(ClassWithReadOnlyProperties));

            //-------------------------------------------------------------------------------------------------------------------
            // Act
            //-------------------------------------------------------------------------------------------------------------------
            Action action = () => propertyInfoSelector.Should().BeWritable("because we want to test the error {0}", "message");

            //-------------------------------------------------------------------------------------------------------------------
            // Assert
            //-------------------------------------------------------------------------------------------------------------------
            action
            .ShouldThrow <AssertFailedException>()
            .WithMessage(
                "Expected all selected properties to have a setter because we want to test the error message, " +
                "but the following properties do not:\r\n" +
                "String FluentAssertions.Specs.ClassWithReadOnlyProperties.ReadOnlyProperty\r\n" +
                "String FluentAssertions.Specs.ClassWithReadOnlyProperties.ReadOnlyProperty2");
        }
コード例 #22
0
            When_asserting_properties_are_virtual_but_non_virtual_properties_are_found_it_should_throw_with_descriptive_message()
        {
            //-------------------------------------------------------------------------------------------------------------------
            // Arrange
            //-------------------------------------------------------------------------------------------------------------------
            var propertyInfoSelector = new PropertyInfoSelector(typeof(ClassWithNonVirtualPublicProperties));

            //-------------------------------------------------------------------------------------------------------------------
            // Act
            //-------------------------------------------------------------------------------------------------------------------
            Action act = () =>
                propertyInfoSelector.Should().BeVirtual("we want to test the error {0}", "message");

            //-------------------------------------------------------------------------------------------------------------------
            // Assert
            //-------------------------------------------------------------------------------------------------------------------
            act.ShouldThrow<AssertFailedException>()
               .WithMessage("Expected all selected properties" +
                   " to be virtual because we want to test the error message," +
                   " but the following properties are not virtual:\r\n" +
                   "String FluentAssertions.Specs.ClassWithNonVirtualPublicProperties.PublicNonVirtualProperty\r\n" +
                   "String FluentAssertions.Specs.ClassWithNonVirtualPublicProperties.InternalNonVirtualProperty\r\n" +
                   "String FluentAssertions.Specs.ClassWithNonVirtualPublicProperties.ProtectedNonVirtualProperty");
        }
コード例 #23
0
        public void When_a_read_only_property_is_expected_to_be_writable_it_should_throw_with_descriptive_message()
        {
            //-------------------------------------------------------------------------------------------------------------------
            // Arrange
            //-------------------------------------------------------------------------------------------------------------------
            var propertyInfoSelector = new PropertyInfoSelector(typeof(ClassWithReadOnlyProperties));

            //-------------------------------------------------------------------------------------------------------------------
            // Act
            //-------------------------------------------------------------------------------------------------------------------
            Action action = () => propertyInfoSelector.Should().BeWritable("because we want to test the error {0}", "message");

            //-------------------------------------------------------------------------------------------------------------------
            // Assert
            //-------------------------------------------------------------------------------------------------------------------
            action
                .ShouldThrow<AssertFailedException>()
                .WithMessage(
                    "Expected all selected properties to have a setter because we want to test the error message, " +
                    "but the following properties do not:\r\n" +
                    "String FluentAssertions.Specs.ClassWithReadOnlyProperties.ReadOnlyProperty\r\n" +
                    "String FluentAssertions.Specs.ClassWithReadOnlyProperties.ReadOnlyProperty2");
        }
コード例 #24
0
        public void When_asserting_properties_are_decorated_with_attribute_and_they_are_not_it_should_throw_with_descriptive_message()
        {
            //-------------------------------------------------------------------------------------------------------------------
            // Arrange
            //-------------------------------------------------------------------------------------------------------------------
            var propertyInfoSelector = new PropertyInfoSelector(typeof(ClassWithPropertiesThatAreNotDecoratedWithDummyAttribute));

            //-------------------------------------------------------------------------------------------------------------------
            // Act
            //-------------------------------------------------------------------------------------------------------------------
            Action act = () =>
                propertyInfoSelector.Should()
                                    .BeDecoratedWith<DummyPropertyAttribute>("because we want to test the error {0}", "message");

            //-------------------------------------------------------------------------------------------------------------------
            // Assert
            //-------------------------------------------------------------------------------------------------------------------
            act.ShouldThrow<AssertFailedException>()
                .WithMessage("Expected all selected properties to be decorated with" +
                   " FluentAssertions.Specs.DummyPropertyAttribute because we want to test the error message," +
                   " but the following properties are not:\r\n" +
                   "String FluentAssertions.Specs.ClassWithPropertiesThatAreNotDecoratedWithDummyAttribute.PublicProperty\r\n" +
                   "String FluentAssertions.Specs.ClassWithPropertiesThatAreNotDecoratedWithDummyAttribute.InternalProperty\r\n" +
                   "String FluentAssertions.Specs.ClassWithPropertiesThatAreNotDecoratedWithDummyAttribute.ProtectedProperty");
        }
コード例 #25
0
        public void When_writeable_properties_are_expected_to_be_writable_it_should_not_throw()
        {
            //-------------------------------------------------------------------------------------------------------------------
            // Arrange
            //-------------------------------------------------------------------------------------------------------------------
            var propertyInfoSelector = new PropertyInfoSelector(typeof(ClassWithOnlyWritableProperties));

            //-------------------------------------------------------------------------------------------------------------------
            // Act
            //-------------------------------------------------------------------------------------------------------------------
            Action action = () => propertyInfoSelector.Should().BeWritable();

            //-------------------------------------------------------------------------------------------------------------------
            // Assert
            //-------------------------------------------------------------------------------------------------------------------
            action.ShouldNotThrow();
        }