public void ManualMockingScenarioTest() { ManualMockSession sess = new ManualMockSession(); Sample.ICurrencyService cv = (Sample.ICurrencyService)sess.Mock(typeof(Sample.ICurrencyService), "cs") .ExpectAndReturn("ConvertAmount", 50m) .ExpectAndReturn("ConvertAmount", 80m).WithArguments(50m, ExpectedValue.OfType(typeof(Sample.CurrencyUnit)), ExpectedValue.OfType(typeof(Sample.CurrencyUnit))) .ExpectAndReturn("ConvertAmount", 30m).WithArguments(ExpectedValue.Any, ExpectedValue.OfType(typeof(Sample.CurrencyUnit)), Sample.CurrencyUnit.EUR).RepeatTimes(3) .Mock; Sample.CurrencyServiceFactory.NextInstance = cv; Sample.Account acc = new Sample.Account(Sample.CurrencyUnit.EUR); acc.Deposit(100m); Assert.AreEqual(100m, acc.Balance); acc.SwitchCurrency(Sample.CurrencyUnit.GBP); Assert.AreEqual(50m, acc.Balance); acc.SwitchCurrency(Sample.CurrencyUnit.USD); Assert.AreEqual(80m, acc.Balance); acc.SwitchCurrency(Sample.CurrencyUnit.EUR); Assert.AreEqual(30m, acc.Balance); acc.SwitchCurrency(Sample.CurrencyUnit.EUR); Assert.AreEqual(30m, acc.Balance); try { acc.SwitchCurrency(Sample.CurrencyUnit.NULL); Assert.Fail("Exception expected."); } catch (ReplayMockException) { } sess.ValidateSession(); }
public void ManualMockingValidate01Test() { ManualMockSession sess = new ManualMockSession(); Sample.ICurrencyService cv = (Sample.ICurrencyService)sess.Mock(typeof(Sample.ICurrencyService), "cs") .ExpectAndReturn("ConvertAmount", 50m) .Mock; sess.ValidateSession(); }
public void ManualMockingValidate03Test() { ManualMockSession sess = new ManualMockSession(); Sample.ICurrencyService cv = (Sample.ICurrencyService)sess.Mock(typeof(Sample.ICurrencyService), "cs") .ExpectAndReturn("GetRate", 1.2m) .Mock; Assert.AreEqual(1.2m, cv.GetRate(Sample.CurrencyUnit.GBP)); sess.ValidateSession(); }