Exemple #1
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);
        }