public void CartsCollectionEntryUsesTheIdInTheInfoHeader() { var testContext = new TestContext(); var cartInfo = new CartInfo(); var cartEntry = new CartsCollection.CartsCollectionEntry(cartInfo, testContext.CartFactory.Create()); Assert.Equal(cartEntry.Id, cartInfo.Id); }
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); }
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); }
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()); }
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); }); }
private void ApplyPipeline(CartsCollection.CartsCollectionEntry cartEntry) { Task.Run(() => { decimal oldTotal = cartEntry.Cart.Total; cartEntry.Cart = this.promotionPipeline.Apply(cartEntry.Cart); decimal newTotal = cartEntry.Cart.Total; this.logger?.LogInformation($"Cart {cartEntry.Id} updated through pipeline: {oldTotal} => {newTotal}"); var faultTolerantPipeline = this.promotionPipeline as FaultTolerantPromotionPipeline; if (faultTolerantPipeline != null && faultTolerantPipeline.LastApplyExceptions.Any()) { foreach (var errorReport in faultTolerantPipeline.LastApplyExceptions) { this.logger?.LogError($"Cart {cartEntry.Id} updated with errors: rule '{errorReport.Item1}' faulted with '{errorReport.Item2.Message}'"); } } }); }
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); }
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); }
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); }
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); }
public CartOperationInfo <CartInfo> Create() { var cartInfo = new CartInfo(); var cartEntry = new CartsCollection.CartsCollectionEntry(cartInfo, this.cartFactory.Create()); try { this.dataSource.Add(cartEntry); } catch (Exception e) { this.logger?.LogError($"Could not create new cart: {cartInfo.Id}"); return(new CartOperationInfo <CartInfo>(CartOperationType.Create, CartOperationStatus.Error, e)); } this.logger?.LogInformation($"Created new cart: {cartInfo.Id}"); return(new CartOperationInfo <CartInfo>(CartOperationType.Create, CartOperationStatus.Successful) { Body = cartInfo }); }
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); }
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); }
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); }