Ejemplo n.º 1
0
        public void WhenRemovingNonExistingCartThenNoChangesInCollectionAndNullIsReturned()
        {
            var cartsCollection = new TestCartsCollection();

            Assert.Equal(0, cartsCollection.Count);
            Assert.Null(cartsCollection.Remove("001"));
            Assert.Equal(0, cartsCollection.Count);
        }
Ejemplo n.º 2
0
        public void WhenAddingNullThenNoChangesInCollection()
        {
            var cartsCollection = new TestCartsCollection();

            cartsCollection.Add(null);

            Assert.Equal(0, cartsCollection.Count);
        }
Ejemplo n.º 3
0
        public void AddCartEntryToCollection()
        {
            var testContext = new TestContext();

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

            cartsCollection.Add(cartEntry);

            Assert.Equal(1, cartsCollection.Count);
        }
Ejemplo n.º 4
0
        public void RetrieveCartEntryFromCollection()
        {
            var testContext = new TestContext();

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

            cartsCollection.Add(cartEntry);
            var retrievedCartEntry = cartsCollection.Retrieve(cartEntry.Id);

            Assert.True((object)cartEntry == (object)retrievedCartEntry);
        }
Ejemplo n.º 5
0
        public void WhenCheckoutNonExistingCartThenExceptionIsReturnedInMessage()
        {
            var testContext = new TestContext();

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

            var response = controller.Checkout("001");

            Assert.NotNull(response);
            Assert.Equal(CartOperationStatus.Error, response.Status);
            Assert.NotNull(response.Exception);
            Assert.Null(response.Body);
        }
Ejemplo n.º 6
0
        public void RetrieveAll()
        {
            var testContext = new TestContext();

            var cartsCollection = new TestCartsCollection();
            var cartEntry1      = new CartsCollection.CartsCollectionEntry(new CartInfo(),
                                                                           testContext.CartFactory.Create());
            var cartEntry2 = new CartsCollection.CartsCollectionEntry(new CartInfo(),
                                                                      testContext.CartFactory.Create());

            cartsCollection.Add(cartEntry1);
            cartsCollection.Add(cartEntry2);
            var retrievedCartEntries = cartsCollection.Retrieve();

            Assert.Equal(2, retrievedCartEntries.Count());
        }
Ejemplo n.º 7
0
        public void WhenCreatingCartThenNewCartIsAddedToCollection()
        {
            var testContext = new TestContext();

            var inMemoryCollection = new TestCartsCollection();

            Assert.Equal(0, inMemoryCollection.Count);

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

            var response = controller.Create();

            Assert.NotNull(response);
            Assert.Equal(CartOperationStatus.Successful, response.Status);
            Assert.NotNull(response.Body);
            Assert.Equal(1, inMemoryCollection.Count);
        }
Ejemplo n.º 8
0
        public void WhenAddingAnExistingCartThenExceptionIsThrown()
        {
            var testContext = new TestContext();

            var cartsCollection = new TestCartsCollection();
            var id         = "001";
            var cartInfo1  = new TestCartInfo(id);
            var cartInfo2  = new TestCartInfo(id);
            var cartEntry1 = new CartsCollection.CartsCollectionEntry(cartInfo1,
                                                                      testContext.CartFactory.Create());
            var cartEntry2 = new CartsCollection.CartsCollectionEntry(cartInfo2,
                                                                      testContext.CartFactory.Create());

            cartsCollection.Add(cartEntry1);

            Assert.Throws <ArgumentException>(() =>
            {
                cartsCollection.Add(cartEntry2);
            });
        }
Ejemplo n.º 9
0
        public void WhenDeletingCartThenCollectionShrinks()
        {
            var testContext = new TestContext();

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

            inMemoryCollection.Add(cartEntry);
            Assert.NotEqual(0, inMemoryCollection.Count);

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

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

            Assert.NotNull(response);
            Assert.Equal(CartOperationStatus.Successful, response.Status);
            Assert.NotNull(response.Body);
            Assert.Equal(0, inMemoryCollection.Count);
        }
Ejemplo n.º 10
0
        public void WhenCreatedThenCollectionIsEmpty()
        {
            var cartsCollection = new TestCartsCollection();

            Assert.Equal(0, cartsCollection.Count);
        }