public async Task GetIdsByNamesAsync_WithCorrectData_ShouldReturnCorrectResult() { var errorMessagePrefix = "AllergenService GetIdsByNamesAsync() 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 existentNames = new string[] { "Milk", "Eggs" }; // Act var actualResult = (await allergenService.GetIdsByNamesAsync(existentNames)).ToList(); var expectedResult = await allergenRepository .All() .Where(x => existentNames.Contains(x.Name)) .Select(x => x.Id) .ToListAsync(); // Assert for (int i = 0; i < actualResult.Count; i++) { Assert.True(actualResult[i] == expectedResult[i], errorMessagePrefix + " " + "Id is not returned properly."); } }
public async Task GetIdsByNamesAsync_WithNonExistentName_ShouldThrowArgumentNullException() { // Arrange MapperInitializer.InitializeMapper(); var context = ApplicationDbContextInMemoryFactory.InitializeContext(); await this.SeedDataAsync(context); var allergenRepository = new EfRepository <Allergen>(context); var allergenService = new AllergenService(allergenRepository); var existentAndNonExistentNames = new string[] { "Milk", "NonExistent" }; // Act // Assert await Assert.ThrowsAsync <ArgumentNullException>(async() => { await allergenService.GetIdsByNamesAsync(existentAndNonExistentNames); }); }