public async Task CartItemUpdatedEventRaised_WhenItemRemoved() { var shoppingCartItemUpdatedRaised = false; var shoppingCartService = new MockShoppingCartService() { RemoveShoppingCartItemDelegate = (s, s1) => { Assert.AreEqual("TestShoppingCartItemId", s1); return Task.FromResult(string.Empty); } }; var shoppingCartItemUpdatedEvent = new ShoppingCartItemUpdatedEvent(); shoppingCartItemUpdatedEvent.Subscribe((a) => shoppingCartItemUpdatedRaised = true); var eventAggregator = new MockEventAggregator() { GetEventDelegate = (a) => shoppingCartItemUpdatedEvent }; var target = new ShoppingCartRepository(shoppingCartService, new MockAccountService(), eventAggregator, new MockProductCatalogRepository(), new MockSuspensionManagerState()); await target.RemoveShoppingCartItemAsync("TestShoppingCartItemId"); Assert.IsTrue(shoppingCartItemUpdatedRaised); }
public async Task Remove_InvalidatesCachedCart() { var shoppingCartService = new MockShoppingCartService { RemoveShoppingCartItemDelegate = (s, s1) => Task.FromResult(string.Empty), GetShoppingCartAsyncDelegate = s => Task.FromResult(new ShoppingCart(new Collection<ShoppingCartItem>()) {Id = "first"}) }; var eventAggregator = new MockEventAggregator { GetEventDelegate = type => new ShoppingCartItemUpdatedEvent() }; var target = new ShoppingCartRepository(shoppingCartService, null, eventAggregator, null, new MockSuspensionManagerState()); var firstCartReturned = await target.GetShoppingCartAsync(); await target.RemoveShoppingCartItemAsync("TestShoppingCartItemId"); shoppingCartService.GetShoppingCartAsyncDelegate = s => Task.FromResult(new ShoppingCart(new Collection<ShoppingCartItem>()) { Id = "second" }); var secondCartReturned = await target.GetShoppingCartAsync(); Assert.IsNotNull(firstCartReturned); Assert.IsNotNull(secondCartReturned); Assert.AreNotSame(firstCartReturned, secondCartReturned); }