public OutputDtoAddCategory Create(InputDtoAddCategory inputDtoAddCategory) { //DTO --> Domain var categoryFromDto = _categoryFactory.CreateFromName(inputDtoAddCategory.Name); //Repository demande un element du domain var categoriesInDb = _categoryRepository.Query(); foreach (var category in categoriesInDb) { if (category.Name == categoryFromDto.Name) { throw new Exception("Category already in database"); } } //On crée la catégorie var categoryInDb = _categoryRepository.Create(categoryFromDto); //Domain -> DTO return(new OutputDtoAddCategory { Id = categoryInDb.Id, Name = categoryInDb.Name }); }
public void Create_InputDtoAddCategory_ThrowsAlreadyInDBException() { var input = new InputDtoAddCategory("Multi"); _categoryFactory.CreateFromName(input.Name).Returns(new Category(input.Name)); _categoryRepository.Query().Returns(getCategoryList()); var exception = Assert.Throws <Exception>(() => _categoryService.Create(input)); Assert.AreEqual("Category already in database", exception.Message); }
public OutputDtoAddCategory CreateSubCategory(int parentCategoryId, InputDtoAddCategory inputDtoAddCategory) { var categoryFromDto = new Category { Title = inputDtoAddCategory.Title }; var categoryInDb = _categoryRepository.CreateSubCategory(parentCategoryId, categoryFromDto); return(new OutputDtoAddCategory { Id = categoryInDb.Id, Title = categoryInDb.Title }); }
public void Create_InputDtoAddCategory_AreSame() { var input = new InputDtoAddCategory("Cardio"); _categoryFactory.CreateFromName(input.Name).Returns(new Category(input.Name)); var icategory = _categoryFactory.CreateFromName(input.Name); _categoryRepository.Query().Returns(getCategoryList()); _categoryRepository.Create(icategory).Returns(new Category(input.Name)); var res = _categoryService.Create(input); var expected = new OutputDtoAddCategory("Cardio"); Assert.AreEqual(expected, res); }
public ActionResult <OutputDtoAddCategory> CreateSubCategory(int categoryId, [FromBody] InputDtoAddCategory subCategory) { return(Ok(_categoryService.CreateSubCategory(categoryId, subCategory))); }
public ActionResult <OutputDtoAddCategory> CreateCategory([FromBody] InputDtoAddCategory inputDtoAddCategory) { return(Ok(_categoryService.CreateCategory(inputDtoAddCategory))); }