public async Task CreateIngredientCorrectly() { var options = TestUtilities.GetOptions(nameof(CreateIngredientCorrectly)); var mapToDTOMock = new Mock <IDTOServiceMapper <Ingredient, IngredientDTO> >(); var mapToEntityMock = new Mock <IDTOServiceMapper <IngredientDTO, Ingredient> >(); var ingredientDTOMock = new Mock <IngredientDTO>(); var ingredient = new Ingredient() { Name = "Chubaka", Id = "1", }; mapToEntityMock.Setup(m => m.MapFrom(ingredientDTOMock.Object)).Returns(ingredient); using (var actContext = new IriOnCocktailServiceDbContext(options)) { var sut = new IngredientService(actContext, mapToDTOMock.Object, mapToEntityMock.Object); await sut.CreateIngredient(ingredientDTOMock.Object); } using (var assertContext = new IriOnCocktailServiceDbContext(options)) { Assert.AreEqual(1, assertContext.Ingredients.Count()); } }
public async Task Create_Correct_Ingredient() { var options = Utils.GetOptions(nameof(Create_Correct_Ingredient)); using (var arrangeContext = new CMContext(options)) { var sut = new IngredientService(arrangeContext); var ingredientDTO = await sut.CreateIngredient( new IngredientDTO { Id = Guid.Parse("1b98e50e-8314-4b1e-82df-491c3c8d086f"), Name = "Gin", Abv = 40, Description = "Gin is a distilled alcoholic drink that derives its " + "predominant flavour from juniper berries (Juniperus communis). " + "Gin is one of the broadest categories of spirits, all of various origins, styles," + " and flavour profiles, that revolve around juniper as a common ingredient.", TypeId = Guid.Parse("24cd3f18-f0a8-4f66-bc5b-2108e099cf53"), }); } using (var assertContext = new CMContext(options)) { Assert.AreEqual("Gin", assertContext.Ingredients.First().Name); } }
public async Task Throw_Exception_When_Ingredient_IsNull() { var options = Utils.GetOptions(nameof(Throw_Exception_When_Ingredient_IsNull)); using (var assertContext = new CMContext(options)) { var sut = new IngredientService(assertContext); await Assert.ThrowsExceptionAsync <ArgumentNullException> (async() => await sut.CreateIngredient(null)); } }
public async Task CreateIngredientShouldProperlyWork() { var ingredientTypeRepository = new Mock <IRepository <IngredientType> >(); var ingredientRepository = new Mock <IRepository <Ingredient> >(); var service = new IngredientService(ingredientTypeRepository.Object, ingredientRepository.Object); var actualResult = await service.CreateIngredient <IngredientBindingModel>(new IngredientBindingModel { Name = "Carrots" }); ingredientRepository.Verify(x => x.AddAsync(It.IsAny <Ingredient>()), Times.Once, "Create ingredients should call AddAsync Once with correct type."); Assert.True(actualResult == true, "Create ingredient should return true with correct data"); }
public async Task <IActionResult> Create(Ingredient ingredient) { if (ModelState.IsValid) { await _ingredientService.CreateIngredient(ingredient); return(RedirectToAction(nameof(Index))); } await FillViewData(); return(View(ingredient)); }
public void CreateIngredient() { using var context = new InMemoryDbContext(); var newIngredientDto = new NewIngredientDto(new ExistingArticleDto(1, "Tomato", new ExistingArticleGroupDto(1, "Vegetables"), false), 2, new ExistingUnitDto(1, "Piece")); var ingredientActionMock = new Mock <IIngredientAction>(); var testee = new IngredientService(ingredientActionMock.Object, context); testee.CreateIngredient(newIngredientDto); ingredientActionMock.Verify(x => x.CreateIngredient(newIngredientDto), Times.Once); }
public IHttpActionResult Post(IngredientCreate ingredient) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!ingredientService.CreateIngredient(ingredient)) { return(InternalServerError()); } return(Ok()); }