public OnNavigatedTo ( NavigatedToEventArgs e, object>.Dictionary |
||
e | NavigatedToEventArgs | |
viewModelState | object>.Dictionary | |
return | void |
public void OnNavigatedTo_Fill_Properties_With_Shopping_Cart_Items() { var navigationService = new MockNavigationService(); var shoppingCartRepository = new MockShoppingCartRepository(); shoppingCartRepository.GetShoppingCartAsyncDelegate = () => { ShoppingCart shoppingCart = null; var shoppingCartItems = new ObservableCollection<ShoppingCartItem> { new ShoppingCartItem() {Product = new Product { ListPrice = 100, DiscountPercentage = 50, ProductNumber = "p1", ImageUri = new Uri("http://image")}, Currency = "USD", Quantity = 1}, new ShoppingCartItem() {Product = new Product { ListPrice = 100, DiscountPercentage = 50, ProductNumber = "p2", ImageUri = new Uri("http://image")}, Currency = "USD", Quantity = 1} }; shoppingCart = new ShoppingCart(shoppingCartItems) { Currency = "USD"}; return Task.FromResult(shoppingCart); }; bool signInUserControlOnNavigatedToCalled = false; var signInUserControlViewModel = new MockSignInUserControlViewModel() { OnNavigatedToDelegate = (a, b, c) => signInUserControlOnNavigatedToCalled = true }; var eventAggregator = new MockEventAggregator(); eventAggregator.GetEventDelegate = type => new MockShoppingCartUpdatedEvent(); var target = new ShoppingCartPageViewModel(shoppingCartRepository, navigationService, new MockAccountService(), signInUserControlViewModel, null, null, null, null, eventAggregator); target.OnNavigatedTo(new NavigatedToEventArgs { Parameter = null, NavigationMode = NavigationMode.New }, null); Assert.IsTrue(signInUserControlOnNavigatedToCalled); Assert.AreEqual("$200.00", target.FullPrice); Assert.AreEqual("$100.00", target.TotalDiscount); Assert.AreEqual(2, target.ShoppingCartItemViewModels.Count); }
public void ShoppingCartUpdated_WhenShoppingCartChanged() { var navigationService = new MockNavigationService(); var accountService = new MockAccountService(); var shoppingCartRepository = new MockShoppingCartRepository(); shoppingCartRepository.GetShoppingCartAsyncDelegate = () => { ShoppingCart shoppingCart = new ShoppingCart(new ObservableCollection<ShoppingCartItem>()) { Currency = "USD"}; return Task.FromResult(shoppingCart); }; bool signInUserControlOnNavigatedToCalled = false; var signInUserControlViewModel = new MockSignInUserControlViewModel() { OnNavigatedToDelegate = (a, b, c) => signInUserControlOnNavigatedToCalled = true }; var eventAggregator = new MockEventAggregator(); var shoppingCartUpdatedEvent = new ShoppingCartUpdatedEvent(); eventAggregator.GetEventDelegate = type => shoppingCartUpdatedEvent; var target = new ShoppingCartPageViewModel(shoppingCartRepository, navigationService, accountService, signInUserControlViewModel, null, null, null, null, eventAggregator); target.OnNavigatedTo(new NavigatedToEventArgs { Parameter = null, NavigationMode = NavigationMode.New }, null); Assert.AreEqual("$0.00", target.FullPrice); shoppingCartRepository.GetShoppingCartAsyncDelegate = () => { var shoppingCartItems = new ObservableCollection<ShoppingCartItem> { new ShoppingCartItem() { Product = new Product { ListPrice = 100, ProductNumber = "p1", ImageUri = new Uri("http://image")}, Currency = "USD", Quantity = 2}, }; ShoppingCart shoppingCart = new ShoppingCart(new ObservableCollection<ShoppingCartItem>(shoppingCartItems)) { Currency = "USD" }; return Task.FromResult(shoppingCart); }; shoppingCartUpdatedEvent.Publish(null); Assert.IsTrue(signInUserControlOnNavigatedToCalled); Assert.AreEqual("$200.00", target.FullPrice); }
public void UpdateShoppingCart_ClearsFields_WhenShoppingCartEmpty() { var shoppingCartRepository = new MockShoppingCartRepository(); shoppingCartRepository.GetShoppingCartAsyncDelegate = () => Task.FromResult<ShoppingCart>(null); var eventAggregator = new MockEventAggregator(); bool signInUserControlOnNavigatedToCalled = false; var signInUserControlViewModel = new MockSignInUserControlViewModel() { OnNavigatedToDelegate = (a, b, c) => Task.Delay(0) }; eventAggregator.GetEventDelegate = type => new MockShoppingCartUpdatedEvent(); var target = new ShoppingCartPageViewModel(shoppingCartRepository, new MockNavigationService(), new MockAccountService(), signInUserControlViewModel, null, null, null, null, eventAggregator); target.OnNavigatedTo(new NavigatedToEventArgs { Parameter = null, NavigationMode = NavigationMode.New }, null); Assert.AreEqual(string.Empty, target.TotalPrice); Assert.AreEqual(string.Empty, target.TotalDiscount); Assert.AreEqual(string.Empty, target.FullPrice); }