public async Task Add_InvalidatesCachedCart() { var shoppingCartService = new MockShoppingCartService { AddProductToShoppingCartAsyncDelegate = (s, s1) => Task.FromResult(new ShoppingCartItem()), 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, new MockSessionStateService()); var firstCartReturned = await target.GetShoppingCartAsync(); await target.AddProductToShoppingCartAsync("TestProductId"); 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); }
public async void CartItemUpdatedEventRaised_WhenProductAdded() { var shoppingCartItemUpdatedRaised = false; var shoppingCartService = new MockShoppingCartService(); shoppingCartService.AddProductToShoppingCartAsyncDelegate = (s, s1) => Task.FromResult(string.Empty); var shoppingCartItemUpdatedEvent = new ShoppingCartItemUpdatedEvent(); shoppingCartItemUpdatedEvent.Subscribe((_) => { shoppingCartItemUpdatedRaised = true; }); var eventAggregator = new MockEventAggregator(); eventAggregator.GetEventDelegate = type => shoppingCartItemUpdatedEvent; var target = new ShoppingCartRepository(shoppingCartService, new MockAccountService(), eventAggregator, new MockSessionStateService()); await target.AddProductToShoppingCartAsync("TestProductId"); Assert.IsTrue(shoppingCartItemUpdatedRaised); }
public async void CartItemUpdatedEventRaised_WhenProductAdded() { var shoppingCartItemUpdatedRaised = false; var shoppingCartService = new MockShoppingCartService(); shoppingCartService.AddProductToShoppingCartAsyncDelegate = (s, s1) => Task.FromResult(string.Empty); var shoppingCartItemUpdatedEvent = new ShoppingCartItemUpdatedEvent(); shoppingCartItemUpdatedEvent.Subscribe((_) => { shoppingCartItemUpdatedRaised = true; }); var eventAggregator = new MockEventAggregator(); eventAggregator.GetEventDelegate = type => shoppingCartItemUpdatedEvent; var target = new ShoppingCartRepository(shoppingCartService, new MockAccountService(), eventAggregator, new MockSessionStateService()); await target.AddProductToShoppingCartAsync("TestProductId"); Assert.IsTrue(shoppingCartItemUpdatedRaised); }
public async Task Add_InvalidatesCachedCart() { var shoppingCartService = new MockShoppingCartService { AddProductToShoppingCartAsyncDelegate = (s, s1) => Task.FromResult(new ShoppingCartItem()), 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, new MockSessionStateService()); var firstCartReturned = await target.GetShoppingCartAsync(); await target.AddProductToShoppingCartAsync("TestProductId"); 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); }