コード例 #1
0
        public void ArgumentOfReferenceType_IsSavedInProperty()
        {
            var payrollSystemMock = new Mock <IPayrollSystem>();

            TestPropertyToSaveStringIn = null;

            payrollSystemMock.Arrange()
            .SoThatWhenMethod(x => x.FinalisePaymentsForEmployee(WithAnyArgument.OfType <string>()))
            .IsCalled()
            .TheArgumentsPassedIn()
            .AreSavedTo(() => TestPropertyToSaveStringIn);

            payrollSystemMock.Object.FinalisePaymentsForEmployee("Foo");

            TestPropertyToSaveStringIn.ShouldBe("Foo");
        }
コード例 #2
0
        public void TwoArgumentOfReferenceType_IsSavedInProperty()
        {
            var payrollSystemMock = new Mock <IPayrollSystem>();

            TestPropertyToSaveStringIn = null;

            payrollSystemMock.Arrange()
            .SoThatWhenMethod(x => x.GetSalaryForEmployeeForYear(WithAnyArgument.OfType <string>(), WithAnyArgument.OfType <int>()))
            .IsCalled()
            .TheArgumentsPassedIn()
            .AreSavedTo(() => TestPropertyToSaveStringIn,
                        () => TestPropertyToSaveIntIn);

            payrollSystemMock.Object.GetSalaryForEmployeeForYear("Foo", 3);

            TestPropertyToSaveStringIn.ShouldBe("Foo");
            TestPropertyToSaveIntIn.ShouldBe(3);
        }
コード例 #3
0
        public void ArgumentOfReferenceType_IsSavedInProperty_AndReturnsValue()
        {
            var payrollSystemMock = new Mock <IPayrollSystem>();

            TestPropertyToSaveStringIn = null;

            payrollSystemMock.Arrange()
            .SoThatWhenMethod(x => x.GetSalaryForEmployee(WithAnyArgument.OfType <string>()))
            .IsCalled()
            .ItReturns(5)
            .AndTheArgumentsPassedIn()
            .AreSavedTo(() => TestPropertyToSaveStringIn);

            var returnValueFromMock = payrollSystemMock.Object.GetSalaryForEmployee("Foo");

            TestPropertyToSaveStringIn.ShouldBe("Foo");
            returnValueFromMock.ShouldBe(5);
        }