public void TestCalc1()
        {
            // Configure the ICalcMethod to behave how we want
            A.CallTo(() => calcMethod.Calc(Position.BOSS)).Returns(70000.0);
            A.CallTo(() => calcMethod.Calc(Position.PROGRAMMER)).Returns(50000.0);

            // Set the calc method
            calc.SetCalcMethod(calcMethod);

            calc.SetPosition(Position.BOSS);
            double income1 = calc.Calc();

            Assert.AreEqual(70000.0, income1);

            double income2 = calc.Calc();

            Assert.AreEqual(70000.0, income2);

            calc.SetPosition(Position.PROGRAMMER);
            double income3 = calc.Calc();

            Assert.AreEqual(50000.0, income3);

            // Verify that the ICalcMethod.Calc method was called the right number of times
            A.CallTo(() => calcMethod.Calc(Position.BOSS)).MustHaveHappened(2, Times.Exactly);
            A.CallTo(() => calcMethod.Calc(Position.PROGRAMMER)).MustHaveHappenedOnceExactly();
        }
Exemple #2
0
 public double Calc()
 {
     if (calcMethod == null)
     {
         throw new Exception("CalcMethod not yet maintained");
     }
     if (position == Position.NONE)
     {
         throw new Exception("Position not yet maintained");
     }
     return(calcMethod.Calc(position));
 }