Example #1
0
        public void RetriveFromServerAtFirstTime()
        {
            IUsersRetriever usersRetriever = MockRepository.GenerateStrictMock <IUsersRetriever>();
            UsersCache      cache          = new UsersCache(usersRetriever);

            usersRetriever.Expect(r => r.RetrieveUserNameFromServer(1)).Return("Alex").Repeat.Once();

            var user = cache.GetUserById(1);

            usersRetriever.VerifyAllExpectations();
            Assert.Equal("Alex", user);
        }
Example #2
0
        public void DoNotConnectToServerAtSecondAndNextTimes()
        {
            IUsersRetriever usersRetriever = MockRepository.GenerateStrictMock <IUsersRetriever>();
            UsersCache      cache          = new UsersCache(usersRetriever);

            usersRetriever.Expect(r => r.RetrieveUserNameFromServer(1)).Return("Alex").Repeat.Once();
            usersRetriever.Expect(r => r.RetrieveUserNameFromServer(1)).Repeat.Never();
            var firstTimeUserRetrieved = cache.GetUserById(1);

            usersRetriever.Expect(r => r.RetrieveUserNameFromServer(1)).Repeat.Never();

            var secondTimeUserRetrieved = cache.GetUserById(1);

            usersRetriever.VerifyAllExpectations();
            Assert.Equal("Alex", firstTimeUserRetrieved);
            Assert.Equal("Alex", secondTimeUserRetrieved);
        }