コード例 #1
0
            public void When_asserting_methods_are_not_async_and_they_are_not_then_it_succeeds()
            {
                // Arrange
                var methodSelector = new MethodInfoSelector(typeof(ClassWithNonAsyncMethods));

                // Act
                Action act = () => methodSelector.Should().NotBeAsync();

                // Assert
                act.Should().NotThrow();
            }
コード例 #2
0
        public void When_method_info_selector_is_null_then_should_should_throw()
        {
            // Arrange
            MethodInfoSelector methodInfoSelector = null;

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

            // Assert
            act.Should().ThrowExactly <ArgumentNullException>()
            .WithParameterName("methodSelector");
        }
コード例 #3
0
        public void When_method_info_selector_is_created_with_a_null_type_list_it_should_throw()
        {
            // Arrange
            MethodInfoSelector methodInfoSelector;

            // Act
            Action act = () => methodInfoSelector = new MethodInfoSelector((Type[])null);

            // Assert
            act.Should().ThrowExactly <ArgumentNullException>()
            .WithParameterName("types");
        }
コード例 #4
0
        public void When_asserting_methods_are_not_virtual_and_they_are_not_it_should_succeed()
        {
            // Arrange
            var methodSelector = new MethodInfoSelector(typeof(ClassWithNonVirtualPublicMethods));

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

            // Assert
            act.Should().NotThrow();
        }
コード例 #5
0
            public void When_all_methods_does_not_have_specified_accessor_it_should_succeed()
            {
                // Arrange
                var methodSelector = new MethodInfoSelector(typeof(ClassWithNonPublicMethods));

                // Act
                Action act = () =>
                             methodSelector.Should().NotBe(CSharpAccessModifier.Public);

                // Assert
                act.Should().NotThrow();
            }
コード例 #6
0
        public void When_asserting_methods_are_not_virtual_but_virtual_methods_are_found_it_should_throw()
        {
            // Arrange
            var methodSelector = new MethodInfoSelector(typeof(ClassWithAllMethodsVirtual));

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

            // Assert
            act.Should().Throw <XunitException>();
        }
コード例 #7
0
        public void When_asserting_methods_are_not_decorated_with_attribute_and_they_are_not_it_should_succeed()
        {
            // Arrange
            var methodSelector = new MethodInfoSelector(typeof(ClassWithMethodsThatAreNotDecoratedWithDummyAttribute));

            // Act
            Action act = () =>
                         methodSelector.Should().NotBeDecoratedWith <DummyMethodAttribute>();

            // Assert
            act.Should().NotThrow();
        }
コード例 #8
0
        public void When_injecting_a_null_predicate_into_NotBeDecoratedWith_it_should_throw()
        {
            // Arrange
            var methodSelector = new MethodInfoSelector(typeof(ClassWithMethodsThatAreNotDecoratedWithDummyAttribute));

            // Act
            Action act = () =>
                         methodSelector.Should().NotBeDecoratedWith <DummyMethodAttribute>(isMatchingAttributePredicate: null);

            // Assert
            act.Should().ThrowExactly <ArgumentNullException>()
            .Which.ParamName.Should().Be("isMatchingAttributePredicate");
        }
コード例 #9
0
        public void When_asserting_methods_are_not_decorated_with_attribute_but_they_are_it_should_throw()
        {
            // Arrange
            MethodInfoSelector methodSelector =
                new MethodInfoSelector(typeof(ClassWithAllMethodsDecoratedWithDummyAttribute))
                .ThatArePublicOrInternal;

            // Act
            Action act = () =>
                         methodSelector.Should().NotBeDecoratedWith <DummyMethodAttribute>();

            // Assert
            act.Should().Throw <XunitException>();
        }
コード例 #10
0
            public void When_any_method_have_specified_accessor_it_should_throw()
            {
                // Arrange
                var methodSelector = new MethodInfoSelector(typeof(ClassWithPublicMethods));

                // Act
                Action act = () =>
                             methodSelector.Should().NotBe(CSharpAccessModifier.Public);

                // Assert
                act.Should().Throw <XunitException>()
                .WithMessage("Expected all selected methods to not be Public" +
                             ", but the following methods are:*" +
                             "Void FluentAssertions*ClassWithPublicMethods.PublicDoNothing*");
            }
コード例 #11
0
        public void When_any_method_have_specified_accessor_it_should_throw_with_descriptive_message()
        {
            // Arrange
            var methodSelector = new MethodInfoSelector(typeof(ClassWithPublicMethods));

            // Act
            Action act = () =>
                         methodSelector.Should().NotBe(CSharpAccessModifier.Public, "we want to test the error {0}", "message");

            // Assert
            act.Should().Throw <XunitException>()
            .WithMessage("Expected all selected methods to not be Public" +
                         " because we want to test the error message" +
                         ", but the following methods are:*" +
                         "Void FluentAssertions.Specs.ClassWithPublicMethods.PublicDoNothing*");
        }
