public void TestInitialize() { IoC.GetInstance = (type, s) => null; _eventAggregator = new MockEventAggregator(); _navigationService = new MockNavigationService(); _subject = new DefaultBottomBarViewModel(_navigationService, _eventAggregator) { Navigate = _navigationService.DoNavigate }; }
protected void Configure() { var mockEventAggregator = new MockEventAggregator(); var mockSubsonicService = new MockSubsonicService(); var mockNavigationService = new MockNavigationService(); var mockNotificationService = new MockToastNotificationService(); var mockDialogNotificationService = new MockDialogNotificationService(); var mockStorageService = new MockStorageService(); var mockWinRTWrappersService = new MockWinRTWrappersService(); var shellViewModel = new ShellViewModel(mockEventAggregator, mockSubsonicService, mockNavigationService, mockNotificationService, mockDialogNotificationService, mockStorageService, mockWinRTWrappersService); IoC.GetInstance = (type, s) => { object instance = null; if (type == typeof(IShellViewModel)) { instance = shellViewModel; } else if (type == typeof(ISubsonicService)) { instance = mockSubsonicService; } return(instance); }; }
public void FailedCallToProductCatalogRepository_ShowsAlert() { var alertCalled = false; var productCatalogRepository = new MockProductCatalogRepository(); var navService = new MockNavigationService(); productCatalogRepository.GetRootCategoriesAsyncDelegate = (maxAmmountOfProducts) => { throw new Exception(); }; var alertMessageService = new MockAlertMessageService(); alertMessageService.ShowAsyncDelegate = (s, s1) => { alertCalled = true; Assert.AreEqual("ErrorServiceUnreachable", s1); return(Task.FromResult(string.Empty)); }; var target = new HubPageViewModel(productCatalogRepository, navService, alertMessageService, new MockResourceLoader()); target.OnNavigatedTo(null, NavigationMode.New, null); Assert.IsTrue(alertCalled); }
public void OnNavigatedTo_Fill_RootCategories() { var repository = new MockProductCatalogRepository(); var navigationService = new MockNavigationService(); repository.GetRootCategoriesAsyncDelegate = (maxAmmountOfProducts) => { var categories = new Collection <Category>(new List <Category> { new Category(), new Category(), new Category() }); return(Task.FromResult((ICollection <Category>)categories)); }; var viewModel = new HubPageViewModel(repository, navigationService, null, null); viewModel.OnNavigatedTo(new NavigatedToEventArgs { Parameter = null, NavigationMode = NavigationMode.New }, null); Assert.IsNotNull(viewModel.RootCategories); Assert.AreEqual(((ICollection <CategoryViewModel>)viewModel.RootCategories).Count, 3); }
public void AddCheckoutData_NavigatesToProperPage() { string requestedPageName = string.Empty; var navigationService = new MockNavigationService() { NavigateDelegate = (pageName, navParam) => { Assert.IsTrue(pageName == requestedPageName); return(true); } }; var target = new CheckoutSummaryPageViewModel(navigationService, null, null, null, null, null, null, null, null, null); requestedPageName = "ShippingAddress"; target.SelectedCheckoutData = new CheckoutDataViewModel() { DataType = Constants.ShippingAddress }; target.AddCheckoutDataCommand.Execute(); requestedPageName = "BillingAddress"; target.SelectedCheckoutData = new CheckoutDataViewModel() { DataType = Constants.BillingAddress }; target.AddCheckoutDataCommand.Execute(); requestedPageName = "PaymentMethod"; target.SelectedCheckoutData = new CheckoutDataViewModel() { DataType = Constants.PaymentMethod }; target.AddCheckoutDataCommand.Execute(); }
public async Task AssignmentSavedInAssignmentManagingPageTest() { var _azureService = new MockAzureService(); var _navigationService = new MockNavigationService(); var app = new App(_azureService); var viewModel = new AssignmentManagingPageViewModel(_navigationService, null); await _azureService.SyncOfflineCacheAsync(); var assignment = (await(await _azureService.GetTableAsync <Assignment>()) .Where(s => s.Name == "Assignment1")) .FirstOrDefault(); var navigationParams = new NavigationParameters { { "model", assignment } }; viewModel.OnNavigatingTo(navigationParams); viewModel.Assignment.Name = "AssignmentChanged"; viewModel.SaveAssignmentCommand.Execute(); var assignmentAfter = (await(await _azureService.GetTableAsync <Assignment>()) .Where(s => s.Name == "AssignmentChanged")) .FirstOrDefault(); Assert.IsNotNull(assignmentAfter); }
protected void Configure() { var mockEventAggregator = new MockEventAggregator(); var mockSubsonicService = new MockSubsonicService(); var mockNavigationService = new MockNavigationService(); var mockNotificationService = new MockToastNotificationService(); var mockDialogNotificationService = new MockDialogNotificationService(); var mockStorageService = new MockStorageService(); var mockWinRTWrappersService = new MockWinRTWrappersService(); var shellViewModel = new ShellViewModel(mockEventAggregator, mockSubsonicService, mockNavigationService, mockNotificationService, mockDialogNotificationService, mockStorageService, mockWinRTWrappersService); IoC.GetInstance = (type, s) => { object instance = null; if (type == typeof(IShellViewModel)) { instance = shellViewModel; } else if (type == typeof(ISubsonicService)) { instance = mockSubsonicService; } return instance; }; }
public void Setup() { _mockSubsonicService = new MockSubsonicService(); _mockStorageService = new MockStorageService(); _mockToastNotificationService = new MockToastNotificationService(); _mockNavigationService = new MockNavigationService(); _subject = new SettingsViewModel(_mockSubsonicService, _mockToastNotificationService, _mockStorageService, _mockNavigationService); }
public SearchQuerySubmittedHandlerScenario() { _settings = new MockApplicationSettings(); _imageSearchService = new MockImageSearchService(); _navigationService = new MockNavigationService(); _statusService = new MockStatusService(); Handler = new SearchQuerySubmittedHandler(_settings, _imageSearchService, _navigationService, _statusService); }
public void NavigateToCafeDetails() { var navigationService = new MockNavigationService(); var cafe = new Cafe { Id = "1" }; var item = new CafeSummaryViewModel(cafe, navigationService); item.Navigate.Execute(null); Assert.AreEqual("CafeDetails", navigationService.Current.Location); Assert.AreEqual("1", navigationService.Current.Parameters["Id"]); }
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 InitializeDataTest() { // Arrange var mockDataService = new MockDataService(); var mockNavigationService = new MockNavigationService(); // Act var vm = new ProductsViewModel(mockDataService, mockNavigationService); // Assert Assert.True(vm.Products.Count == 3); }
public void ApproveAnotherCustomerClearsCurrentCustomerAndRedirectsToApproveCustomerView() { MockNavigationService navigationService = new MockNavigationService(); CustomersController controller = GetCustomersControllerInitialized(navigationService); controller.CurrentCustomer = new Customer(); controller.ApproveAnotherCustomer(); Assert.IsNull(controller.CurrentCustomer); Assert.IsTrue(navigationService.NavigateCalled); Assert.AreEqual(ViewNames.ApproveCustomerView, navigationService.View); }
public void NavigationTest() { // Arrange var mockDataService = new MockDataService(); var mockNavigationService = new MockNavigationService(); var vm = new ProductsViewModel(mockDataService, mockNavigationService); // Act vm.GoToDetailsPage(new Product()); // Assert Assert.True(mockNavigationService.IsNavigated); }
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 Setup() { _mockWinRTWrapperService = new MockWinRTWrappersService(); _mockNavigationService = new MockNavigationService(); _mockDialogNotificationService = new MockDialogNotificationService(); _mockResourceService = new MockResourceService(); _mockDialogService = new MockDialogService(); _subject = new ErrorDialogViewModel( _mockWinRTWrapperService, _mockNavigationService, _mockDialogNotificationService, _mockResourceService, _mockDialogService); }
public void Setup() { MockEventAggregator = new MockEventAggregator(); MockNavigationService = new MockNavigationService(); MockPlyalistManagementService = new MockPlyalistManagementService(); MockErrorDialogViewModel = new MockErrorDialogViewModel(); Subject = new TViewModel { NavigationService = MockNavigationService, EventAggregator = MockEventAggregator, PlaylistManagementService = MockPlyalistManagementService, ErrorDialogViewModel = MockErrorDialogViewModel }; TestInitializeExtensions(); }
public void TestInitialize() { IoC.GetInstance = (type, s) => null; _mockSubsonicService = new MockSubsonicService(); _mockNavigationService = new MockNavigationService(); _mockToastNotificationService = new MockToastNotificationService(); _mockDialogNotificationService = new MockDialogNotificationService(); _mockStorageService = new MockStorageService(); _mockWinRTWrappersService = new MockWinRTWrappersService(); _mockPlayerControls = new MockPlayerControls(); Subject = new ShellViewModel(_eventAggregator, _mockSubsonicService, _mockNavigationService, _mockToastNotificationService, _mockDialogNotificationService, _mockStorageService, _mockWinRTWrappersService) { PlayerControls = _mockPlayerControls }; }
public void TestInitialize() { MockSubsonicService = new MockSubsonicService(); MockNavigationService = new MockNavigationService(); MockDialogNotificationService = new MockDialogNotificationService(); MockEventAggregator = new MockEventAggregator(); MockErrorDialogViewModel = new MockErrorDialogViewModel(); Subject = new TViewModel { EventAggregator = MockEventAggregator, SubsonicService = MockSubsonicService, NavigationService = MockNavigationService, NotificationService = MockDialogNotificationService, UpdateDisplayName = () => Subject.DisplayName = string.Empty, ErrorDialogViewModel = MockErrorDialogViewModel }; TestInitializeExtensions(); }
public async Task NavigateFiresNavigateAsync() { var navService = new MockNavigationService() { Result = new MockNavigationResult { Success = true } }; var builder = navService.Navigate("ViewA"); var success = false; var ex = await Record.ExceptionAsync(async() => success = await builder.ExecuteAsync()); Assert.Null(ex); Assert.True(success); Assert.True(navService.NavigateCalled); }
public void TestInitialize() { MockDefaultBottomBar = new MockDefaultBottomBarViewModel(); MockSubsonicService = new MockSubsonicService(); MockNavigationService = new MockNavigationService(); MockDialogNotificationService = new MockDialogNotificationService(); MockEventAggregator = new MockEventAggregator(); Subject = new TViewModel { EventAggregator = MockEventAggregator, BottomBar = MockDefaultBottomBar, SubsonicService = MockSubsonicService, NavigationService = MockNavigationService, NotificationService = MockDialogNotificationService, UpdateDisplayName = () => Subject.DisplayName = "" }; TestInitializeExtensions(); }
public async Task SubmitValidOrder_NavigatesToOrderConfirmation() { bool navigateCalled = false; bool clearHistoryCalled = false; bool clearCartCalled = false; var navigationService = new MockNavigationService(); navigationService.NavigateDelegate = (s, o) => { Assert.AreEqual("OrderConfirmation", s); navigateCalled = true; return(true); }; navigationService.ClearHistoryDelegate = () => { clearHistoryCalled = true; }; var accountService = new MockAccountService() { VerifySavedCredentialsAsyncDelegate = () => Task.FromResult <UserInfo>(new UserInfo()) }; var orderService = new MockOrderService() { // the order is valid, it can be processed ProcessOrderAsyncDelegate = (o) => Task.FromResult(true) }; var resourcesService = new MockResourceLoader() { GetStringDelegate = (key) => key }; var shoppingCartRepository = new MockShoppingCartRepository(); shoppingCartRepository.ClearCartAsyncDelegate = () => { clearCartCalled = true; return(Task.Delay(0)); }; var target = new CheckoutSummaryPageViewModel(navigationService, orderService, null, null, null, shoppingCartRepository, accountService, resourcesService, null, null); await target.SubmitCommand.Execute(); Assert.IsTrue(navigateCalled); Assert.IsTrue(clearHistoryCalled); Assert.IsTrue(clearCartCalled); }
public async Task NavigateUsesUriNotString() { var navService = new MockNavigationService() { Result = new MockNavigationResult { Success = true } }; var builder = navService.Navigate("ViewA"); var success = false; var ex = await Record.ExceptionAsync(async() => success = await builder.ExecuteAsync()); Assert.Null(ex); Assert.True(success); Assert.Null(navService.NavigationName); Assert.NotNull(navService.NavigationUri); }
public void SubmitInvalidOrder_CallsErrorDialog() { bool successDialogCalled = false; bool errorDialogCalled = false; var navigationService = new MockNavigationService(); var accountService = new MockAccountService() { VerifySavedCredentialsAsyncDelegate = () => Task.FromResult <UserInfo>(new UserInfo()) }; var orderService = new MockOrderService() { // the order is invalid, it cannot be processed ProcessOrderAsyncDelegate = (o) => { var modelValidationResult = new ModelValidationResult(); modelValidationResult.ModelState.Add("someKey", new List <string>() { "the value of someKey is invalid" }); throw new ModelValidationException(modelValidationResult); } }; var resourcesService = new MockResourceLoader() { GetStringDelegate = (key) => key }; var alertService = new MockAlertMessageService() { ShowAsyncDelegate = (dialogTitle, dialogMessage) => { successDialogCalled = dialogTitle.ToLower().Contains("purchased"); errorDialogCalled = !successDialogCalled; return(Task.FromResult(successDialogCalled)); } }; var target = new CheckoutSummaryPageViewModel(navigationService, orderService, null, null, null, null, accountService, resourcesService, alertService, null); target.SubmitCommand.Execute(); Assert.IsFalse(successDialogCalled); Assert.IsTrue(errorDialogCalled); }
public async Task NavigateCatchesSpecificException() { var navService = new MockNavigationService() { Result = new MockNavigationResult { Exception = new ArgumentNullException() } }; bool catchAllFired = false; bool argumentNullFired = false; bool aritmeticExceptionFired = false; Exception caughtException = null; var builder = navService.Navigate("ViewA") .WithParameter("message", "Hello World") .Catch(e => { caughtException = e; catchAllFired = true; }) .Catch <ArithmeticException>(e => { caughtException = e; aritmeticExceptionFired = true; }) .Catch <ArgumentNullException>(e => { caughtException = e; argumentNullFired = true; }); var success = false; var ex = await Record.ExceptionAsync(async() => success = await builder.ExecuteAsync()); Assert.Null(ex); Assert.False(success); Assert.False(catchAllFired); Assert.False(aritmeticExceptionFired); Assert.True(argumentNullFired); Assert.Equal(navService.Result.Exception, caughtException); }
public void ApproveCurrentCustomerApprovesCustomerAndUpdatesDataStoreAndRedirectsToSummary() { MockNavigationService navigationService = new MockNavigationService(); List <Customer> customers = new List <Customer>(); CustomersController controller = GetCustomersControllerInitialized(navigationService, customers); Customer customerInDataStore = new Customer(1000, "Enrique", "Gil", false); customers.Add(customerInDataStore); Customer customerToApprove = new Customer(1000, "Enrique", "Gil", false); controller.CurrentCustomer = customerToApprove; controller.ApproveCurrentCustomer(); Assert.IsTrue(customerToApprove.Approved); Assert.IsTrue(customerInDataStore.Approved); Assert.IsTrue(navigationService.NavigateCalled); Assert.AreEqual(ViewNames.SummaryView, navigationService.View); }
public async Task NavigatePassesParameters() { var navService = new MockNavigationService() { Result = new MockNavigationResult { Success = true } }; var builder = navService.Navigate("ViewA") .WithParameter("message", "Hello World"); var success = false; var ex = await Record.ExceptionAsync(async() => success = await builder.ExecuteAsync()); Assert.Null(ex); Assert.True(success); Assert.Single(navService.ParametersUsed); Assert.Equal("Hello World", navService.ParametersUsed.GetValue <string>("message")); }
public async Task LoginCommand_LoginSuccess_TestAsync() { await _viewModel.NavigatedToAsync <object>(null); _viewModel.Username = "******"; _viewModel.Password = "******"; _mockLoginDataAccess.Setup(x => x.Login(It.IsAny <string>(), It.IsAny <string>())) .Returns(Task.FromResult(new Model.LoginResult { IsAuthenticated = true, User = new Model.User { Username = "******", FirstName = "test", LastName = "user", UserType = Enums.UserType.PrivilegedUser } })); _viewModel.LoginCommand.Execute(null); MockNavigationService.Verify(x => x.PushToRootAsync <PriceEstimationPage>(It.IsAny <object>())); }
public void OnNavigatedTo_ClearsNavigationHistory() { bool clearHistoryCalled = false; var navigationService = new MockNavigationService(); navigationService.ClearHistoryDelegate = () => { clearHistoryCalled = true; }; var resourcesService = new MockResourceLoader() { GetStringDelegate = (key) => key }; var target = new OrderConfirmationPageViewModel(resourcesService, navigationService); target.OnNavigatedTo(new NavigatedToEventArgs { Parameter = null, NavigationMode = NavigationMode.Forward }, null); Assert.IsTrue(clearHistoryCalled); }
public void OnNavigatedTo_Fill_Properties_No_Shopping_Cart_Items() { var navigationService = new MockNavigationService(); var shoppingCartRepository = new MockShoppingCartRepository(); shoppingCartRepository.GetShoppingCartAsyncDelegate = () => { var shoppingCartItems = new List <ShoppingCartItem>(); shoppingCartItems.Add(new ShoppingCartItem { Quantity = 1, Product = new Product { ListPrice = 200, DiscountPercentage = 50 }, Currency = "USD" }); ShoppingCart shoppingCart = new ShoppingCart(new ObservableCollection <ShoppingCartItem>(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(null, NavigationMode.New, null); Assert.IsTrue(signInUserControlOnNavigatedToCalled); Assert.AreEqual("$200.00", target.FullPrice); Assert.AreEqual("$100.00", target.TotalDiscount); Assert.AreEqual(1, target.ShoppingCartItemViewModels.Count); }
public void DecrementCountCommand_NotExecutable() { var navigationService = new MockNavigationService(); var shoppingCartRepository = new MockShoppingCartRepository(); var eventAggregator = new MockEventAggregator(); eventAggregator.GetEventDelegate = type => new MockShoppingCartUpdatedEvent(); var target = new ShoppingCartPageViewModel(shoppingCartRepository, navigationService, null, null, null, null, null, null, eventAggregator); target.SelectedItem = new ShoppingCartItemViewModel(new ShoppingCartItem() { Quantity = 2, Currency = "USD", Product = new Product() }, null); Assert.IsTrue(target.DecrementCountCommand.CanExecute()); target.SelectedItem = new ShoppingCartItemViewModel(new ShoppingCartItem() { Quantity = 1, Currency = "USD", Product = new Product() }, null); Assert.IsFalse(target.DecrementCountCommand.CanExecute()); }
public void TestInitialize() { IoC.GetInstance = (type, s) => null; _mockEventAggregator = new MockEventAggregator(); _mockSubsonicService = new MockSubsonicService(); _mockNavigationService = new MockNavigationService(); _mockToastNotificationService = new MockToastNotificationService(); _mockDialogNotificationService = new MockDialogNotificationService(); _mockStorageService = new MockStorageService(); _mockWinRTWrappersService = new MockWinRTWrappersService(); _mockErrorDialogViewModel = new MockErrorDialogViewModel(); Subject = new ShellViewModel { EventAggregator = _mockEventAggregator, SubsonicService = _mockSubsonicService, NavigationService = _mockNavigationService, NotificationService = _mockToastNotificationService, DialogNotificationService = _mockDialogNotificationService, StorageService = _mockStorageService, WinRTWrappersService = _mockWinRTWrappersService, ErrorDialogViewModel = _mockErrorDialogViewModel }; }