public async Task GetIdByRecipeIdAsync_WithNonExistentRecipeId_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.GetIdByRecipeIdAsync(nonExistentId); }); }
public async Task GetIdByRecipeIdAsync_WithExistentRecipeId_ShouldReturnCorrectResult() { var errorMessagePrefix = "ShoppingListService GetIdByRecipeIdAsync() 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 recipeId = context.Recipes.First().Id; // Act var actualResult = await shoppingListService.GetIdByRecipeIdAsync(recipeId); var expectedResult = shoppingListRepository.All().First().Id; // Assert Assert.True(expectedResult == actualResult, errorMessagePrefix + " " + "Id is not returned properly."); }