コード例 #12
0
        public void When_asserting_methods_are_not_decorated_with_attribute_but_they_are_it_should_throw_with_descriptive_message()
        {
            // Arrange
            var methodSelector = new MethodInfoSelector(typeof(ClassWithAllMethodsDecoratedWithDummyAttribute));

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

            // Assert
            act.Should().Throw <XunitException>()
            .WithMessage("Expected all selected methods to not be decorated*DummyMethodAttribute*because we want to test the error message" +
                         "*ClassWithAllMethodsDecoratedWithDummyAttribute.PublicDoNothing*" +
                         "*ClassWithAllMethodsDecoratedWithDummyAttribute.PublicDoNothingWithSameAttributeTwice*" +
                         "*ClassWithAllMethodsDecoratedWithDummyAttribute.ProtectedDoNothing*" +
                         "*ClassWithAllMethodsDecoratedWithDummyAttribute.PrivateDoNothing");
        }
コード例 #13
0
            public void When_asserting_methods_are_not_async_but_async_methods_are_found_it_should_throw_with_descriptive_message()
            {
                // Arrange
                var methodSelector = new MethodInfoSelector(typeof(ClassWithAllMethodsAsync));

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

                // Assert
                act.Should().Throw <XunitException>()
                .WithMessage("Expected all selected methods" +
                             " not to be async because we want to test the error message," +
                             " but the following methods are:" + Environment.NewLine +
                             "Task FluentAssertions.Specs.Types.ClassWithAllMethodsAsync.PublicAsyncDoNothing" + Environment.NewLine +
                             "Task FluentAssertions.Specs.Types.ClassWithAllMethodsAsync.InternalAsyncDoNothing" + Environment.NewLine +
                             "Task FluentAssertions.Specs.Types.ClassWithAllMethodsAsync.ProtectedAsyncDoNothing");
            }
コード例 #14
0
        public void When_not_all_methods_have_specified_accessor_it_should_throw()
        {
            // Arrange
            var methodSelector = new MethodInfoSelector(typeof(ClassWithNonPublicMethods));

            // Act
            Action act = () =>
                         methodSelector.Should().Be(CSharpAccessModifier.Public);

            // Assert
            act.Should().Throw <XunitException>()
            .WithMessage("Expected all selected methods to be Public" +
                         ", but the following methods are not:*" +
                         "Void FluentAssertions.Specs.ClassWithNonPublicMethods.PublicDoNothing*" +
                         "Void FluentAssertions.Specs.ClassWithNonPublicMethods.DoNothingWithParameter*" +
                         "Void FluentAssertions.Specs.ClassWithNonPublicMethods.DoNothingWithAnotherParameter");
        }
コード例 #15
0
        public void When_asserting_methods_are_decorated_with_attribute_and_they_are_it_should_succeed()
        {
            //-------------------------------------------------------------------------------------------------------------------
            // Arrange
            //-------------------------------------------------------------------------------------------------------------------
            var methodSelector = new MethodInfoSelector(typeof(ClassWithAllMethodsDecoratedWithDummyAttribute));

            //-------------------------------------------------------------------------------------------------------------------
            // Act
            //-------------------------------------------------------------------------------------------------------------------
            Action act = () =>
                methodSelector.Should().BeDecoratedWith<DummyMethodAttribute>();

            //-------------------------------------------------------------------------------------------------------------------
            // Assert
            //-------------------------------------------------------------------------------------------------------------------
            act.ShouldNotThrow();
        }
コード例 #16
0
        public void When_asserting_methods_are_virtual_and_they_are_it_should_succeed()
        {
            //-------------------------------------------------------------------------------------------------------------------
            // Arrange
            //-------------------------------------------------------------------------------------------------------------------
            var methodSelector = new MethodInfoSelector(typeof(ClassWithAllMethodsVirtual));

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

            //-------------------------------------------------------------------------------------------------------------------
            // Assert
            //-------------------------------------------------------------------------------------------------------------------
            act.ShouldNotThrow();
        }
