コード例 #1
0
        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();
        }
コード例 #2
0
		public void DeepCustomMockingTest()
		{
			using (RecorderManager.NewPlayBackSession("test", false))
			{
				MockService.AddTypeToMock(typeof(Sample.CustomizableCurrencyService));
				Sample.Account acc = new Sample.Account(Sample.CurrencyUnit.EUR);
				acc.Deposit(100m);
				acc.SwitchCurrency(Sample.CurrencyUnit.USD);
				Assert.AreEqual(100m, acc.Balance);
			}
		}
コード例 #3
0
 public void DeepCustomMockingTest()
 {
     using (RecorderManager.NewPlayBackSession("test", false))
     {
         MockService.AddTypeToMock(typeof(Sample.CustomizableCurrencyService));
         Sample.Account acc = new Sample.Account(Sample.CurrencyUnit.EUR);
         acc.Deposit(100m);
         acc.SwitchCurrency(Sample.CurrencyUnit.USD);
         Assert.AreEqual(100m, acc.Balance);
     }
 }
コード例 #4
0
        public void RecordAndPlaybackTest()
        {
            decimal balanceToBe;

            Assert.AreEqual(RecorderState.None, RecorderManager.Action);
            using (RecorderManager.NewRecordingSession("test"))
            {
                Assert.AreEqual(RecorderState.Recording, RecorderManager.Action);
                MockService.AddTypeToMock(typeof(Sample.Account));
                MockService.AddTypeToMock(typeof(Sample.CustomizableCurrencyService));
                Sample.Account acc = new Sample.Account(Sample.CurrencyUnit.EUR);
                Assert.IsTrue(MockService.IsMock(acc));
                acc.Deposit(100m);
                acc.SwitchCurrency(Sample.CurrencyUnit.USD);
                acc.Withdraw(50m);
                balanceToBe = acc.Balance;
            }
            Assert.AreEqual(RecorderState.None, RecorderManager.Action);
            Assert.AreEqual(5, CurrentRecorder.Count);
            Assert.IsTrue(CurrentRecorder[0].IsConstructorCall);
            Assert.AreEqual("Deposit", CurrentRecorder[1].Method.Name);
            Assert.AreEqual("SwitchCurrency", CurrentRecorder[2].Method.Name);
            Assert.AreEqual("Withdraw", CurrentRecorder[3].Method.Name);
            Assert.AreEqual("get_Balance", CurrentRecorder[4].Method.Name);
            Assert.AreEqual(balanceToBe, CurrentRecorder[4].ReturnValue);
            using (RecorderManager.NewPlayBackSession("test", false))
            {
                Assert.AreEqual(RecorderState.PlayBack, RecorderManager.Action);
                MockService.AddTypeToMock(typeof(Sample.Account));
                MockService.AddTypeToMock(typeof(Sample.CustomizableCurrencyService));
                Sample.Account acc = new Sample.Account(Sample.CurrencyUnit.EUR);
                Assert.IsTrue(MockService.IsMock(acc));
                acc.Deposit(100m);
                acc.SwitchCurrency(Sample.CurrencyUnit.USD);
                acc.Withdraw(50m);
                Assert.AreEqual(balanceToBe, acc.Balance);
                RecorderManager.ValidatePlayBack();
            }
            Assert.AreEqual(RecorderState.None, RecorderManager.Action);
            Assert.IsTrue(CurrentRecorder.Validated);
        }
コード例 #5
0
		public void RecordAndPlaybackTest()
		{
			decimal balanceToBe;
			Assert.AreEqual(RecorderState.None, RecorderManager.Action);
			using (RecorderManager.NewRecordingSession("test"))
			{
				Assert.AreEqual(RecorderState.Recording, RecorderManager.Action);
				MockService.AddTypeToMock(typeof(Sample.Account));
				MockService.AddTypeToMock(typeof(Sample.CustomizableCurrencyService));
				Sample.Account acc = new Sample.Account(Sample.CurrencyUnit.EUR);
				Assert.IsTrue(MockService.IsMock(acc));
				acc.Deposit(100m);
				acc.SwitchCurrency(Sample.CurrencyUnit.USD);
				acc.Withdraw(50m);
				balanceToBe = acc.Balance;
			}
			Assert.AreEqual(RecorderState.None, RecorderManager.Action);
			Assert.AreEqual(5, CurrentRecorder.Count);
			Assert.IsTrue(CurrentRecorder[0].IsConstructorCall);
			Assert.AreEqual("Deposit", CurrentRecorder[1].Method.Name);
			Assert.AreEqual("SwitchCurrency", CurrentRecorder[2].Method.Name);
			Assert.AreEqual("Withdraw", CurrentRecorder[3].Method.Name);
			Assert.AreEqual("get_Balance", CurrentRecorder[4].Method.Name);
			Assert.AreEqual(balanceToBe, CurrentRecorder[4].ReturnValue);
			using (RecorderManager.NewPlayBackSession("test", false))
			{
				Assert.AreEqual(RecorderState.PlayBack, RecorderManager.Action);
				MockService.AddTypeToMock(typeof(Sample.Account));
				MockService.AddTypeToMock(typeof(Sample.CustomizableCurrencyService));
				Sample.Account acc = new Sample.Account(Sample.CurrencyUnit.EUR);
				Assert.IsTrue(MockService.IsMock(acc));
				acc.Deposit(100m);
				acc.SwitchCurrency(Sample.CurrencyUnit.USD);
				acc.Withdraw(50m);
				Assert.AreEqual(balanceToBe, acc.Balance);
				RecorderManager.ValidatePlayBack();
			}
			Assert.AreEqual(RecorderState.None, RecorderManager.Action);
			Assert.IsTrue(CurrentRecorder.Validated);
		}
コード例 #6
0
		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();
		}