public async Task ReturnFalse_when_NotValidIngredientIDAsync() { //Arrange var options = Utils.GetOptions("ReturnFalse_when_NotValidIngredientIDAsync"); var entity = new Ingredient { Name = "Lime", IsAlcoholic = false }; var mockMapper = new Mock <IIngredientMapper>(); using (var arrangeContext = new BCcontext(options)) { arrangeContext.Ingredients.Add(entity); arrangeContext.SaveChanges(); } //Act & Assert using (var context = new BCcontext(options)) { var sut = new IngredientsService(context, mockMapper.Object); var result = await sut.DeleteAsync(Utils.MySampleGuid()); Assert.IsFalse(result); } }
public async Task DeleteCocktail_ShouldReturnTrue_when_ValidAsync() { //Arrange var options = Utils.GetOptions(nameof(DeleteCocktail_ShouldReturnTrue_when_ValidAsync)); var entity = new Cocktail { Id = Utils.MySampleGuid(), Name = "Mohito", IsDeleted = false, }; var mockMapper = new Mock <ICocktailMapper>(); mockMapper.Setup(x => x.MapDTOToEntity(It.IsAny <CocktailDTO>())) .Returns((CocktailDTO x) => new Cocktail() { Id = x.Id, Name = x.Name, TimesRated = x.TimesRated, }); mockMapper.Setup(x => x.MapEntityToDTO(It.IsAny <Cocktail>())) .Returns((Cocktail x) => new CocktailDTO() { Id = x.Id, Name = x.Name, TimesRated = x.TimesRated, }); var mockBarMapper = new Mock <IBarMapper>(); using (var arrangeContext = new BCcontext(options)) { arrangeContext.Cocktails.Add(entity); arrangeContext.SaveChanges(); } //Act & Assert using (var context = new BCcontext(options)) { var sut = new CocktailsService(context, mockMapper.Object, mockBarMapper.Object); var result = await sut.DeleteAsync(Utils.MySampleGuid()); Assert.IsTrue(result); } }
public async System.Threading.Tasks.Task ReturnCorrectIngredient_when_ValidAsync() { //Arrange var options = Utils.GetOptions("ReturnCorrectIngredient_when_ValidAsync"); var entity = new Ingredient { Id = Utils.MySampleGuid(), Name = "Lime", IsAlcoholic = false }; var mockMapper = new Mock <IIngredientMapper>(); mockMapper.Setup((x) => x.MapEntityToDTO(It.IsAny <Ingredient>())) .Returns(new IngredientDTO() { Id = entity.Id, Name = entity.Name, IsAlcoholic = entity.IsAlcoholic, }); using (var arrangeContext = new BCcontext(options)) { arrangeContext.Ingredients.Add(entity); arrangeContext.SaveChanges(); } //Act & Assert using (var context = new BCcontext(options)) { var sut = new IngredientsService(context, mockMapper.Object); var dbResult = await context.Ingredients.FirstOrDefaultAsync(x => x.Name == entity.Name); var result = await sut.GetAsync(dbResult.Id); Assert.AreEqual(dbResult.Id, result.Id); Assert.AreEqual(dbResult.Name, result.Name); Assert.AreEqual(dbResult.IsAlcoholic, result.IsAlcoholic); } }
public void ReturnCorrectIngredients_when_AllValid() { //Arrange var options = Utils.GetOptions("ReturnCorrectIngredients_when_AllValid");; var entity1 = new Ingredient { Name = "Lime", IsAlcoholic = false }; var entity2 = new Ingredient { Name = "Coca Cola", IsAlcoholic = false }; var entity3 = new Ingredient { Name = "Bacardi Oro", IsAlcoholic = true }; var entity1DTO = new IngredientDTO { Name = "Lime", IsAlcoholic = false }; var entity2DTO = new IngredientDTO { Name = "Coca Cola", IsAlcoholic = false }; var entity3DTO = new IngredientDTO { Name = "Bacardi Oro", IsAlcoholic = true }; var mockMapper = new Mock <IIngredientMapper>(); mockMapper .Setup((x) => x.MapEntityToDTO(It.Is <Ingredient>(a => a.Name == entity1.Name))) .Returns(entity1DTO); mockMapper .Setup((x) => x.MapEntityToDTO(It.Is <Ingredient>(a => a.Name == entity2.Name))) .Returns(entity2DTO); mockMapper .Setup((x) => x.MapEntityToDTO(It.Is <Ingredient>(a => a.Name == entity3.Name))) .Returns(entity3DTO); using (var arrangeContext = new BCcontext(options)) { arrangeContext.Ingredients.Add(entity1); arrangeContext.Ingredients.Add(entity2); arrangeContext.Ingredients.Add(entity3); arrangeContext.SaveChanges(); } //Act & Assert using (var context = new BCcontext(options)) { var sut = new IngredientsService(context, mockMapper.Object); var result = sut.GetAllAsync().Result.ToList(); Assert.AreEqual(3, result.Count()); Assert.AreEqual(entity3.Name, result[2].Name); Assert.AreEqual(entity3.IsAlcoholic, result[2].IsAlcoholic); } }