public void ValidateDecoratedWithAttribute_GivenMethodDecoratedWithAttribute_ShouldPassTest() { //---------------Set up test pack------------------- //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- MethodTestHelper.ValidateDecoratedWithAttribute <FakeTestClass>("TestMethod1", typeof(FakeTestAttribute)); //---------------Test Result ----------------------- }
public void AddStateData_GivenNullParameterValue_ShouldThrowException(string parameterName) { //---------------Set up test pack------------------- //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- MethodTestHelper.ValidateArgumentNullExceptionIfParameterIsNull <FakeStatefulMessage>("AddStateData", parameterName); //---------------Test Result ----------------------- }
public void ValidateExceptionIsThrownIfParameterIsNull_GivenOverloadedMethods_ShouldTestMethodWithParameterNameMatch(string parameterName) { //---------------Set up test pack------------------- //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- MethodTestHelper.ValidateExceptionIsThrownIfParameterIsNull <FakeMethodTest, ArgumentNullException>("OverloadedMethod", parameterName); //---------------Test Result ----------------------- }
public void ValidateExceptionIsThrownIfParameterIsNullAsync_GivenNullParameter_ShouldDetectArgumentNullException() { //---------------Set up test pack------------------- //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- MethodTestHelper.ValidateExceptionIsThrownIfParameterIsNullAsync <FakeMethodTest, ArgumentNullException>("TestMethodAsync", "nonNullParameter"); //---------------Test Result ----------------------- }
public void Method_GivenNullParameter_ShouldThrowException(string methodName, string parameterName) { //---------------Set up test pack------------------- //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- MethodTestHelper.ValidateArgumentNullExceptionIfParameterIsNull <SqliteDbConnectionProvider>(methodName, parameterName); //---------------Test Result ----------------------- }
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"); }
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}"); }
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"); }
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"); }
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 ----------------------- }
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 ----------------------- }
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"); }
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"); }