/// <summary> /// Async wrapper for database init followed by proper page transition /// </summary> private async void AsyncInit() { // Initialize database await Task.Run(() => DataService.Initialize()); // If there are accounts, start in the accounts view using (var dataService = new DataService()) { if (dataService.AnyExistingAccounts()) _modernNavigationService.NavigateTo(nameof(ViewModelLocator.Accounts)); else // No existing accounts, show welcome screen _modernNavigationService.NavigateTo(nameof(ViewModelLocator.Welcome)); } //prevent the user from navigating to this point or further back _modernNavigationService.ClearNavigationHistory(); }
public void TestAnyExistingAccount() { // Mock setup for DataService var mockSet = new Mock<DbSet<Account>>(); var mockContext = new Mock<SoCashDbContext>(MockBehavior.Loose); mockContext.Setup(m => m.Accounts).Returns(mockSet.Object); mockContext.Setup(m => m.Set<Account>()).Returns(mockSet.Object); // Start with empty account list var data = new List<Account>(); mockSet.As<IQueryable<Account>>().Setup(m => m.Provider).Returns(data.AsQueryable().Provider); mockSet.As<IQueryable<Account>>().Setup(m => m.Expression).Returns(data.AsQueryable().Expression); mockSet.As<IQueryable<Account>>().Setup(m => m.ElementType).Returns(data.AsQueryable().ElementType); mockSet.As<IQueryable<Account>>().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator()); // No accounts in DB using (var service = new DataService(mockContext.Object)) Assert.IsFalse(service.AnyExistingAccounts()); // Add some records data.Add(new Account {AccountName = "Acct1", AccountType = AccountType.Checking.ToString(),Currency = "USD"}); data.Add(new Account {AccountName = "Acct2", AccountType = AccountType.Savings.ToString(), Currency = "USD"}); data.Add(new Account {AccountName = "Acct3", AccountType = AccountType.Creditcard.ToString(), Currency = "USD"}); // There are now accounts in the db using (var service = new DataService(mockContext.Object)) Assert.IsTrue(service.AnyExistingAccounts()); // Verify that both transactions ended properly mockContext.Verify(m => m.SaveChanges(), Times.Exactly(2)); }