コード例 #1
0
 public void LocalPattern02Test()
 {
     using (RecorderManager.NewPlayBackSession("test", false))
     {
         RemotingMockService.AddGlobalMockingUri("*");
     }
 }
コード例 #2
0
        public void ScenarioPlayTest()
        {
            using (RecorderManager.NewRecordingSession("test"))
            {
                // Make a callee, not really used but needed to record a constructor call:
                MockingProxy callee = new MockingProxy(typeof(Sample.Account), null, "m1");

                // Push some calls in the recorder:
                MockableCall lastcall;
                CurrentRecorder.RecordCall(lastcall = new MockableCall(callee, typeof(Sample.Account).GetConstructor(new Type[] { typeof(Sample.CurrencyUnit) }), null));
                lastcall.SetConstructionResult("acc");
                CurrentRecorder.RecordCall(lastcall = new MockableCall(callee, typeof(Sample.Account).GetMethod("Deposit"), null));
                lastcall.SetCallResult();
                CurrentRecorder.RecordCall(lastcall = new MockableCall(callee, typeof(Sample.Account).GetMethod("Withdraw"), null));
                lastcall.SetCallResult();
                CurrentRecorder.RecordCall(lastcall = new MockableCall(callee, typeof(Sample.Account).GetProperty("Balance").GetGetMethod(), null));
                lastcall.SetCallResult(10m);
            }

            using (RecorderManager.NewPlayBackSession("test", true))
            {
                // Register types to mock:
                MockService.AddTypeToMock(typeof(Sample.Account));

                // Play scenario:
                Sample.Account acc = new Sample.Account(Sample.CurrencyUnit.EUR);
                acc.Deposit(100m);
                acc.Withdraw(25m);
                Decimal balance = acc.Balance;

                // Checks:
                Assert.AreEqual(10m, balance);                 // Does not match the scenario, but the mocking result !
            }
        }
コード例 #3
0
 public void NoMockingTest()
 {
     using (RecorderManager.NewPlayBackSession("test", false))
     {
         Sample.ICurrencyService srv = Sample.CurrencyServiceFactory.NextInstance;
         Assert.IsFalse(MockService.IsMock(srv));
     }
 }
コード例 #4
0
 public void AddTypeToMockTest()
 {
     using (RecorderManager.NewPlayBackSession("test", false))
     {
         Assert.IsFalse(MockService.IsTypeToMock(typeof(Sample.CustomizableCurrencyService)));
         MockService.AddTypeToMock(typeof(Sample.CustomizableCurrencyService));
         Assert.IsTrue(MockService.IsTypeToMock(typeof(Sample.CustomizableCurrencyService)));
     }
 }
コード例 #5
0
 public void MockingTest()
 {
     using (RecorderManager.NewPlayBackSession("test", false))
     {
         MockService.AddTypeToMock(typeof(Sample.CustomizableCurrencyService));
         Sample.ICurrencyService srv = Sample.CurrencyServiceFactory.NextInstance;
         Assert.IsTrue(MockService.IsMock(srv));
     }
 }
コード例 #6
0
 public void CustomMockingScenarioTest()
 {
     using (RecorderManager.NewPlayBackSession("test", false))
     {
         MockService.AddTypeToMock(typeof(Sample.CustomizableCurrencyService));
         Sample.ICurrencyService srv = Sample.CurrencyServiceFactory.NextInstance;
         decimal result = srv.ConvertAmount(100, Sample.CurrencyUnit.NULL, Sample.CurrencyUnit.GBP);
         Assert.AreEqual(100m, result);
     }
 }
コード例 #7
0
 public void UriPatternsTest()
 {
     using (RecorderManager.NewPlayBackSession("test", false))
     {
         RemotingMockService.AddMockingUri("http://*/*?id=5");
         Assert.IsTrue(RemotingMockService.IsUriToMock("http://localhost/service.rem?id=5"));
         Assert.IsFalse(RemotingMockService.IsUriToMock("http://localhost/service.rem?id=6"));
         Assert.IsFalse(RemotingMockService.IsUriToMock("tcp://localhost/service.rem?id=5"));
     }
 }
コード例 #8
0
 public void LocalPattern00Test()
 {
     Assert.IsFalse(RemotingMockService.IsUriToMock("http://localhost/service.rem"));
     using (RecorderManager.NewPlayBackSession("test", false))
     {
         RemotingMockService.AddMockingUri("*");
         Assert.IsTrue(RemotingMockService.IsUriToMock("http://localhost/service.rem"));
     }
     Assert.IsFalse(RemotingMockService.IsUriToMock("http://localhost/service.rem"));
 }
コード例 #9
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);
     }
 }
コード例 #10
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);
        }
コード例 #11
0
 public void PropertyMock()
 {
     using (RecorderManager.NewRecordingSession("test"))
     {
         MockService.AddTypeToMock(typeof(Sample.Account));
         Sample.Account acc = new Sample.Account(Sample.CurrencyUnit.EUR);
         Assert.IsTrue(MockService.IsMock(acc));
         acc.Deposit(100m);
         acc.Withdraw(50m);
         Assert.IsTrue(acc.IsBalancePositive);
     }
     using (RecorderManager.NewPlayBackSession("test", true))
     {
         MockService.AddTypeToMock(typeof(Sample.Account));
         Sample.Account acc = new Sample.Account(Sample.CurrencyUnit.EUR);
         Assert.IsTrue(MockService.IsMock(acc));
         acc.Deposit(100m);
         acc.Withdraw(50m);
         Assert.IsTrue(acc.IsBalancePositive);
     }
 }
コード例 #12
0
        public void PlainObjectMockingTest()
        {
            // Running in no mocking state:
            PlainObjectMockingTest_Scenario(false, true);

            // Running recording:
            using (RecorderManager.NewRecordingSession("test"))
            {
                MockService.AddTypeToMock(typeof(Sample.PlainCurrencyService));
                PlainObjectMockingTest_Scenario(true, true);
            }
            // Running playback:
            using (RecorderManager.NewPlayBackSession("test", true))
            {
                MockService.AddTypeToMock(typeof(Sample.PlainCurrencyService));
                PlainObjectMockingTest_Scenario(true, false);
            }
            // Running playback without mocking the type:
            using (RecorderManager.NewRecordingSession("test")) { /* build empty scenario */ }
            using (RecorderManager.NewPlayBackSession("test", true))
            {
                PlainObjectMockingTest_Scenario(false, true);
            }
        }