Ejemplo n.º 1
0
 protected override void AssertMethodWasCalledBetween2And3TimesInclusive()
 {
     PayrollSystemMock.Assert()
     .ThatMethod(x => x.FinalisePaymentsForEmployee(WithAnyArgument.OfType <string>()))
     .WasCalledBetween(2)
     .And(3).TimesIncludingTheToAndFromValues();
 }
Ejemplo n.º 2
0
 protected override void AssertMethodWasCalledExactly2Times()
 {
     PayrollSystemMock.Assert()
     .ThatMethod(x => x.FinalisePaymentsForEmployee(WithAnyArgument.OfType <string>()))
     .WasCalled()
     .Exactly(2).Times();
 }
 protected override void AssertMethodWasCalledBetween2And4TimesExclusive()
 {
     PayrollSystemMock.Assert()
     .ThatMethod(x => x.GetSalaryForEmployee(WithAnyArgument.OfType <string>()))
     .WasCalledBetween(2)
     .And(4).TimesExcludingTheToAndFromValues();
 }
Ejemplo n.º 4
0
 protected override void AssertMethodWasCalledAtLeastOnce()
 {
     PayrollSystemMock.Assert()
     .ThatMethod(x => x.FinalisePaymentsForEmployee(WithAnyArgument.OfType <string>()))
     .WasCalled()
     .AtLeastOnce();
 }
 protected override void AssertMethodWasCalledOnce()
 {
     PayrollSystemMock.Assert()
     .ThatMethod(x => x.GetSalaryForEmployee(WithAnyArgument.OfType <string>()))
     .WasCalled()
     .Once();
 }
        public void CanArrangeMethodWithAnyArgument()
        {
            var payrollSystemMock = new Mock <IPayrollSystem>();

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

            payrollSystemMock.Object.GetSalaryForEmployee("Foo").ShouldBe(5);
        }
        public void CanArrangeMethodWithTwoAnyArguments()
        {
            var payrollSystemMock = new Mock <IPayrollSystem>();

            payrollSystemMock.Arrange()
            .SoThatWhenMethod(x => x.GetSalaryForEmployeeForYear(WithAnyArgument.OfType <string>(),
                                                                 WithAnyArgument.OfType <int>()))
            .IsCalled()
            .ItReturns(6);

            payrollSystemMock.Object.GetSalaryForEmployeeForYear("Foo", 2014).ShouldBe(6);
        }
Ejemplo n.º 8
0
        public void ArgumentOfReferenceType_IsUsedToInvokeAction_Scenario2()
        {
            var payrollSystemMock = new Mock <IPayrollSystem>();

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

            payrollSystemMock.Object.FinalisePaymentsForEmployee("Foo");

            stringPassedToTestActionThatTakesAStringParameter.ShouldBe("Foo");
        }
Ejemplo n.º 9
0
        public void ArgumentOfReferenceType_IsSavedInLocalVariable()
        {
            var    payrollSystemMock = new Mock <IPayrollSystem>();
            string passedInString    = null;

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

            payrollSystemMock.Object.FinalisePaymentsForEmployee("Foo");

            passedInString.ShouldBe("Foo");
        }
        public void ArgumentOfReferenceType_IsUsedToInvokeActionWithTwoParameters_Scenario2()
        {
            var payrollSystemMock = new Mock <IPayrollSystem>();

            payrollSystemMock.Arrange()
            .SoThatWhenMethod(x => x.GetSalaryForEmployeeForYear(WithAnyArgument.OfType <string>(), WithAnyArgument.OfType <int>()))
            .IsCalled()
            .TheArgumentsPassedIn()
            .AreUsedToInvokeAction <string, int>(TestActionThatTakesTwoStringParameter);

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

            string1PassedToTestActionThatTakesAStringParameter.ShouldBe("Foo");
            int2PassedToTestActionThatTakesAStringParameter.ShouldBe(3);
        }
        public void CanArrangeMethodWithThreeAnyArguments()
        {
            var payrollSystemMock = new Mock <IPayrollSystem>();

            payrollSystemMock.Arrange()
            .SoThatWhenMethod(x => x.GetSalaryForEmployeeForPeriod(WithAnyArgument.OfType <string>(),
                                                                   WithAnyArgument.OfType <DateTime>(),
                                                                   WithAnyArgument.OfType <DateTime>()))
            .IsCalled()
            .ItReturns(6);

            payrollSystemMock.Object
            .GetSalaryForEmployeeForPeriod("Foo", DateTime.Now.AddYears(-2), DateTime.Now.AddYears(-1))
            .ShouldBe(6);
        }
        public void ArgumentOfReferenceType_IsUsedToInvokeAction_Scenario1()
        {
            var    payrollSystemMock = new Mock <IPayrollSystem>();
            string passedInString    = null;

            payrollSystemMock.Arrange()
            .SoThatWhenMethod(x => x.GetSalaryForEmployee(WithAnyArgument.OfType <string>()))
            .IsCalled()
            .TheArgumentsPassedIn()
            .AreUsedToInvokeAction <string>(x => passedInString = x);

            payrollSystemMock.Object.GetSalaryForEmployee("Foo");

            passedInString.ShouldBe("Foo");
        }
Ejemplo n.º 13
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");
        }
Ejemplo n.º 14
0
        public void ArgumentOfReferenceType_IsUsedToInvokeActionWithTwoParameters_Scenario1()
        {
            var    payrollSystemMock = new Mock <IPayrollSystem>();
            string passedInString    = null;
            int    passedInInt       = 0;

            payrollSystemMock.Arrange()
            .SoThatWhenMethod(x => x.FinalisePaymentsForEmployeeForMonth(WithAnyArgument.OfType <string>(), WithAnyArgument.OfType <int>()))
            .IsCalled()
            .TheArgumentsPassedIn()
            .AreUsedToInvokeAction <string, int>((x, i) => { passedInString = x; passedInInt = i; });

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

            passedInString.ShouldBe("Foo");
            passedInInt.ShouldBe(3);
        }
        public void ArgumentOfReferenceType_IsSavedInLocalVariable_AndReturnsValue()
        {
            var    payrollSystemMock = new Mock <IPayrollSystem>();
            string passedInString    = null;

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

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

            passedInString.ShouldBe("Foo");
            returnValueFromMock.ShouldBe(5);
        }
        public void TwoArgumentOfReferenceType_IsSavedInLocalVariable()
        {
            var    payrollSystemMock = new Mock <IPayrollSystem>();
            string passedInString    = null;
            int    passedInInt       = 0;

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

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

            passedInString.ShouldBe("Foo");
            passedInInt.ShouldBe(3);
        }
        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);
        }
        public void IsCalledWithAnyArgumentOfTypeIsConvertedToIsAnyOfT()
        {
            Expression <Func <IPayrollSystem, int> > arrangeMockExpression = x => x.GetSalaryForEmployee(WithAnyArgument.OfType <string>());

            var convertedExpression = ExpressionConverter.ConvertArrangeMockExpressionToMoqExpression(arrangeMockExpression);

            Expression <Func <IPayrollSystem, int> > expectedMoqExpression = x => x.GetSalaryForEmployee(It.IsAny <string>());

            // TODO: Is there a better way of checking for equivalency between expressions rather than just using ToString()?
            convertedExpression.ToString().ShouldBe(expectedMoqExpression.ToString());
        }