Esempio n. 1
0
        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(1025);
                LastCall.Return(anotherRoomOccupant);
            }

            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);
        }
Esempio n. 2
0
        public void TestThatHotelDoesGetRoomOccupantFromTheDatabase()
        {
            IDatabase mockDatabase = mocks.Stub<IDatabase>();
            String roomOccupant = "Whale Rider";
            String anotherRoomOccupant = "Raptor Wrangler";

            using (mocks.Record())
            {
                // The mock will return "Whale Rider" when the call is made with 24
                mockDatabase.getRoomOccupant(24);
                // LastCall.Throw(new Exception());
                LastCall.Return(roomOccupant);
                // The mock will return "Raptor Wrangler" when the call is made with 1025
                mockDatabase.getRoomOccupant(1025);
                LastCall.Return(anotherRoomOccupant);
            }

            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);
        }
Esempio n. 3
0
        public void TestThatHotelDoesGetRoomOccupantFromTheDatabase()
        {
            IDatabase mockDatabase = mocks.Stub<IDatabase>();
            String roomOccupant = "Whale Rider";
            String anotherRoomOccupant = "Raptor Wrangler";

            // Uses the "Record and Replay" model discussed in class.
            using (mocks.Record())
            {
                // The mock with 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);
            }

               // Set up the target object that we are testing.
            var target = new Hotel(10);
            target.Database = mockDatabase;

            // Use the target and call the getRoomOccupant method, asserting the expectations.
            String result;

            result = target.getRoomOccupant(1025);
            Assert.AreEqual(result, anotherRoomOccupant);

            result = target.getRoomOccupant(24);
            Assert.AreEqual(result, roomOccupant);
        }