public void PurchaseServiceCanAffordProductWorksCorrectlyWhenInsufficientFundsAreIn()
        {
            //These could be mocked out, but since they are simple in memory
            //instaces there is no point.
            ISessionService sessionService = new InMemorySessionService();
            IItemRepository itemRepository = new ItemRepository();

            IPurchaseService purchaseService = new PurchaseService(itemRepository, sessionService);

            Guid sessionId = Guid.NewGuid();

            double tallyValue = 0.5;

            sessionService.StoreCurrentTally(sessionId, tallyValue);

            //If sufficient money is in a session, the item price minus the session tally is returned.
            double checkResult = tallyValue - itemRepository.GetItem(0).Price;
            double result      = purchaseService.CanAffordProduct(sessionId, 0);

            Assert.True(result < 0);
            Assert.True(checkResult == result);

            //Make sure the session hasn't been modified
            Assert.True(sessionService.GetStoredTally(sessionId) == tallyValue);
        }
Пример #2
0
        public void InMemorySessionServiceReturnsNegativeOneIfInvalidSession()
        {
            ISessionService service   = new InMemorySessionService();
            Guid            sessionId = Guid.NewGuid();
            double          tally     = 1;

            service.StoreCurrentTally(sessionId, tally);

            Assert.True(service.GetStoredTally(sessionId) == tally);
            Assert.True(service.GetStoredTally(Guid.Empty) == -1);
        }
Пример #3
0
        public void InMemorySessionServiceStoresValues()
        {
            ISessionService service   = new InMemorySessionService();
            Guid            sessionId = Guid.NewGuid();

            service.StoreCurrentTally(sessionId, 1);

            Assert.True(service.GetStoredTally(sessionId) == 1);

            service.StoreCurrentTally(sessionId, 2);

            Assert.True(service.GetStoredTally(sessionId) == 2);
        }
        public void PurchaseServiceBuyProductWorksCorrectly()
        {
            //These could be mocked out, but since they are simple in memory
            //instaces there is no point.
            ISessionService sessionService = new InMemorySessionService();
            IItemRepository itemRepository = new ItemRepository();

            IPurchaseService purchaseService = new PurchaseService(itemRepository, sessionService);

            Guid sessionId = Guid.NewGuid();

            double initialTallyValue = 2;

            sessionService.StoreCurrentTally(sessionId, initialTallyValue);

            purchaseService.BuyProduct(sessionId, 1);

            Assert.True(sessionService.GetStoredTally(sessionId) == (initialTallyValue - itemRepository.GetItem(1).Price));
        }