public void TestThatHotelDoesGetRoomOccupantFromTheDatabase() { IDatabase mockDatabase = mocks.Stub <IDatabase>(); String roomOccupant = "Sexy Beast"; String anotherRoomOccupant = "Provocative Critter"; using (mocks.Record()) { mockDatabase.getRoomOccupant(24); LastCall.Return(roomOccupant); mockDatabase.getRoomOccupant(1025); LastCall.Return(anotherRoomOccupant); } var target = new Hotel(10); target.Database = mockDatabase; String result = target.getRoomOccupant(1025); Assert.AreEqual(result, anotherRoomOccupant); result = target.getRoomOccupant(24); Assert.AreEqual(result, roomOccupant); }
public void TestThatCarGetsCorrectLocation() { IDatabase mockDatabase = mocks.Stub <IDatabase>(); String carLocation1 = "Tallahassee, FL"; String carLocation2 = "Dallas, TX"; using (mocks.Record()) { //The mock will return "Tallahassee, FL" When the given carNumber is 4145 mockDatabase.getCarLocation(4145); LastCall.Return(carLocation1); //The mock will return "Dallas, TX" when the given carNumber is 9000 mockDatabase.getCarLocation(9000); LastCall.Return(carLocation2); } var target = ObjectMother.Saab(); target.Database = mockDatabase; String result = target.getCarLocation(4145); Assert.AreEqual(result, carLocation1); result = target.getCarLocation(9000); Assert.AreEqual(result, carLocation2); }
public void TestThatCarLocationIsCorrectInDatabase() { IDatabase mockDatabase mocks.Stub <IDatabase>(); String myCarLoc = "Japan"; String otherCarLoc = "Ireland"; using (mocks.Record()) { mockDatabase.getCarLocation(12); LastCall.Return(myCarLoc); mockDatabase.getCarLocation(42); LastCall.Return(otherCarLoc); } var target = new Car(365); target.Database = mockDatabase; String result; result = target.getCarLocation(12); Assert.AreEqual(result, myCarLoc); result = target.getCarLocation(42); Assert.AreEqual(result, otherCarLoc); }
public void TestCarLocation() { IDatabase mockDatabase = mocks.Stub <IDatabase>(); String location = "Terre Haute, IN"; String anotherLocation = "Lexington, KY"; using (mocks.Record()) { // The mock will return "Whale Rider" when the call is made with 24 mockDatabase.getCarLocation(50); LastCall.Return(location); // The mock will return "Raptor Wrangler" when the call is made with 1025 mockDatabase.getCarLocation(1025); LastCall.Return(anotherLocation); } var target = new Car(11); target.Database = mockDatabase; String result; result = target.getCarLocation(50); Assert.AreEqual(result, location); result = target.getCarLocation(1025); Assert.AreEqual(result, anotherLocation); }
private void CreateMocks() { mockConnectionFactory = (IConnectionFactory)mocks.CreateMock(typeof(IConnectionFactory)); mockConnection = (IConnection)mocks.CreateMock(typeof(IConnection)); mockSession = (ISession)mocks.CreateMock(typeof(ISession)); TIBCO.EMS.Queue queue = new TIBCO.EMS.Queue("test"); //(Queue) mocks.CreateMock(typeof (Queue)); Expect.Call(mockConnectionFactory.CreateConnection()).Return(mockConnection).Repeat.Once(); if (UseTransactedTemplate) { Expect.Call(mockConnection.CreateSession(true, Session.SESSION_TRANSACTED)).Return(mockSession).Repeat. Once(); } else { Expect.Call(mockConnection.CreateSession(false, Session.AUTO_ACKNOWLEDGE)).Return(mockSession). Repeat. Once(); } Expect.Call(mockSession.Transacted).Return(true); mockDestinationResolver = (IDestinationResolver)mocks.CreateMock(typeof(IDestinationResolver)); mockDestinationResolver.ResolveDestinationName(mockSession, "testDestination", false); LastCall.Return(queue).Repeat.Any(); }
public void TestThatHotelDoesGetRoomOccupantFromTheDatabase() { IDatabase mockDatabase = mocks.Stub <IDatabase>(); String roomOccupant = "Whale Rider"; String anotherRoomOccupant = "Raptor Wrangler"; using (mocks.Record()) { mockDatabase.getRoomOccupant(24); LastCall.Return(roomOccupant); mockDatabase.getRoomOccupant(1024); LastCall.Return(anotherRoomOccupant); } var target = new Hotel(10); target.Database = mockDatabase; String result; result = target.getRoomOccupant(1024); Assert.AreEqual(anotherRoomOccupant, result); result = target.getRoomOccupant(24); Assert.AreEqual(roomOccupant, result); }
public void Parse_SingleNodeNoPrecondition_NoProblems() { AssignabilityPreCondition[] preConditions = (new List <AssignabilityPreCondition>()).ToArray(); SymbolTable postConditions = new SymbolTable(_blacklistManager); int[] successors = (new List <int>()).ToArray(); BasicBlock node = new BasicBlock(0, preConditions, postConditions, successors, c_EmptyAssignments); using (_mocks.Record()) { _methodGraph.IsEmpty(); LastCall.Return(false); SetupResult.For(_methodGraph.InitialBlock) .Return(node); SetupResult.For(_methodGraph.Blocks) .Return(new BasicBlock[] { node }); _methodGraphBuilder.GetResult(); LastCall.Return(_methodGraph); _parameterSymbolTableBuilder.GetResult(); LastCall.Return(_methodPreConditions); } ProblemCollection result = ParseGraph(); Assert.That(result.Count, Is.EqualTo(0)); }
public void GetCountryNameByNumber_PhoneNumberInDresdenGermany_ReturnsGermany() { MockRepository mocks = new MockRepository(); IPhoneNumberDataXml xmlDataProvider = mocks.Stub <IPhoneNumberDataXml>(); IPhoneNumberDataRegistry registryDataProvider = mocks.Stub <IPhoneNumberDataRegistry>(); string number = "+493511234567"; string expected = "Deutschland"; using (mocks.Record()) { xmlDataProvider.GetCountryCode("4935"); LastCall.Return("49"); xmlDataProvider.GetAreaCode("+493511234567"); LastCall.Return("+49351"); xmlDataProvider.GetCountryID("+49351"); LastCall.Return("49"); registryDataProvider.GetCountryName(49); LastCall.Return(expected); } PhoneNumbers phoneNumberConverter = new PhoneNumbers(xmlDataProvider, registryDataProvider); string actual = phoneNumberConverter.GetCountryNameByNumber(number); Assert.AreEqual(expected, actual); }
public void GetCountryNameByNumber_PhoneNumberInDresdenGermanyWithoutRegistryAccess_GetsCountryNameFromXML() { MockRepository mocks = new MockRepository(); IPhoneNumberDataXml xmlDataProvider = mocks.StrictMock <IPhoneNumberDataXml>(); IPhoneNumberDataRegistry registryDataProvider = mocks.Stub <IPhoneNumberDataRegistry>(); string number = "+493511234567"; using (mocks.Record()) { xmlDataProvider.GetCountryCode("4935"); LastCall.Return("49"); xmlDataProvider.GetAreaCode("+493511234567"); LastCall.Return("+49351"); xmlDataProvider.GetCountryID("+49351"); LastCall.Return("49"); xmlDataProvider.GetCountryName(49); LastCall.Return("Germany"); } PhoneNumbers phoneNumberConverter = new PhoneNumbers(xmlDataProvider, registryDataProvider); phoneNumberConverter.GetCountryNameByNumber(number); mocks.VerifyAll(); }
public void TestBasicInterceptionExceptionThrow() { //Create and mock the interceptor. MockRepository mock = new MockRepository(); IAspect hmock = mock.CreateMock <IAspect>(); hmock.PreCall(null); LastCall.Return(MethodVoteOptions.Continue) .IgnoreArguments(); hmock.OnException(null, null, null); LastCall.Constraints( new Rhino.Mocks.Constraints.Anything(), Rhino.Mocks.Constraints.Is.TypeOf(typeof(NullReferenceException)), Rhino.Mocks.Constraints.Is.Anything()); mock.ReplayAll(); using (TestContainer container = new TestContainer(@"Concrete\Castle\AOP\TestSuite1\Configs\ConfigSample1.config")) { container.Kernel.RemoveComponent("interceptor"); container.Kernel.AddComponentInstance("interceptor", hmock); try { container.Resolve <ISomething>().OtherMethod(null, null); Assert.Fail("If reach here exception was not thrown"); } catch (Exception) { } } mock.VerifyAll(); }
public void FormatPhoneNumber_PhoneNumberInDresdenGermany_ReturnsFormattedNumber( [Values(DISTANCE_RULE.CANONICAL, DISTANCE_RULE.InternationalRule, DISTANCE_RULE.LongDistanceRule, DISTANCE_RULE.SameAreaRule)] DISTANCE_RULE distanceRule, [Values("+49 (351) 1234567", "00493511234567", "03511234567", "1234567")] string expected) { MockRepository mocks = new MockRepository(); IPhoneNumberDataXml xmlDataProvider = mocks.Stub <IPhoneNumberDataXml>(); IPhoneNumberDataRegistry registryDataProvider = mocks.Stub <IPhoneNumberDataRegistry>(); string number = "+493511234567"; using (mocks.Record()) { registryDataProvider.GetUserCountryID(); LastCall.Return("49"); registryDataProvider.GetUserAreaCode(); LastCall.Return("351"); registryDataProvider.GetPhoneFormat(49, DISTANCE_RULE.InternationalRule); LastCall.Return("00EFG"); registryDataProvider.GetPhoneFormat(49, DISTANCE_RULE.LongDistanceRule); LastCall.Return("0FG"); registryDataProvider.GetPhoneFormat(49, DISTANCE_RULE.SameAreaRule); LastCall.Return("G"); xmlDataProvider.GetCountryCode("4935"); LastCall.Return("49"); xmlDataProvider.GetAreaCode("+493511234567"); LastCall.Return("+49351"); } PhoneNumbers phoneNumberConverter = new PhoneNumbers(xmlDataProvider, registryDataProvider); string actual = phoneNumberConverter.FormatPhoneNumber(number, distanceRule); Assert.AreEqual(expected, actual); }
public void TestThatCarDoesGetCarLocationFromDatabase() { IDatabase mockDatabase = mocks.Stub <IDatabase>(); string location1 = "The Moon"; string location2 = "Mars"; using (mocks.Record()) { mockDatabase.getCarLocation(5); LastCall.Return(location1); mockDatabase.getCarLocation(7); LastCall.Return(location2); } var target = new Car(10); target.Database = mockDatabase; string rval = target.getCarLocation(7); Assert.AreEqual(rval, location2); rval = target.getCarLocation(5); Assert.AreEqual(rval, location1); }
public void ReturnResultsFromMock() { MockRepository repository = new MockRepository(); IGetRestuls resultGetter = repository.DynamicMock <IGetRestuls>(); using (repository.Record()) { resultGetter.GetSomeNumber("a"); LastCall.Return(1); resultGetter.GetSomeNumber("a"); LastCall.Return(2); resultGetter.GetSomeNumber("b"); LastCall.Return(3); } int result = resultGetter.GetSomeNumber("b"); Assert.AreEqual(3, result); int result2 = resultGetter.GetSomeNumber("a"); Assert.AreEqual(1, result2); int result3 = resultGetter.GetSomeNumber("a"); Assert.AreEqual(2, result3); }
public void TestThatCarGetsLocation() { IDatabase mockDatabase = mocks.Stub <IDatabase>(); String location1 = "here"; String location2 = "OVER NINE THOUSAND!"; using (mocks.Record()) { mockDatabase.getCarLocation(2); LastCall.Return(location1); mockDatabase.getCarLocation(9001); LastCall.Return(location2); } var target = new Car(10); target.Database = mockDatabase; String result; result = target.getCarLocation(2); Assert.AreEqual(result, location1); result = target.getCarLocation(9001); Assert.AreEqual(result, location2); }
private void SetUpConventionalExistsTest(Guid id, decimal countSqlReturn) { var factory = mocks.Stub <ISqlProviderFactory>(); ProvisionedProvider.SetFactory(factory); var provider = mocks.DynamicMock <ISqlProvider>(); string expectedSql = String.Format("SELECT count(*) FROM Entity WHERE IdEntity = '{0}'", id); using (mocks.Record()) { factory.CreateProvider("some string"); LastCall.Return(provider).IgnoreArguments(); var res = new StubSqlResult() { ReturnObject = countSqlReturn }; var resList = new List <ISqlResult> { res }; provider.ExecuteQuery(expectedSql, SelectOptions.Single); LastCall.Return(resList); } }
public void LastCallReturn() { demo.ReturnIntNoArgs(); LastCall.Return(5); mocks.ReplayAll(); Assert.Equal(5, demo.ReturnIntNoArgs()); }
public void TesteAssineRegraCargoJacadastrado() { var cargo = new Cargo(); var mockRepositorio = new MockRepository(); // DLL var repositorio = mockRepositorio.StrictMock <IRepositorioCargo>(); using (mockRepositorio.Record()) { repositorio.Consulte(1); LastCall.Return(new Cargo()); LastCall.IgnoreArguments(); } var validadorDeCargo = new ValidadorDeCargo <Cargo>(repositorio); validadorDeCargo.AssineRegraCargoJaCadastrado(); var resultado = validadorDeCargo.Validate(cargo); Assert.AreEqual(1, resultado.Errors.Count); Assert.AreEqual( "Cargo já cadastrado.", resultado.Errors[0].ErrorMessage); Assert.AreEqual( "Codigo", resultado.Errors[0].PropertyName); }
public void Commit_WithReturnValue_SelectExecutedAsExpected() { //INSERT INTO Address (ID, IdPerson) VALUES('7e7304db-2b77-4040-ae64-9eb6a686a036', 1) var factory = GetProviderFactory(); var provider = new StubSqlProvider(); provider.SetObjectToReturn(1); using (mocks.Record()) { factory.CreateProvider("somestring"); LastCall.Return(provider).IgnoreArguments(); } Guid personId = Guid.NewGuid(); DataBoy .ForTable("Person") .Row("Id", personId) .ReturnValue("IdPerson").AtKey("IdOfPerson") //.ForTable("Address") // .Row("Id", Guid.NewGuid()) // .BindColumn("IdPerson").To("IdOfPerson") .Commit(); //HasAnySqlMatching string expectedSql = string.Format("SELECT IdPerson FROM Person WHERE Id = '{0}'", personId); Assert.IsTrue(provider.HasAnySqlMatching(expectedSql)); }
public void Parse_SingleNodeNewPrecondition_ReturnsProblem() { AssignabilityPreCondition[] preConditions = { new AssignabilityPreCondition("z", Fragment.CreateNamed("SqlFragment")) }; SymbolTable postConditions = new SymbolTable(_blacklistManager); int[] successors = (new List <int>()).ToArray(); BasicBlock node = new BasicBlock(0, preConditions, postConditions, successors, c_EmptyAssignments); using (_mocks.Record()) { _methodGraph.IsEmpty(); LastCall.Return(false); SetupResult.For(_methodGraph.InitialBlock) .Return(node); SetupResult.For(_methodGraph.Blocks) .Return(new BasicBlock[] { node }); _methodGraphBuilder.GetResult(); LastCall.Return(_methodGraph); _parameterSymbolTableBuilder.GetResult(); LastCall.Return(_methodPreConditions); } ProblemCollection result = ParseGraph(); Assert.That(TestHelper.ContainsProblemID(c_InjectionCopRuleId, result), Is.True); }
public void Commit_BindColumnToForInsert_InsertWorksCorrectly() { var factory = GetProviderFactory(); var provider = new StubSqlProvider(); provider.SetObjectToReturn(1); using (mocks.Record()) { factory.CreateProvider("somestring"); LastCall.Return(provider).IgnoreArguments(); } Guid personId = Guid.NewGuid(); Guid addressId = Guid.NewGuid(); DataBoy .ForTable("Person") .Row("Id", personId) .ReturnValue("IdPerson").AtKey("IdOfPerson") .ForTable("Address") .Row("Id", addressId) .BindColumn("IdPerson").To("IdOfPerson") .Commit(); string expectedSql = string.Format("INSERT INTO Address (ID, IdPerson) VALUES('{0}', 1)", addressId); Assert.IsTrue(provider.HasAnySqlMatching(expectedSql)); }
public void TestThatHotelDoesGetRoomOccupantFromTheDatabase() { IDatabase mockDatabase = mocks.Stub <IDatabase>(); String roomOccupant = "Whale Rider"; String anotherRoomOccupant = "Raptor Wrangler"; String extraRoomOccupant = "Holy Diver"; using (mocks.Record()) { // The mock will return "Whale Rider" when the call is made with 24 mockDatabase.getRoomOccupant(24); LastCall.Return(roomOccupant); // The mock will return "Raptor Wrangler" when the call is made with 1025 mockDatabase.getRoomOccupant(1025); LastCall.Return(anotherRoomOccupant); mockDatabase.getRoomOccupant(2); LastCall.Return(extraRoomOccupant); } var target = new Hotel(10); target.Database = mockDatabase; String result; result = target.getRoomOccupant(1025); Assert.AreEqual(result, anotherRoomOccupant); result = target.getRoomOccupant(24); Assert.AreEqual(result, roomOccupant); result = target.getRoomOccupant(2); Assert.AreEqual(result, extraRoomOccupant); }
public void Commit_MultipleRows_SendsSqlsInCorrectOrder() { var factory = GetProviderFactory(); var provider = new StubSqlProvider(); using (mocks.Record()) { factory.CreateProvider("somestring"); LastCall.Return(provider).IgnoreArguments(); } DataBoy .ForTable("Person") .Row("IdPerson", 1).Data("Surname", "Obama").DeleteFirst() .Row("IdPerson", 2).Data("Surname", "Bush").DeleteFirst() .ForTable("Address") .Row("IdAddress", 100).Data("Street", "Main street").DeleteFirst() .Commit(); Assert.AreEqual("DELETE FROM Address WHERE IdAddress = 100", provider.GetExecutedQuery(0)); Assert.AreEqual("DELETE FROM Person WHERE IdPerson = 2", provider.GetExecutedQuery(1)); Assert.AreEqual("DELETE FROM Person WHERE IdPerson = 1", provider.GetExecutedQuery(2)); Assert.AreEqual("INSERT INTO Person (IDPERSON, SURNAME) VALUES(1, 'Obama')", provider.GetExecutedQuery(3)); Assert.AreEqual("INSERT INTO Person (IDPERSON, SURNAME) VALUES(2, 'Bush')", provider.GetExecutedQuery(4)); Assert.AreEqual("INSERT INTO Address (IDADDRESS, STREET) VALUES(100, 'Main street')", provider.GetExecutedQuery(5)); }
public void AnalyzeFile_FileWith3Lines_CallsLogProvider3Times_AAA() { MockRepository mocks = new MockRepository(); ILogProvider mockLog = mocks.StrictMock <ILogProvider>(); LogAnalyzer log = new LogAnalyzer(mockLog); using (mocks.Record()) { mockLog.GetLineCount(); LastCall.Return(3); mockLog.GetText("someFile.txt", 1, 1); LastCall.Return("a"); mockLog.GetText("someFile.txt", 2, 2); LastCall.Return("b"); mockLog.GetText("someFile.txt", 3, 3); LastCall.Return("c"); } AnalyzeResults results = log.AnalyzeFile("someFile.txt"); mocks.VerifyAll(); }
public void TestThatCarDoesGetLocationFromTheDatabase() { IDatabase mockDatabase = mocks.Stub <IDatabase>(); String car = "Beetle"; String truck = "Wat"; using (mocks.Record()) { mockDatabase.getCarLocation(1); LastCall.Return(car); mockDatabase.getCarLocation(2); LastCall.Return(truck); } var target = new Car(10); target.Database = mockDatabase; String result = target.getCarLocation(1); Assert.AreEqual(result, car); result = target.getCarLocation(2); Assert.AreEqual(result, truck); }
private StandardHookInTension CreateHookObject(double ConcStrength, double RebarDiameter, bool IsEpoxyCoated, ConcreteTypeByWeight typeByWeight, double ExcessFlexureReinforcementRatio) { MockRepository mocks = new MockRepository(); IRebarMaterial rebarMat = mocks.Stub <IRebarMaterial>(); Expect.Call(rebarMat.YieldStress).Return(60000); Rebar rebar = new Rebar(RebarDiameter, IsEpoxyCoated, rebarMat); ICalcLogEntry entryStub = mocks.Stub <ICalcLogEntry>(); ICalcLog logStub = mocks.Stub <ICalcLog>(); //IConcreteMaterial ConcStub = mocks.Stub<IConcreteMaterial>(); IConcreteMaterial ConcStub = new ConcreteMaterial(ConcStrength, typeByWeight, logStub) as IConcreteMaterial; ConcStub.SpecifiedCompressiveStrength = ConcStrength; ConcStub.TypeByWeight = typeByWeight; using (mocks.Record()) { logStub.CreateNewEntry(); LastCall.Return(entryStub); } StandardHookInTension tensHook = new StandardHookInTension(ConcStub, rebar, logStub, ExcessFlexureReinforcementRatio); return(tensHook); }
public void TestThatCarDoesGetCarLocationFromTheDatabase() { IDatabase mockDatabase = mocks.Stub <IDatabase>(); String carLocation = "there"; String anotherCarLocation = "everywhere"; using (mocks.Record()) { mockDatabase.getCarLocation(17); LastCall.Return(carLocation); mockDatabase.getCarLocation(5); LastCall.Return(anotherCarLocation); } var target = new Car(10); target.Database = mockDatabase; String result; result = target.getCarLocation(5); Assert.AreEqual(result, anotherCarLocation); result = target.getCarLocation(17); Assert.AreEqual(result, carLocation); }
private void CreateMocks() { mockConnectionFactory = mocks.StrictMock <IConnectionFactory>(); mockConnection = mocks.StrictMock <IConnection>(); mockSession = mocks.StrictMock <ISession>(); IQueue queue = mocks.StrictMock <IQueue>(); Expect.Call(mockConnectionFactory.CreateConnection()).Return(mockConnection).Repeat.Once(); if (UseTransactedTemplate) { Expect.Call(mockConnection.CreateSession(AcknowledgementMode.Transactional)).Return(mockSession).Repeat. Once(); } else { Expect.Call(mockConnection.CreateSession(AcknowledgementMode.AutoAcknowledge)).Return(mockSession). Repeat. Once(); } Expect.Call(mockSession.Transacted).Return(true); mockDestinationResolver = mocks.StrictMock <IDestinationResolver>(); mockDestinationResolver.ResolveDestinationName(mockSession, "testDestination", false); LastCall.Return(queue).Repeat.Any(); }
public void TestClientConnectionLoginSuccess() { using (mocks.Record()) { mockSocket.connect(iSocket.constants.host, iSocket.constants.defaultPort); LastCall.On(mockSocket).Repeat.Once(); // Caesura mockSocket.send(iSocket.aSocket.stringToBytes("Caesura" + "\0", iSocket.constants.MAXPACKETSIZE)); LastCall.On(mockSocket).Repeat.Once(); // Major mockSocket.send(iSocket.aSocket.stringToBytes(iSocket.constants.MajorNumber, iSocket.constants.MAXPACKETSIZE)); LastCall.On(mockSocket).Repeat.Once(); // Minor mockSocket.send(iSocket.aSocket.stringToBytes(iSocket.constants.MinorNumber, iSocket.constants.MAXPACKETSIZE)); LastCall.On(mockSocket).Repeat.Once(); // Username mockSocket.send(iSocket.aSocket.stringToBytes("TestUser" + "\0", iSocket.constants.MAXPACKETSIZE)); LastCall.On(mockSocket).Repeat.Once(); // Password mockSocket.send(iSocket.aSocket.stringToBytes("TestPass" + "\0", iSocket.constants.MAXPACKETSIZE)); LastCall.On(mockSocket).Repeat.Once(); mockSocket.receive(iSocket.constants.MAXPACKETSIZE); LastCall.Return(iSocket.aSocket.stringToBytes("True", iSocket.constants.MAXPACKETSIZE)); } Assert.True(connection.login("TestUser", "TestPass")); mocks.VerifyAll(); }
public void TestCarLocation() { IDatabase mockDatabase = mocks.Stub <IDatabase>(); String car1 = "Here"; String car2 = "There"; using (mocks.Record()) { mockDatabase.getCarLocation(5); LastCall.Return(car1); mockDatabase.getCarLocation(8); LastCall.Return(car2); } var target = new Car(5); target.Database = mockDatabase; String result; result = target.getCarLocation(5); Assert.AreEqual(result, car1); result = target.getCarLocation(8); Assert.AreEqual(result, car2); }
public void TestThatCarDoesGetCarLocationFromTheDatabase() { IDatabase mockDatabase = mocks.Stub <IDatabase>(); int car1 = 10; String car1Location = "Hawaii"; int car2 = 50; String car2Location = "Indiana"; using (mocks.Record()) { mockDatabase.getCarLocation(car1); LastCall.Return(car1Location); mockDatabase.getCarLocation(car2); LastCall.Return(car2Location); } var target = new Car(10); target.Database = mockDatabase; String result; result = target.getCarLocation(10); Assert.AreEqual(result, car1Location); result = target.getCarLocation(50); Assert.AreEqual(result, car2Location); }