public async Task SetAllergenToRecipeAsync_WithCorrectData_ShouldSuccessfullySet() { var errorMessagePrefix = "AllergenService SetAllergenToRecipeAsync() method does not work properly."; // Arrange MapperInitializer.InitializeMapper(); var context = ApplicationDbContextInMemoryFactory.InitializeContext(); await this.SeedDataAsync(context); var allergenRepository = new EfRepository <Allergen>(context); var allergenService = new AllergenService(allergenRepository); var recipe = new Recipe(); // Act await allergenService.SetAllergenToRecipeAsync("Milk", recipe); var actualResult = recipe.Allergens.First().Allergen; var expectedResult = await allergenRepository .All() .SingleOrDefaultAsync(x => x.Name == "Milk"); // Assert Assert.True(actualResult.Id == expectedResult.Id, errorMessagePrefix + " " + "Id is not returned properly."); Assert.True(actualResult.Name == expectedResult.Name, errorMessagePrefix + " " + "Name is not returned properly."); }
public async Task SetAllergenToRecipeAsync_WithNonExistentAllergen_ShouldThrowArgumentNullException() { // Arrange MapperInitializer.InitializeMapper(); var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var allergenRepository = new EfRepository <Allergen>(context); var allergenService = new AllergenService(allergenRepository); var recipe = new Recipe(); // Act // Assert await Assert.ThrowsAsync <ArgumentNullException>(async() => { await allergenService.SetAllergenToRecipeAsync("NonExistent", recipe); }); }