public async Task Return_ShoppingCartItem_When_Correct_Carameters_Are_Passed()
        {
            var userId           = "a";
            var mockShoppingCart = ShoppingCardMock
                                   .GetMockShoppingCart(userId)
                                   .ShoppingCartItems.ToList()
                                   .FirstOrDefault();

            var userShoppingCartItem = new UserShoppingCartItem()
            {
                ShoppingCartItem = mockShoppingCart,
                UserId           = userId
            };

            var requestProviderMock = new Mock <IRequestProvider>();

            requestProviderMock
            .Setup(e => e.PostAsync <UserShoppingCartItem>(It.IsAny <string>(), It.IsAny <UserShoppingCartItem>(), It.IsAny <string>()))
            .Returns(Task.FromResult <UserShoppingCartItem>(userShoppingCartItem));

            var shoppingCartDataService = new ShoppingCartDataService(requestProviderMock.Object);

            var shoppingCartOrderResult = await shoppingCartDataService.AddShoppingCartItem(mockShoppingCart, userId);

            Assert.NotNull(shoppingCartOrderResult);
            Assert.AreEqual(shoppingCartOrderResult.UserId, userId);
            Assert.NotNull(shoppingCartOrderResult.ShoppingCartItem);
        }
Example #2
0
        public void Throws_When_Invalid_UserId_Is_Passed(string userId)
        {
            var mockShoppingCart = ShoppingCardMock.GetMockShoppingCart(userId);

            var requestProviderMock = new Mock <IRequestProvider>();

            requestProviderMock
            .Setup(e => e.GetAsync <ShoppingCart>(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(Task.FromResult <ShoppingCart>(mockShoppingCart));

            var shoppingCartDataService = new ShoppingCartDataService(requestProviderMock.Object);

            Assert.ThrowsAsync <ShoppingCartDataServiceException>(
                async() => await shoppingCartDataService.GetShoppingCart(userId));
        }
Example #3
0
        public async Task Return_ShoppingCart_When_Correct_Carameters_Are_Passed()
        {
            var userId           = "a";
            var mockShoppingCart = ShoppingCardMock.GetMockShoppingCart(userId);

            var requestProviderMock = new Mock <IRequestProvider>();

            requestProviderMock
            .Setup(e => e.GetAsync <ShoppingCart>(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(Task.FromResult <ShoppingCart>(mockShoppingCart));

            var shoppingCartDataService = new ShoppingCartDataService(requestProviderMock.Object);

            var addedOrderResult = await shoppingCartDataService.GetShoppingCart(userId);

            Assert.NotNull(addedOrderResult);
            Assert.AreEqual(addedOrderResult.ShoppingCartId, mockShoppingCart.ShoppingCartId);
            Assert.AreEqual(addedOrderResult.UserId, mockShoppingCart.UserId);
            Assert.NotNull(addedOrderResult.ShoppingCartItems);
            Assert.AreEqual(addedOrderResult.ShoppingCartItems.ToList().Count, 1);
        }
        public void Throws_When_Invalid_UserId_Is_Passed(string userId)
        {
            var mockShoppingCart = ShoppingCardMock
                                   .GetMockShoppingCart(userId)
                                   .ShoppingCartItems.ToList()
                                   .FirstOrDefault();

            var userShoppingCartItem = new UserShoppingCartItem()
            {
                ShoppingCartItem = mockShoppingCart,
                UserId           = userId
            };

            var requestProviderMock = new Mock <IRequestProvider>();

            requestProviderMock
            .Setup(e => e.PostAsync <UserShoppingCartItem>(It.IsAny <string>(), It.IsAny <UserShoppingCartItem>(), It.IsAny <string>()))
            .Returns(Task.FromResult <UserShoppingCartItem>(userShoppingCartItem));

            var shoppingCartDataService = new ShoppingCartDataService(requestProviderMock.Object);

            Assert.ThrowsAsync <ShoppingCartDataServiceException>(
                async() => await shoppingCartDataService.AddShoppingCartItem(mockShoppingCart, userId));
        }