public async Task CreateAllAsync_WithDummyData_ShouldSuccessfullyCreate() { var errorMessagePrefix = "AllergenService CreateAllAsync() method does not work properly."; // Arrange MapperInitializer.InitializeMapper(); var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var allergenRepository = new EfRepository <Allergen>(context); var allergenService = new AllergenService(allergenRepository); var allergenNames = new string[] { "Milk", "Eggs" }; // Act await allergenService.CreateAllAsync(allergenNames); var actualResult = await allergenRepository .All() .Select(x => x.Name) .ToListAsync(); var expectedResult = allergenNames; // Assert for (int i = 0; i < actualResult.Count; i++) { Assert.True(expectedResult[i] == actualResult[i], errorMessagePrefix + " " + "Expected name and actual name do not match."); } }
public async Task CreateAllAsync_WithZeroData_ShouldReturnCorrectResult() { var errorMessagePrefix = "AllergenService CreateAllAsync() method does not work properly."; // Arrange MapperInitializer.InitializeMapper(); var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var allergenRepository = new EfRepository <Allergen>(context); var allergenService = new AllergenService(allergenRepository); var allergenNames = new string[] { }; // Act var result = await allergenService.CreateAllAsync(allergenNames); // Assert Assert.False(result, errorMessagePrefix + " " + "Returns true."); }