public async Task DeleteAsync_ShouldReturnTrueStyleIfSucceded() { //Arrange var options = InMemory.GetOptions("DeleteAsync_ShouldReturnTrueStyleIfSucceded"); using (var context = new BOContext(options)) { var style = new BeerStyle() { Name = "Ale", Description = "This description" }; context.BeerStyles.Add(style); await context.SaveChangesAsync(); } using (var context = new BOContext(options)) { //Act var sut = new BeerStylesService(context); var result = await sut.DeleteAsync(1); //Assert Assert.AreEqual(result, true); } }
public async Task DeleteAsync_ShouldDeleteStyleIfExist() { //Arrange var options = InMemory.GetOptions("DeleteAsync_ShouldDeleteStyleIfExist"); using (var context = new BOContext(options)) { var style = new BeerStyle() { Name = "Ale", Description = "This description" }; context.BeerStyles.Add(style); await context.SaveChangesAsync(); } using (var context = new BOContext(options)) { //Act var sut = new BeerStylesService(context); await sut.DeleteAsync(1); var dbresult = await context.BeerStyles.FirstOrDefaultAsync(c => c.Name == "Ale"); //Assert Assert.AreEqual(dbresult.Name, "Ale"); Assert.AreEqual(dbresult.DeletedOn, dbresult.ModifiedOn); Assert.AreEqual(dbresult.IsDeleted, true); } }
public async Task DeleteAsync_ShouldDeleteRecordBeersOfStyleIfExist() { //Arrange var options = InMemory.GetOptions("DeleteAsync_ShouldDeleteRecordBeersOfStyleIfExist"); using (var context = new BOContext(options)) { var country = new Country() { Name = "Bulgaria", Breweries = new List <Brewery>() { new Brewery() { Name = "Brewery", } } }; context.Countries.Add(country); await context.SaveChangesAsync(); var beer = new Beer() { Name = "Carlsberg", ABV = 5, Country = await context.Countries.FirstOrDefaultAsync(c => c.Name == "Bulgaria"), Brewery = await context.Breweries.FirstOrDefaultAsync(b => b.Name == "Brewery"), Style = new BeerStyle() { Name = "Ale", Description = "Some description", }, Rating = 5 }; context.Beers.Add(beer); await context.SaveChangesAsync(); } using (var context = new BOContext(options)) { //Act var sut = new BeerStylesService(context); await sut.DeleteAsync(1); var dbresult = await context.BeerStyles.FirstOrDefaultAsync(c => c.Name == "Ale"); var dbBeerResult = await context.Beers.FirstOrDefaultAsync(b => b.StyleID == dbresult.ID); //Assert Assert.AreEqual(dbresult.Name, "Ale"); Assert.AreEqual(dbresult.DeletedOn, dbresult.ModifiedOn); Assert.AreEqual(dbresult.IsDeleted, true); Assert.AreEqual(dbBeerResult.Name, "Carlsberg"); Assert.AreEqual(dbBeerResult.DeletedOn, dbBeerResult.ModifiedOn); Assert.AreEqual(dbBeerResult.IsDeleted, true); } }
public async Task DeleteAsync_ShouldReturnFalseIfStyleDoesntExistAsync() { //Arrange var options = InMemory.GetOptions("DeleteAsync_ShouldReturnFalseIfStyleDoesntExistAsync"); using (var context = new BOContext(options)) { } using (var context = new BOContext(options)) { //Act var sut = new BeerStylesService(context); var result = await sut.DeleteAsync(1); //Assert Assert.AreEqual(result, false); } }