public void CartUpdatedEventRaised_WhenUserChanged() { var shoppingCartUpdatedRaised = false; var accountService = new MockAccountService(); var shoppingCartUpdatedEvent = new MockShoppingCartUpdatedEvent() { PublishDelegate = () => shoppingCartUpdatedRaised = true }; var eventAggregator = new MockEventAggregator() { GetEventDelegate = (a) => shoppingCartUpdatedEvent }; var shoppingCartService = new MockShoppingCartService() { MergeShoppingCartsAsyncDelegate = (s, s1) => Task.FromResult(false) }; var target = new ShoppingCartRepository(shoppingCartService, accountService, eventAggregator, new MockSessionStateService()); accountService.RaiseUserChanged(new UserInfo { UserName = "******" }, null); Assert.IsTrue(shoppingCartUpdatedRaised); }
public async Task CachedAddressesAndPaymentMethodsExpire_WhenUserChanged() { var accountService = new MockAccountService(); var target = new CheckoutDataRepository(SetupAddressService(), SetupPaymentMethodService(), accountService); var paymentMethods = await target.GetAllPaymentMethodsAsync(); Assert.AreSame(await target.GetAllPaymentMethodsAsync(), paymentMethods, "Cached data should be same."); accountService.RaiseUserChanged(null, null); Assert.AreNotSame(await target.GetAllPaymentMethodsAsync(), paymentMethods); }
public void ShoppingCartMerged_WhenAnonymousUserLogsIn() { bool mergeShoppingCartsCalled = false; bool alertMessageServiceCalled = false; var anonymousCartItems = new List<ShoppingCartItem> { new ShoppingCartItem {Quantity = 1, Product = new Product {ProductNumber = "123"}} }; var testUserCartItems = new List<ShoppingCartItem> { new ShoppingCartItem {Quantity = 2, Product = new Product {ProductNumber = "123"}} }; var shoppingCartService = new MockShoppingCartService() { GetShoppingCartAsyncDelegate = s => { switch (s) { case "AnonymousId": return Task.FromResult(new ShoppingCart(anonymousCartItems)); default: return Task.FromResult(new ShoppingCart(testUserCartItems)); } }, MergeShoppingCartsAsyncDelegate = (s, s1) => { mergeShoppingCartsCalled = true; Assert.AreEqual("AnonymousId", s); Assert.AreEqual("TestUserName", s1); return Task.FromResult(true); } }; var accountService = new MockAccountService(); var shoppingCartUpdatedEvent = new MockShoppingCartUpdatedEvent { PublishDelegate = () => { } }; var eventAggregator = new MockEventAggregator() { GetEventDelegate = (a) => shoppingCartUpdatedEvent }; var sessionStateService = new MockSessionStateService(); sessionStateService.SessionState[ShoppingCartRepository.ShoppingCartIdKey] = "AnonymousId"; var target = new ShoppingCartRepository(shoppingCartService, accountService, eventAggregator, sessionStateService); accountService.RaiseUserChanged(new UserInfo { UserName = "******" }, null); Assert.IsTrue(mergeShoppingCartsCalled); }