Пример #1
0
 public void ValidateDecoratedWithAttribute_GivenMethodDecoratedWithAttribute_ShouldPassTest()
 {
     //---------------Set up test pack-------------------
     //---------------Assert Precondition----------------
     //---------------Execute Test ----------------------
     MethodTestHelper.ValidateDecoratedWithAttribute <FakeTestClass>("TestMethod1", typeof(FakeTestAttribute));
     //---------------Test Result -----------------------
 }
Пример #2
0
        public void ValidateDecoratedWithAttribute_GivenNullAttributeType_ShouldFailTest()
        {
            //---------------Set up test pack-------------------
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            var exception = Assert.Throws <ArgumentNullException>(() => MethodTestHelper.ValidateDecoratedWithAttribute <FakeMethodTest>("OverloadedMethod", null));

            //---------------Test Result -----------------------
            exception.ParamName.Should().Be("attributeType");
        }
Пример #3
0
        public void ValidateDecoratedWithAttribute_GivenMethodNameDoesNotExist_ShouldFailTest()
        {
            //---------------Set up test pack-------------------
            var methodName = "UnknownMethod";
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            var exception = Assert.Throws <AssertionException>(() => MethodTestHelper.ValidateDecoratedWithAttribute <FakeMethodTest>(methodName, typeof(FakeTestAttribute)));

            //---------------Test Result -----------------------
            exception.Message.Should().Be($"Method [{methodName}] does not exists on {typeof(FakeMethodTest).FullName}");
        }
Пример #4
0
        public void ValidateDecoratedWithAttribute_GivenMultipleMethodsWithSameName_And_AllowMultipleMethods_And_NoMatchingParameters_ShouldFailTest()
        {
            //---------------Set up test pack-------------------
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            var exception = Assert.Throws <AssertionException>(() => MethodTestHelper.ValidateDecoratedWithAttribute <FakeTestClass2>("FakeTestMethod",
                                                                                                                                      typeof(FakeTestAttribute),
                                                                                                                                      supportMultipleMethods: true));

            //---------------Test Result -----------------------
            exception.Message.Should().Be("Multiple methods with the same name found. Please specify the method to use by specifying the matching parameters");
        }
Пример #5
0
        public void ValidateDecoratedWithAttribute_GivenMethodNotDecoratedWithAttribute_ShouldPassTest()
        {
            //---------------Set up test pack-------------------
            var methodName    = "TestMethod2";
            var attributeType = typeof(FakeTestAttribute);
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            var exception = Assert.Throws <AssertionException>(() => MethodTestHelper.ValidateDecoratedWithAttribute <FakeTestClass>(methodName, attributeType));

            //---------------Test Result -----------------------
            exception.Message.Should().Be($"Method {methodName} is not decorated with {attributeType.Name} Attribute");
        }
Пример #6
0
 public void ValidateDecoratedWithAttribute_GivenMethodDecoratedWithAttribute_And_AttributeParametersMatch_ShouldPassTest()
 {
     //---------------Set up test pack-------------------
     //---------------Assert Precondition----------------
     //---------------Execute Test ----------------------
     MethodTestHelper.ValidateDecoratedWithAttribute <FakeTestClass>("TestMethod1", typeof(FakeTestAttribute),
                                                                     new List <(string propertyName, object propertyValue)>
     {
         ("PropertyName", "TestMethod1"), ("Sequence", 2)
     });
     //---------------Test Result -----------------------
 }
Пример #7
0
        public void ValidateDecoratedWithAttribute_GivenMultipleMethodsWithSameName_And_MethodDecoratedWithAttribute_ShouldPassTest()
        {
            //---------------Set up test pack-------------------
            var matchingParameters = new List <string>
            {
                "someParameter"
            };

            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            MethodTestHelper.ValidateDecoratedWithAttribute <FakeTestClass2>("FakeTestMethod", typeof(FakeTestAttribute),
                                                                             supportMultipleMethods: true,
                                                                             matchingParameters: matchingParameters);
            //---------------Test Result -----------------------
        }
Пример #8
0
        public void ValidateDecoratedWithAttribute_GivenMultipleMethodsWithSameName_And_AllowMultipleMethods_And_NoParametersFail_ShouldFailTest()
        {
            //---------------Set up test pack-------------------
            var matchingParameters = new List <string>
            {
                "someParameter",
                "unmatchedParameter"
            };
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            var exception = Assert.Throws <AssertionException>(() => MethodTestHelper.ValidateDecoratedWithAttribute <FakeTestClass2>("FakeTestMethod",
                                                                                                                                      typeof(FakeTestAttribute),
                                                                                                                                      supportMultipleMethods: true,
                                                                                                                                      matchingParameters: matchingParameters));

            //---------------Test Result -----------------------
            exception.Message.Should().Be("Failed to find a matching method using the specified matching parameters");
        }
Пример #9
0
        public void ValidateDecoratedWithAttribute_GivenMethodDecoratedWithAttribute_And_AttributeParametersDoNotMatch_ShouldFailTest()
        {
            //---------------Set up test pack-------------------
            var methodName    = "TestMethod1";
            var attributeType = typeof(FakeTestAttribute);
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            var exception = Assert.Throws <AssertionException>(() => MethodTestHelper.ValidateDecoratedWithAttribute <FakeTestClass>(methodName, attributeType,
                                                                                                                                     new List <(string propertyName, object propertyValue)>
            {
                ("PropertyName", "TestMethod2"),
                ("Sequence", 1)
            }));

            //---------------Test Result -----------------------
            exception.Message.Should().Contain($"{methodName} Method is decorated with {attributeType.Name} but the attribute property PropertyName is not set to TestMethod2");
            exception.Message.Should().Contain($"{methodName} Method is decorated with {attributeType.Name} but the attribute property Sequence is not set to 1");
        }