public void ReturnsBudgetsOnlyForTheUser() { // Act. List <BudgetSummary> actualList; using (CheckbookContext context = new CheckbookContext(this.dbContextOptions)) { BudgetsRepository repository = new BudgetsRepository(context); actualList = repository.GetTotals(this.userId).ToList(); } // Assert. using (CheckbookContext context = new CheckbookContext(this.dbContextOptions)) { int numberOfBudgetUsers = context.Budgets .GroupBy(a => a.UserId) .Count(); Assert.AreNotEqual(numberOfBudgetUsers, 0, "For the test to work there must be more than one user with budgets."); Assert.AreNotEqual(numberOfBudgetUsers, 1, "For the test to work there must be more than one user with budgets."); } foreach (BudgetSummary actual in actualList) { Assert.AreEqual(this.userId, actual.UserId, "The user ID for each budget should match the input user ID."); } }
public void ReturnsEmptyListWhenNoRecordsFound() { // Arrange. this.userId = 123; // Act. List <BudgetSummary> actualList; using (CheckbookContext context = new CheckbookContext(this.dbContextOptions)) { BudgetsRepository repository = new BudgetsRepository(context); actualList = repository.GetTotals(this.userId).ToList(); } // Assert. Assert.AreEqual(0, actualList.Count(), "An empty list should be returned."); }
public void ReturnsBudgetTotalsFromContext() { // Act. List <BudgetSummary> actualList; using (CheckbookContext context = new CheckbookContext(this.dbContextOptions)) { BudgetsRepository repository = new BudgetsRepository(context); actualList = repository.GetTotals(this.userId).ToList(); } // Assert. Assert.AreEqual(this.entities.Count(), actualList.Count(), "The entity count should match."); BudgetSummary expected = new BudgetSummary(this.entities.ElementAt(0)); BudgetSummary actual = actualList.ElementAt(0); string index = "first"; Assert.AreNotEqual(0, actual.Balance, "The current total should not be zero."); Assert.AreEqual(expected.Balance, actual.Balance, $"The current total for the {index} entity should match."); }