public void WhenProductCategoryIsNullThenNotSuccessfullStatusIsReturned() { ProductCategoryService service = new ProductCategoryService(Mock.Of <IProductCategoryRepository>(), Mock.Of <IShopRepository>()); ServiceActionResult result = service.AddProductCategory(null); result.Status.Should().Be(ActionStatus.NotSuccessfull); result.Reason.Should().Be("Product category cannot be null"); }
public string AddProductCategory(ProductCategory productCategory) { // Validate and Add to Database if (_productCategoryService.ValidateProductCategoryInfo(productCategory) == true) { return(_productCategoryService.AddProductCategory(productCategory).ToString()); } else { return("-1"); } }
public void WhenShopGuidIsEmptyGuidThenNotSuccessfullActionIsReturned() { ProductCategoryService service = new ProductCategoryService(Mock.Of <IProductCategoryRepository>(), Mock.Of <IShopRepository>()); ServiceActionResult result = service.AddProductCategory(new ProductCategoryDto() { CategoryName = "testName", ShopGuid = Guid.Empty }); result.Status.Should().Be(ActionStatus.NotSuccessfull); result.Reason.Should().Be("Shop guid cannot be empty"); }
public void WhenProductCategoryNameIsNullOrEmptyThenNotSuccessfullStatusIsReturned(string categoryName) { ProductCategoryService service = new ProductCategoryService(Mock.Of <IProductCategoryRepository>(), Mock.Of <IShopRepository>()); ServiceActionResult result = service.AddProductCategory(new ProductCategoryDto() { CategoryName = categoryName }); result.Status.Should().Be(ActionStatus.NotSuccessfull); result.Reason.Should().Be("Category name cannot be null or empty"); }
public ActionResult Create(ProductCategoryViewModel model) { try { bool result = _productCategoryService.AddProductCategory(model); if (result) { return(RedirectToAction(nameof(Index))); } throw new Exception(); } catch { ModelState.AddModelError(string.Empty, "Ooops! Something went wrong!"); return(View()); } }
public void WhenShopDoesntExistThenNotSuccessfullActionResultIsReturned() { Guid shopGuid = Guid.NewGuid(); var shopRepositoryMock = new Mock <IShopRepository>(); shopRepositoryMock.Setup(r => r.GetShopById(shopGuid)).Returns((Shop)null); ProductCategoryService service = new ProductCategoryService( Mock.Of <IProductCategoryRepository>( r => r.GetProductCategoryByName(shopGuid, "testName") == new Business.Products.ProductCategory("testName")), shopRepositoryMock.Object); ServiceActionResult result = service.AddProductCategory(new ProductCategoryDto() { CategoryName = "testName", ShopGuid = shopGuid }); result.Status.Should().Be(ActionStatus.NotSuccessfull); result.Reason.Should().Be("Provided shop doesn't exist"); }
public void WhenProductCategoryWithDefinedGuidAlreadyExistsThenNotSuccessfullStatusIsReturned() { Guid shopGuid = Guid.NewGuid(); ProductCategoryService service = new ProductCategoryService( Mock.Of <IProductCategoryRepository>( r => r.GetProductCategoryByName(shopGuid, "testName") == new Business.Products.ProductCategory("testName")), Mock.Of <IShopRepository>(r => r.GetShopById(shopGuid) == new Shop() { UniqueId = shopGuid })); ServiceActionResult result = service.AddProductCategory(new ProductCategoryDto() { CategoryName = "testName", ShopGuid = shopGuid }); result.Status.Should().Be(ActionStatus.NotSuccessfull); result.Reason.Should().Be("Product category already exist"); }
public void WhenProductCategoryIsSuccessfullyAddedThenSuccessfullServiceActionResultIsReturned() { var shopId = Guid.NewGuid(); var repositoryMock = new Mock <IProductCategoryRepository>(); repositoryMock.Setup(r => r.GetProductCategoryByName(shopId, "testName")).Returns((Business.Products.ProductCategory)null); var shopRepositoryMock = new Mock <IShopRepository>(); shopRepositoryMock.Setup(r => r.GetShopById(shopId)).Returns(new Shop() { UniqueId = shopId }); ProductCategoryService service = new ProductCategoryService(repositoryMock.Object, shopRepositoryMock.Object); ServiceActionResult result = service.AddProductCategory(new ProductCategoryDto() { CategoryName = "testName", ShopGuid = shopId }); result.ShouldBeEquivalentTo(ServiceActionResult.Successfull); repositoryMock.Verify(r => r.AddToDatabase(It.IsAny <Business.Products.ProductCategory>()), Times.Once()); }