public void HandleCall(MockingProxy proxy, MockableCall call)
		{
			if (call.IsConstructorCall)
			{
				call.SetConstructionResult("CurrencyMock");
			}
			else
			{
				if (call.Method.Name.Equals("ConvertAmount"))
				{
					// Retrieve call args:
					decimal amount = (decimal)call.InArgs[0];
					// Mock the call:
					call.SetCallResult(amount);
				}
				else
				{
					// Return from a void call:
					call.SetCallResult();
				}
			}
		}
Exemplo n.º 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 !
			}
		}