public async Task GetByIdAsync_WithExistentId_ShouldReturnCorrectResult() { var errorMessagePrefix = "LifestyleService GetByIdAsync() 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 existentId = lifestyleRepository.All().First().Id; // Act var actualResult = await lifestyleService.GetByIdAsync(existentId); var expectedResult = (await lifestyleRepository .All() .SingleOrDefaultAsync(x => x.Id == existentId)) .To <LifestyleServiceModel>(); // Assert Assert.True(actualResult.Id == expectedResult.Id, errorMessagePrefix + " " + "Id is not returned properly."); Assert.True(actualResult.Type == expectedResult.Type, errorMessagePrefix + " " + "Type is not returned properly."); }
public async Task GetByIdAsync_WithNonExistentId_ShouldThrowArgumentNullException() { // Arrange MapperInitializer.InitializeMapper(); var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var lifestyleRepository = new EfRepository <Lifestyle>(context); var lifestyleService = new LifestyleService(lifestyleRepository); var nonExistentId = 10000; // Act // Assert await Assert.ThrowsAsync <ArgumentNullException>(async() => { await lifestyleService.GetByIdAsync(nonExistentId); }); }