public async Task DeleteByIdAsync_WithNonExistentId_ShouldThrowArgumentNullException() { // Arrange MapperInitializer.InitializeMapper(); var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var shoppingListRepository = new EfDeletableEntityRepository <ShoppingList>(context); var shoppingListService = new ShoppingListService(shoppingListRepository); var nonExistentId = Guid.NewGuid().ToString(); // Act // Assert await Assert.ThrowsAsync <ArgumentNullException>(async() => { await shoppingListService.DeleteByIdAsync(nonExistentId); }); }
public async Task DeleteByIdAsync_WithExistentId_ShouldReturnCorrectResult() { var errorMessagePrefix = "ShoppingListService DeleteByIdAsync() method does not work properly."; // Arrange MapperInitializer.InitializeMapper(); var context = ApplicationDbContextInMemoryFactory.InitializeContext(); await this.SeedDataAsync(context); var shoppingListRepository = new EfDeletableEntityRepository <ShoppingList>(context); var shoppingListService = new ShoppingListService(shoppingListRepository); var existentId = shoppingListRepository.All().First().Id; // Act var result = await shoppingListService.DeleteByIdAsync(existentId); // Assert Assert.True(result, errorMessagePrefix + " " + "Returns false."); }
public async Task DeleteByIdAsync_WithExistentId_ShouldSuccessfullyDelete() { var errorMessagePrefix = "ShoppingListService DeleteByIdAsync() method does not work properly."; // Arrange MapperInitializer.InitializeMapper(); var context = ApplicationDbContextInMemoryFactory.InitializeContext(); await this.SeedDataAsync(context); var shoppingListRepository = new EfDeletableEntityRepository <ShoppingList>(context); var shoppingListService = new ShoppingListService(shoppingListRepository); var existentId = shoppingListRepository.All().First().Id; // Act var shoppingListsCount = shoppingListRepository.All().Count(); await shoppingListService.DeleteByIdAsync(existentId); var actualResult = shoppingListRepository.All().Count(); var expectedResult = shoppingListsCount - 1; // Assert Assert.True(actualResult == expectedResult, errorMessagePrefix + " " + "ShoppingLists count is not reduced."); }