コード例 #17
0
        public void When_asserting_methods_are_decorated_with_attribute_but_they_are_not_it_should_throw_with_descriptive_message()
        {
            // Arrange
            var methodSelector = new MethodInfoSelector(typeof(ClassWithMethodsThatAreNotDecoratedWithDummyAttribute));

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

            // Assert
            act.Should().Throw <XunitException>()
            .WithMessage("Expected all selected methods to be decorated with" +
                         " FluentAssertions.Specs.DummyMethodAttribute because we want to test the error message," +
                         " but the following methods are not:*" +
                         "Void FluentAssertions.Specs.ClassWithMethodsThatAreNotDecoratedWithDummyAttribute.PublicDoNothing*" +
                         "Void FluentAssertions.Specs.ClassWithMethodsThatAreNotDecoratedWithDummyAttribute.ProtectedDoNothing*" +
                         "Void FluentAssertions.Specs.ClassWithMethodsThatAreNotDecoratedWithDummyAttribute.PrivateDoNothing");
        }
コード例 #18
0
        public void When_asserting_methods_are_virtual_but_non_virtual_methods_are_found_it_should_throw()
        {
            //-------------------------------------------------------------------------------------------------------------------
            // Arrange
            //-------------------------------------------------------------------------------------------------------------------
            var methodSelector = new MethodInfoSelector(typeof(ClassWithNonVirtualPublicMethods));

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

            //-------------------------------------------------------------------------------------------------------------------
            // Assert
            //-------------------------------------------------------------------------------------------------------------------
            act.Should().Throw <XunitException>();
        }
コード例 #19
0
        public void When_asserting_methods_are_decorated_with_attribute_and_they_are_it_should_succeed()
        {
            //-------------------------------------------------------------------------------------------------------------------
            // Arrange
            //-------------------------------------------------------------------------------------------------------------------
            var methodSelector = new MethodInfoSelector(typeof(ClassWithAllMethodsDecoratedWithDummyAttribute));

            //-------------------------------------------------------------------------------------------------------------------
            // Act
            //-------------------------------------------------------------------------------------------------------------------
            Action act = () =>
                         methodSelector.Should().BeDecoratedWith <DummyMethodAttribute>();

            //-------------------------------------------------------------------------------------------------------------------
            // Assert
            //-------------------------------------------------------------------------------------------------------------------
            act.Should().NotThrow();
        }
コード例 #20
0
        public void When_asserting_methods_are_virtual_and_they_are_it_should_succeed()
        {
            //-------------------------------------------------------------------------------------------------------------------
            // Arrange
            //-------------------------------------------------------------------------------------------------------------------
            var methodSelector = new MethodInfoSelector(typeof(ClassWithAllMethodsVirtual));

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

            //-------------------------------------------------------------------------------------------------------------------
            // Assert
            //-------------------------------------------------------------------------------------------------------------------
            act.Should().NotThrow();
        }
コード例 #21
0
        public void When_asserting_methods_are_virtual_but_non_virtual_methods_are_found_it_should_throw()
        {
            //-------------------------------------------------------------------------------------------------------------------
            // Arrange
            //-------------------------------------------------------------------------------------------------------------------
            var methodSelector = new MethodInfoSelector(typeof(ClassWithNonVirtualPublicMethods));

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

            //-------------------------------------------------------------------------------------------------------------------
            // Assert
            //-------------------------------------------------------------------------------------------------------------------
            act.ShouldThrow<AssertFailedException>();
        }
コード例 #22
0
        public void When_asserting_methods_are_not_virtual_but_virtual_methods_are_found_it_should_throw_with_descriptive_message()
        {
            // Arrange
            var methodSelector = new MethodInfoSelector(typeof(ClassWithAllMethodsVirtual));

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

            // Assert
            act.Should().Throw <XunitException>()
            .WithMessage("Expected all selected methods" +
                         " not to be virtual because we want to test the error message," +
                         " but the following methods are virtual" +
                         "*ClassWithAllMethodsVirtual.PublicVirtualDoNothing" +
                         "*ClassWithAllMethodsVirtual.InternalVirtualDoNothing" +
                         "*ClassWithAllMethodsVirtual.ProtectedVirtualDoNothing*");
        }
コード例 #23
0
        public void When_asserting_methods_are_virtual_but_non_virtual_methods_are_found_it_should_throw_with_descriptive_message()
        {
            // Arrange
            var methodSelector = new MethodInfoSelector(typeof(ClassWithNonVirtualPublicMethods));

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

            // Assert
            act.Should().Throw <XunitException>()
            .WithMessage("Expected all selected methods" +
                         " to be virtual because we want to test the error message," +
                         " but the following methods are not virtual:*" +
                         "Void FluentAssertions.Specs.ClassWithNonVirtualPublicMethods.PublicDoNothing*" +
                         "Void FluentAssertions.Specs.ClassWithNonVirtualPublicMethods.InternalDoNothing*" +
                         "Void FluentAssertions.Specs.ClassWithNonVirtualPublicMethods.ProtectedDoNothing");
        }
