Esempio n. 1
0
        public void WhenCollectionIsNotEmptyThenGetAllReturnsInfoCollection()
        {
            var testContext = new TestContext();

            var inMemoryCollection = new CartsCollection();

            inMemoryCollection.Add(new CartsCollection.CartsCollectionEntry(
                                       new CartInfo(), testContext.CartFactory.Create()));

            var controller = new CartController(null, inMemoryCollection,
                                                testContext.CartFactory, testContext.PriceList, new NeutralPipeline());

            var response = controller.GetAll();

            Assert.NotNull(response);
            Assert.Equal(CartOperationStatus.Successful, response.Status);
            Assert.NotEmpty(response.Body);
            Assert.Single(response.Body);
        }
Esempio n. 2
0
        public void CannotDeleteCheckedOutCart()
        {
            var testContext = new TestContext();

            var inMemoryCollection = new CartsCollection();
            var cartEntry          = new CartsCollection.CartsCollectionEntry(
                new CartInfo(), testContext.CartFactory.Create());

            cartEntry.Info.CheckedOut = true;
            inMemoryCollection.Add(cartEntry);
            var controller = new CartController(null, inMemoryCollection,
                                                testContext.CartFactory, testContext.PriceList, new NeutralPipeline());

            var response = controller.Delete(cartEntry.Id);

            Assert.NotNull(response);
            Assert.Equal(CartOperationStatus.Error, response.Status);
            Assert.NotNull(response.Exception);
            Assert.Null(response.Body);
        }
Esempio n. 3
0
        public void WhenCheckoutEmptyCartThenExceptionIsReturnedInMessage()
        {
            var testContext = new TestContext();

            var inMemoryCollection = new CartsCollection();
            var cartEntry          = new CartsCollection.CartsCollectionEntry(
                new CartInfo(), testContext.CartFactory.Create());

            inMemoryCollection.Add(cartEntry);

            var controller = new CartController(null, inMemoryCollection,
                                                testContext.CartFactory, testContext.PriceList, new NeutralPipeline());

            var response = controller.Checkout(cartEntry.Id);

            Assert.NotNull(response);
            Assert.Equal(CartOperationStatus.Error, response.Status);
            Assert.NotNull(response.Exception);
            Assert.Null(response.Body);
        }
Esempio n. 4
0
        public void WhenCheckoutCartThenCartMarkedInCollectionAndNotRemoved()
        {
            var testContext = new TestContext();

            var inMemoryCollection = new CartsCollection();
            var cartEntry          = new CartsCollection.CartsCollectionEntry(
                new CartInfo(), testContext.CartFactory.Create());

            cartEntry.Cart.Add(testContext.CreateNewSku("A", 100));
            inMemoryCollection.Add(cartEntry);

            var controller = new CartController(null, inMemoryCollection,
                                                testContext.CartFactory, testContext.PriceList, new NeutralPipeline());

            var response = controller.Checkout(cartEntry.Id);

            Assert.NotNull(response);
            Assert.Equal(CartOperationStatus.Successful, response.Status);
            Assert.NotNull(response.Body);
            Assert.True(cartEntry.Info.CheckedOut);
        }
Esempio n. 5
0
        public void WhenCartExistsThenGetCartReturnsCartContent()
        {
            var testContext = new TestContext();

            var inMemoryCollection = new CartsCollection();
            var cartEntry          = new CartsCollection.CartsCollectionEntry(
                new CartInfo(), testContext.CartFactory.Create());

            inMemoryCollection.Add(cartEntry);

            var controller = new CartController(null, inMemoryCollection,
                                                testContext.CartFactory, testContext.PriceList, new NeutralPipeline());

            var response = controller.GetCart(cartEntry.Id);

            Assert.NotNull(response);
            Assert.Equal(CartOperationStatus.Successful, response.Status);
            Assert.Null(response.Exception);
            Assert.NotNull(response.Body);
            Assert.NotNull(response.Body.Info);
            Assert.NotNull(response.Body.CartEntries);
        }
Esempio n. 6
0
        public void WhenAddingToCartThenCartIsUpdatedInCollection()
        {
            var testContext = new TestContext();

            var sku = testContext.CreateNewSku("A", 100);

            var inMemoryCollection = new CartsCollection();
            var cartEntry          = new CartsCollection.CartsCollectionEntry(
                new CartInfo(), testContext.CartFactory.Create());

            inMemoryCollection.Add(cartEntry);
            Assert.Empty(cartEntry.Cart);

            var controller = new CartController(null, inMemoryCollection,
                                                testContext.CartFactory, testContext.PriceList, new NeutralPipeline());

            var response = controller.Add(cartEntry.Id, sku.Id, null);

            Assert.NotNull(response);
            Assert.Equal(CartOperationStatus.Successful, response.Status);
            Assert.NotNull(response.Body);
            Assert.NotEmpty(cartEntry.Cart);
        }
Esempio n. 7
0
        public void WhenAddingToCheckedOutCartThenExceptionIsReturnedInMessage()
        {
            var testContext = new TestContext();

            var sku = testContext.CreateNewSku("A", 100);

            var inMemoryCollection = new CartsCollection();
            var cartEntry          = new CartsCollection.CartsCollectionEntry(
                new CartInfo(), testContext.CartFactory.Create());

            cartEntry.Info.CheckedOut = true;
            inMemoryCollection.Add(cartEntry);

            var controller = new CartController(null, inMemoryCollection,
                                                testContext.CartFactory, testContext.PriceList, new NeutralPipeline());

            var response = controller.Add(cartEntry.Id, sku.Id, null);

            Assert.NotNull(response);
            Assert.Equal(CartOperationStatus.Error, response.Status);
            Assert.NotNull(response.Exception);
            Assert.Null(response.Body);
        }