public void CheckExpensesOnPaginatedListShouldReturnAllExpenseOnAPage() { var options = new DbContextOptionsBuilder <DataDbContext>() .UseInMemoryDatabase(databaseName: nameof(CheckExpensesOnPaginatedListShouldReturnAllExpenseOnAPage)) .Options; using (var context = new DataDbContext(options)) { // declare service var expenseService = new ExpensesService(context); // add 5 expenses, for 2 pages with 3 expenses on a PaginatedList expenseService.AddExpense(new ExpensesPostModel() { Description = "Test description 1", Sum = 20, Location = "Cluj", Date = DateTime.ParseExact("05/30/2019", "MM/dd/yyyy", CultureInfo.InvariantCulture), Currency = "RON", Type = "Food", Comments = new List <Comment>() { new Comment() { Text = "A test comment", Important = false } } }); expenseService.AddExpense(new ExpensesPostModel() { Description = "Test description 2", Sum = 20, Location = "Brasov", Date = DateTime.ParseExact("05/31/2019", "MM/dd/yyyy", CultureInfo.InvariantCulture), Currency = "Euro", Type = "Food", Comments = new List <Comment>() { new Comment() { Text = "A test comment 2", Important = false } } }); expenseService.AddExpense(new ExpensesPostModel() { Description = "Test description 2", Sum = 20, Location = "Brasov", Date = DateTime.ParseExact("05/31/2019", "MM/dd/yyyy", CultureInfo.InvariantCulture), Currency = "Euro", Type = "Food", Comments = new List <Comment>() { new Comment() { Text = "A test comment 2", Important = false } } }); expenseService.AddExpense(new ExpensesPostModel() { Description = "Test description 2", Sum = 20, Location = "Brasov", Date = DateTime.ParseExact("05/31/2019", "MM/dd/yyyy", CultureInfo.InvariantCulture), Currency = "Euro", Type = "Food", Comments = new List <Comment>() { new Comment() { Text = "A test comment 2", Important = false } } }); expenseService.AddExpense(new ExpensesPostModel() { Description = "Test description 2", Sum = 20, Location = "Brasov", Date = DateTime.ParseExact("05/31/2019", "MM/dd/yyyy", CultureInfo.InvariantCulture), Currency = "Euro", Type = "Food", Comments = new List <Comment>() { new Comment() { Text = "A test comment 2", Important = false } } }); // set the page number int Page = 1; PaginatedList <ExpensesGetModel> actual = expenseService.GetAllExpenses(Page, DateTime.ParseExact("04/30/2019", "MM/dd/yyyy", CultureInfo.InvariantCulture), DateTime.ParseExact("06/30/2019", "MM/dd/yyyy", CultureInfo.InvariantCulture), TaskWork.Models.Type.Food); // check if something is returned and number of expenses on the first page Assert.IsNotNull(actual); Assert.AreEqual(3, actual.Entries.Count); // set the page number Page = 2; PaginatedList <ExpensesGetModel> actual2 = expenseService.GetAllExpenses(Page, DateTime.ParseExact("04/30/2019", "MM/dd/yyyy", CultureInfo.InvariantCulture), DateTime.ParseExact("06/30/2019", "MM/dd/yyyy", CultureInfo.InvariantCulture), TaskWork.Models.Type.Food); // check if something is returned and number of expenses on on the second page Assert.IsNotNull(actual2); Assert.AreEqual(2, actual2.Entries.Count); } }
public IActionResult GetAllExpenses() { var result = _expensesService.GetAllExpenses(); return(Ok(result)); }
public void GetAllExpensesShouldNotBeNull() { var expenses = _service.GetAllExpenses(); Assert.IsNotNull(expenses); }