Esempio n. 1
0
        public void InvokeTask_ShouldTrackInvocationWithExceptionThrown()
        {
            // Arrange
            MockMethodWithParam <string> subject = new MockMethodWithParam <string>("methodName");

            subject.UpdateInvocation(() => { }, () => throw new Exception("Second Invocation"));

            // Act
            Func <Task> actual = async() => await subject.InvokeTask("");

            Func <Task> thrower = async() => await subject.InvokeTask("");

            // Assert
            actual.Should().NotThrow();
            thrower.Should().ThrowExactly <Exception>().WithMessage("Second Invocation");
            subject.AssertInvokedCountMatches(2);
        }
        public async Task CustomAssert_ShouldAssertInOrderOfInvocation_WithInvokeTask()
        {
            // Arrange
            string expected1 = "expected1";
            string expected2 = "expected2";
            MockMethodWithParam <string> subject = new MockMethodWithParam <string>("methodName");

            subject.UpdateInvocation();
            await subject.InvokeTask(expected1);

            await subject.InvokeTask(expected2);

            // Act
            Action actual  = () => subject.AssertCustom(o => o.Equals(expected1).Should().BeTrue());
            Action actual2 = () => subject.AssertCustom(o => o.Equals(expected2).Should().BeTrue());

            // Assert
            actual.Should().NotThrow();
            actual2.Should().NotThrow();
        }
        public void InvokeTask_ShouldNotThrowWhenTrueWithMultipleInvokes()
        {
            // Arrange
            MockMethodWithParam <string> subject = new MockMethodWithParam <string>("methodName");

            subject.UpdateInvocation();

            // Act
            Func <Task> actual = async() =>
            {
                await subject.InvokeTask("expected");

                await subject.InvokeTask("expected");

                await subject.InvokeTask("expected");
            };

            // Assert
            actual.Should().NotThrow();
        }
        public void InvokeTask_ShouldThrowExceptionWithMethodNameIfInvocationNotUpdated()
        {
            // Arrange
            string expected = "expected";
            MockMethodWithParam <string> subject = new MockMethodWithParam <string>("methodName");

            // Act
            Func <Task> actual = async() => await subject.InvokeTask(expected);

            // Assert
            actual.Should().ThrowExactly <TestException>().WithMessage("If you want to use methodName, configure via Builder.");
        }
        public async Task AssertInvokedWith_ShouldNotThrowWhenTrue_WithInvokeTask()
        {
            // Arrange
            MockMethodWithParam <string> subject = new MockMethodWithParam <string>("methodName");

            subject.UpdateInvocation();
            await subject.InvokeTask("expected");

            // Act
            Action actual = () => subject.AssertInvokedWith("expected");

            // Assert
            actual.Should().NotThrow();
        }
        public async Task AssertInvokedWith_ShouldThrowWhenFalse_WithInvokeTask()
        {
            // Arrange
            MockMethodWithParam <string> subject = new MockMethodWithParam <string>("methodName");

            subject.UpdateInvocation();
            await subject.InvokeTask("Not expected");

            // Act
            Action actual = () => subject.AssertInvokedWith("expected");

            // Assert
            actual.Should().Throw <Exception>().WithMessage("Expected methodName to be invoked with expected but was actually invoked with Not expected");
        }
        public void InvokeTask_ShouldNotThrowExceptionIfInvocationUpdated()
        {
            // Arrange
            string expected = "expected";
            MockMethodWithParam <string> subject = new MockMethodWithParam <string>("methodName");

            subject.UpdateInvocation();

            // Act
            Func <Task> actual = async() => await subject.InvokeTask(expected);

            // Assert
            actual.Should().NotThrow();
        }
        public async Task AssertCustom_ShouldThrowWhenFalse_WithInvokeTask()
        {
            // Arrange
            MockMethodWithParam <string> subject = new MockMethodWithParam <string>("methodName");

            subject.UpdateInvocation();
            await subject.InvokeTask("Not expected");

            // Act
            Action actual = () => subject.AssertCustom(o => o.Equals("expected").Should().BeTrue("this is expected to throw"));

            // Assert
            actual.Should().Throw <Exception>();
        }
        public void InvokeTask_ShouldThrowExceptionWhenUpdateInvocationSetUpForThat()
        {
            // Arrange
            string expected = "expected";
            MockMethodWithParam <string> subject = new MockMethodWithParam <string>("methodName");

            subject.UpdateInvocation(() => throw new Exception("I throw this"));

            // Act
            Func <Task> actual = async() => await subject.InvokeTask(expected);

            // Assert
            actual.Should().ThrowExactly <Exception>().WithMessage("I throw this");
        }
 public Task InvokeTask(TParam value) => _invokeTask.InvokeTask(value);
 public Task ParamTypeResponseTask(double justOne) => _paramTypeResponseTask.InvokeTask(justOne);