コード例 #24
0
        public void When_asserting_methods_are_decorated_with_attribute_but_they_are_not_it_should_throw()
        {
            //-------------------------------------------------------------------------------------------------------------------
            // Arrange
            //-------------------------------------------------------------------------------------------------------------------
            MethodInfoSelector methodSelector =
                new MethodInfoSelector(typeof(ClassWithMethodsThatAreNotDecoratedWithDummyAttribute))
                    .ThatArePublicOrInternal;

            //-------------------------------------------------------------------------------------------------------------------
            // Act
            //-------------------------------------------------------------------------------------------------------------------
            Action act = () =>
                methodSelector.Should().BeDecoratedWith<DummyMethodAttribute>();

            //-------------------------------------------------------------------------------------------------------------------
            // Assert
            //-------------------------------------------------------------------------------------------------------------------
            act.ShouldThrow<AssertFailedException>();
        }
コード例 #25
0
        public void When_asserting_methods_are_decorated_with_attribute_but_they_are_not_it_should_throw()
        {
            //-------------------------------------------------------------------------------------------------------------------
            // Arrange
            //-------------------------------------------------------------------------------------------------------------------
            MethodInfoSelector methodSelector =
                new MethodInfoSelector(typeof(ClassWithMethodsThatAreNotDecoratedWithDummyAttribute))
                .ThatArePublicOrInternal;

            //-------------------------------------------------------------------------------------------------------------------
            // Act
            //-------------------------------------------------------------------------------------------------------------------
            Action act = () =>
                         methodSelector.Should().BeDecoratedWith <DummyMethodAttribute>();

            //-------------------------------------------------------------------------------------------------------------------
            // Assert
            //-------------------------------------------------------------------------------------------------------------------
            act.ShouldThrow <AssertFailedException>();
        }
コード例 #26
0
        public void When_asserting_methods_are_decorated_with_attribute_but_they_are_not_it_should_throw_with_descriptive_message()
        {
            //-------------------------------------------------------------------------------------------------------------------
            // Arrange
            //-------------------------------------------------------------------------------------------------------------------
            var methodSelector = new MethodInfoSelector(typeof(ClassWithMethodsThatAreNotDecoratedWithDummyAttribute));

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

            //-------------------------------------------------------------------------------------------------------------------
            // Assert
            //-------------------------------------------------------------------------------------------------------------------
            act.ShouldThrow<AssertFailedException>()
                .WithMessage("Expected all selected methods to be decorated with" +
                             " FluentAssertions.Specs.DummyMethodAttribute because we want to test the error message," +
                             " but the following methods are not:\r\n" +
                             "Void FluentAssertions.Specs.ClassWithMethodsThatAreNotDecoratedWithDummyAttribute.PublicDoNothing\r\n" +
                             "Void FluentAssertions.Specs.ClassWithMethodsThatAreNotDecoratedWithDummyAttribute.ProtectedDoNothing\r\n" +
                             "Void FluentAssertions.Specs.ClassWithMethodsThatAreNotDecoratedWithDummyAttribute.PrivateDoNothing");
        }
コード例 #27
0
        public void When_asserting_methods_are_virtual_but_non_virtual_methods_are_found_it_should_throw_with_descriptive_message()
        {
            //-------------------------------------------------------------------------------------------------------------------
            // Arrange
            //-------------------------------------------------------------------------------------------------------------------
            var methodSelector = new MethodInfoSelector(typeof(ClassWithNonVirtualPublicMethods));

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

            //-------------------------------------------------------------------------------------------------------------------
            // Assert
            //-------------------------------------------------------------------------------------------------------------------
            act.ShouldThrow<AssertFailedException>()
                .WithMessage("Expected all selected methods" +
                             " to be virtual because we want to test the error message," +
                             " but the following methods are not virtual:\r\n" +
                             "Void FluentAssertions.Specs.ClassWithNonVirtualPublicMethods.PublicDoNothing\r\n" +
                             "Void FluentAssertions.Specs.ClassWithNonVirtualPublicMethods.InternalDoNothing\r\n" +
                             "Void FluentAssertions.Specs.ClassWithNonVirtualPublicMethods.ProtectedDoNothing");
        }
コード例 #28
0
 /// <summary>
 /// Returns a <see cref="MethodInfoSelectorAssertions"/> object that can be used to assert the methods returned by the
 /// current <see cref="MethodInfoSelector"/>.
 /// </summary>
 /// <seealso cref="TypeAssertions"/>
 public static MethodInfoSelectorAssertions Should(this MethodInfoSelector methodSelector)
 {
     return(new MethodInfoSelectorAssertions(methodSelector.ToArray()));
 }