public async Task EditAsync_WithCorrectData_ShouldSuccessfullyEdit() { var errorMessagePrefix = "ShoppingListService EditAsync() 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 shoppingListServiceModel = shoppingListRepository .All() .First() .To <ShoppingListServiceModel>(); var shoppingListId = shoppingListServiceModel.Id; var newValue = "New Ingredients"; shoppingListServiceModel.Ingredients = newValue; // Act await shoppingListService.EditAsync(shoppingListId, shoppingListServiceModel); var actualResult = shoppingListRepository.All().First(); var expectedValue = newValue; // Assert Assert.True(actualResult.Ingredients == expectedValue, errorMessagePrefix + " " + "Ingredients are not returned properly."); }
public async Task EditAsync_WithNonExistentId_ShouldThrowArgumentNullException() { // Arrange MapperInitializer.InitializeMapper(); var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var shoppingListRepository = new EfDeletableEntityRepository <ShoppingList>(context); var shoppingListService = new ShoppingListService(shoppingListRepository); var shoppingListServiceModel = new ShoppingListServiceModel(); var nonExistentId = Guid.NewGuid().ToString(); // Act // Assert await Assert.ThrowsAsync <ArgumentNullException>(async() => { await shoppingListService.EditAsync(nonExistentId, shoppingListServiceModel); }); }