Exemple #1
0
        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_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);
        }