예제 #1
0
        public void ShouldPassPrearrangedDelegateMockAsArgument()
        {
            // ARRANGE
            // Creating a mock instance of the Func<string> delegate.
            var delegateMock = Mock.Create<Func<string>>();

            // Arranging: When the mock is called, it should return "Success".
            Mock.Arrange(() => delegateMock()).Returns("Success");

            // ACT
            var testInstance = new DataRepository();
            // Passing the mock into our system under test.
            var actual = testInstance.GetCurrentUserId(delegateMock);

            // ASSERT
            Assert.AreEqual("Success", actual);
        }
예제 #2
0
        public void ShouldPassDelegateMockAsArgumentAndAssertItsOccurrence()
        {
            bool isCalled = false;

            // ARRANGE
            // Creating a mock instance of the Action<int> delegate.
            var delegateMock = Mock.Create<Action<int>>();

            // Arranging: When the mock is called with any integer value as an argument, it should assign true to isCalled instead.
            Mock.Arrange(() => delegateMock(Arg.AnyInt)).DoInstead(() => isCalled = true);

            // ACT
            var testInstance = new DataRepository();
            // Passing the mock into our system under test.
            testInstance.ApproveCredentials(delegateMock);

            // ASSERT
            Assert.IsTrue(isCalled);
        }