public async Task GetIdByTypeAsync_WithExistentType_ShouldReturnCorrectResult() { var errorMessagePrefix = "LifestyleService GetIdByTypeAsync() method does not work properly."; // Arrange MapperInitializer.InitializeMapper(); var context = ApplicationDbContextInMemoryFactory.InitializeContext(); await this.SeedDataAsync(context); var lifestyleRepository = new EfRepository <Lifestyle>(context); var lifestyleService = new LifestyleService(lifestyleRepository); var existentType = "Vegetarian"; // Act var actualResult = await lifestyleService.GetIdByTypeAsync(existentType); var expectedResult = (await lifestyleRepository .All() .SingleOrDefaultAsync(x => x.Type == existentType)) .Id; // Assert Assert.True(actualResult == expectedResult, errorMessagePrefix + " " + "Id is not returned properly."); }
public async Task GetIdByTypeAsync_WithNonExistentType_ShouldThrowArgumentNullException() { // Arrange MapperInitializer.InitializeMapper(); var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var lifestyleRepository = new EfRepository <Lifestyle>(context); var lifestyleService = new LifestyleService(lifestyleRepository); var nonExistentType = "NonExistent"; // Act // Assert await Assert.ThrowsAsync <ArgumentNullException>(async() => { await lifestyleService.GetIdByTypeAsync(nonExistentType); }); }