public void DeleteValidExpenseShouldDeleteExpense() { var options = new DbContextOptionsBuilder <DataDbContext>() .UseInMemoryDatabase(databaseName: nameof(DeleteValidExpenseShouldDeleteExpense)) .Options; using (var context = new DataDbContext(options)) { var expenseService = new ExpensesService(context); var expected = new ExpensesPostModel() { Description = "Test description", Sum = 20, Location = "Cluj", Date = DateTime.ParseExact("05/30/2019", "MM/dd/yyyy", CultureInfo.InvariantCulture), Currency = "RON", Type = "Food", Comments = null }; // add the expense to db var actual = expenseService.AddExpense(expected); // delete expense and put return expense in obj var afterDelete = expenseService.DeleteExpense(actual.Id); // search for the added expense to see if exists in db var result = context.Expensess.Find(actual.Id); Assert.IsNotNull(afterDelete); Assert.IsNull(result); } }
public void DeleteValidExpenseWithCommentsShouldDeleteExpenseAndComments() { var options = new DbContextOptionsBuilder <DataDbContext>() .UseInMemoryDatabase(databaseName: nameof(DeleteValidExpenseWithCommentsShouldDeleteExpenseAndComments)) .Options; using (var context = new DataDbContext(options)) { var expenseService = new ExpensesService(context); var expected = new ExpensesPostModel() { Description = "Test description", 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 } } }; // add the expense to db var actual = expenseService.AddExpense(expected); // delete expense and put return expense in obj var afterDelete = expenseService.DeleteExpense(actual.Id); // find the number of comments that exists in db int numberOfCommentsInDb = context.Comments.CountAsync().Result; // search for the added expense to see if exists in db var resultExpense = context.Expensess.Find(actual.Id); Assert.IsNotNull(afterDelete); Assert.IsNull(resultExpense); Assert.AreEqual(0, numberOfCommentsInDb); } }