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(string.Empty) }; var target = new ShoppingCartRepository(shoppingCartService, accountService, eventAggregator, new MockProductCatalogRepository(), new MockSuspensionManagerState()); accountService.RaiseUserChanged(new UserInfo { UserName = "******" }, null); Assert.IsTrue(shoppingCartUpdatedRaised); }
public void ShoppingCartMerged_WhenAnonymousUserLogsIn() { bool mergeShoppingCartsCalled = 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(string.Empty); } }; var accountService = new MockAccountService(); var shoppingCartUpdatedEvent = new MockShoppingCartUpdatedEvent { PublishDelegate = () => { } }; var eventAggregator = new MockEventAggregator() { GetEventDelegate = (a) => shoppingCartUpdatedEvent }; var suspensionManagerState = new MockSuspensionManagerState(); suspensionManagerState.SessionState[ShoppingCartRepository.ShoppingCartIdKey] = "AnonymousId"; var target = new ShoppingCartRepository(shoppingCartService, accountService, eventAggregator, null, suspensionManagerState); accountService.RaiseUserChanged(new UserInfo { UserName = "******" }, null); Assert.IsTrue(mergeShoppingCartsCalled); }