public void GetPie_returns_expected_pie(string inputFlavour, string expectedFlavour) { PieService pieService = new PieService(); var actualResult = pieService.GetPie(inputFlavour).GetAwaiter().GetResult(); Pie returnedPie = JsonSerializer.Deserialize <Pie>(actualResult); Assert.AreEqual(expectedFlavour, returnedPie.Flavour); }
public async Task GetPiesByCategoryAsync_WhenCalledWithInvalidCategoryIgnoringCase_ReturnsNull(string category) { // Arrange var sut = new PieService(dbContext); // Act var result = await sut.GetPiesByCategoryAsync(category); // Assert Assert.Empty(result); }
public async Task GetPieAsync_WhenCalledWithInvalidId_ReturnsNull() { // Arrange int pieId = 12; var sut = new PieService(dbContext); // Act var result = await sut.GetPieAsync(pieId); // Assert Assert.Null(result); }
public async Task GetPiesByCategoryAsync_WhenCalledWithValidCategoryIgnoringCase_ReturnsAllPiesOfGivenCategoryWithCategory(string category) { // Arrange var sut = new PieService(dbContext); // Act var result = await sut.GetPiesByCategoryAsync(category); // Assert Assert.Equal(pies.Count(p => p.Category.Name.Equals(category, StringComparison.InvariantCultureIgnoreCase)), result.Count()); Assert.NotNull(result.First().Category); Assert.NotNull(result.Last().Category); }
public async Task GetPieAsync_WhenCalledWithValidId_ReturnsPieOfGivenIdWithCategory(int pieId) { // Arrange var sut = new PieService(dbContext); // Act var result = await sut.GetPieAsync(pieId); // Assert Assert.NotNull(result); Assert.Equal(pieId, result.Id); Assert.NotNull(result.Category); }
public async Task GetPiesOfTheWeekAsync_WhenCalled_ReturnsAllPiesOfTheWeekWithCategory() { // Arrange var sut = new PieService(dbContext); // Act var result = await sut.GetPiesOfTheWeekAsync(); // Assert Assert.Equal(piesOfTheWeekCount, result.Count()); Assert.NotNull(result.First().Category); Assert.NotNull(result.Last().Category); }
public async Task GetPieAsync_WhenCalledWithInvalidId_ReturnsNull(int pieId) { // Act Pie pie = null; using (var context = new OnlineShopContext(options)) { var sut = new PieService(context); pie = await sut.GetPieAsync(pieId); } // Assert Assert.Null(pie); }
public async Task GetPieAsync_WhenCalledWithValidId_ReturnsPieWithIdWithCategory(int pieId) { // Act Pie pie = null; using (var context = new OnlineShopContext(options)) { var sut = new PieService(context); pie = await sut.GetPieAsync(pieId); } // Assert Assert.NotNull(pie); Assert.Equal($"Pie{pieId}", pie.Name); Assert.NotNull(pie.Category); }
public async Task GetPiesOfTheWeekAsync_WhenCalled_ReturnsPiesOfTheWeekWithCategory() { // Act List <Pie> pies = null; using (var context = new OnlineShopContext(options)) { var sut = new PieService(context); pies = (await sut.GetPiesOfTheWeekAsync()).ToList(); } // Assert Assert.NotNull(pies); Assert.Equal(2, pies.Count()); Assert.NotNull(pies[0].Category); Assert.NotNull(pies[1].Category); }
public void GetPie_cherry() { PieService pieService = new PieService(); Pie pie = new Pie { Flavour = "cherry", LastMadeOn = DateTime.Now.ToString("T") }; PieRecord expectedResult = new PieRecord { MostRecent = pie, PieAudit = new List <Pie> { pie } }; var actualResult = pieService.GetPieRecord("cherry").GetAwaiter().GetResult(); Assert.AreEqual("cherry", actualResult.MostRecent.Flavour); Assert.AreEqual(DateTime.Now.ToString("T"), actualResult.MostRecent.LastMadeOn); Assert.AreEqual(1, actualResult.PieAudit.Count); Assert.AreEqual(1, actualResult.PieAudit.Where(p => p.Flavour == "cherry").Count()); }