예제 #1
0
        public void DeleteCategory_ValidCategory_Success()
        {
            //setup mocks
            Mock <ICategoriesRepository> mockRepo = new Mock <ICategoriesRepository>();
            Mock <IMapper> mockMapper             = new Mock <IMapper>();

            Category category = new Category
            {
                Id   = 1,
                Name = "Testowa"
            };
            CategoryDTO categoryDTO = new CategoryDTO
            {
                Id   = 1,
                Name = "Testowa"
            };

            CategoriesService service = new CategoriesService(mockRepo.Object, mockMapper.Object);

            mockMapper.Setup(m => m.Map <CategoryDTO, Category>(categoryDTO)).Returns(category);
            mockRepo.Setup(m => m.GetCategoryById(categoryDTO.Id)).Returns(category);

            //act
            service.DeleteCategoryById(categoryDTO.Id);

            //asserts
            mockRepo.Verify(m => m.Delete(category));
        }
예제 #2
0
        public void DeleteCategory_NotExistingCategory_Unsuccess()
        {
            //setup mocks
            Mock <ICategoriesRepository> mockRepo = new Mock <ICategoriesRepository>();
            Mock <IMapper> mockMapper             = new Mock <IMapper>();

            Category category = new Category
            {
                Id   = 1,
                Name = "Testowa"
            };
            CategoryDTO categoryDTO = new CategoryDTO
            {
                Id   = 1,
                Name = "Testowa"
            };

            CategoriesService service = new CategoriesService(mockRepo.Object, mockMapper.Object);

            mockMapper.Setup(m => m.Map <CategoryDTO, Category>(categoryDTO)).Returns(category);
            mockRepo.Setup(m => m.GetCategoryById(categoryDTO.Id)).Returns((Category)null);

            //act and asserts
            Assert.Throws <ValidationException>(() => {
                service.DeleteCategoryById(categoryDTO.Id);
            });
        }
예제 #3
0
        public IActionResult DeleteCategoryById(int id)
        {
            string urlStr = "http://" + Request.Host.ToString() + "/";

            if (_categoriesService.DeleteCategoryById(id, urlStr))
            {
                return(NoContent());
            }
            return(StatusCode(404));
        }
예제 #4
0
        public IActionResult Delete(int id)
        {
            var category = _catService.DeleteCategoryById(id);

            if (category == false)
            {
                return(BadRequest("404"));
            }
            else
            {
                return(Ok("200"));
            }
        }
예제 #5
0
        public void DeleteCategoryById_ShouldReturn_Success()
        {
            // Arrange
            fakeCategoriesRepository.Setup(a => a.DeleteById(1));
            categoriesService = new CategoriesService(fakeCategoriesRepository.Object,
                                                      new Mock <ICommonRepository>().Object);

            try
            {
                // Act
                categoriesService.DeleteCategoryById(1);
                operationSucceeded = true;
            }
            catch (Exception ex)
            {
                errorMessage = ex.Message + " | " + ex.StackTrace;
            }

            // Assert
            Assert.IsTrue(operationSucceeded, errorMessage);
        }