public void GetAllProductGroups_WhenCalled_ReturnOkAndACollection() { _typeHelperService.Setup(t => t.TypeHasProperties <ProductGroupDto>(null)).Returns(true); _uowMock.Setup(uow => uow.ProductGroupRepository.GetAll(null)) .Returns(new List <ProductGroup> { new ProductGroup { Name = "ProductGroupTest" } }); var controller = new ProductGroupsController(_uowMock.Object, _mapper, _typeHelperService.Object); var result = controller.GetAllProductGroups(new ProductGroupResourceParameters { Fields = null }) as OkObjectResult; var content = result.Value as List <ExpandoObject>; result.ShouldNotBe(null); result.StatusCode.ShouldBe(200); content.ShouldNotBe(null); content.ShouldBeOfType(typeof(List <ExpandoObject>)); content.Count.ShouldBe(1); }
public void AddProductGroup_SuccessfulPost_ReturnsCreatedAtRoute() { var productGroup = new ProductGroup { IDProductGroup = 1, IsActive = true, Name = "TestGroup", Products = new List <ProductGroupProduct>() }; _uowMock.Setup(uow => uow.Commit()) .Returns(Task.FromResult(true)); _uowMock.Setup(uow => uow.ProductGroupRepository.Insert(productGroup)) .Returns(Task.CompletedTask); _uowMock.Setup(uow => uow.ProductGroupRepository.GetProductGroupByName("TestGroup")) .Returns(Task.FromResult(new ProductGroup { Name = "TestGroup" })); var controller = new ProductGroupsController(_uowMock.Object, _mapper, _typeHelperService.Object); var result = controller.AddProductGroup(new CreateProductGroupDto { Name = "TestGroup", Products = { 2, 3 } }).Result; result.ShouldNotBe(null); result.ShouldBeOfType(typeof(CreatedAtRouteResult)); var cast = result as CreatedAtRouteResult; var content = cast.Value as ProductGroupDto; content.Name.ShouldBe("TestGroup"); }
public void UpdateGroup_SuccessfulPatch_ReturnsOkWithUpdatedProductGroup() { _uowMock.Setup(uow => uow.ProductGroupRepository.ProductGroupExists("ProductGroupOne")) .Returns(Task.FromResult(true)); _uowMock.Setup(uow => uow.ProductGroupRepository.GetProductGroupByName("ProductGroupOne")) .Returns(Task.FromResult(new ProductGroup { Name = "ProductGroupOne" })); _uowMock.Setup(uow => uow.Commit()) .Returns(Task.FromResult(true)); var controller = new ProductGroupsController(_uowMock.Object, _mapper, _typeHelperService.Object); var result = controller.UpdateGroup("ProductGroupOne", new UpdateProductGroupDto { Name = "ProductGroupTwo" }).Result as OkObjectResult; result.ShouldNotBe(null); result.StatusCode.ShouldBe(200); var content = result.Value as ProductGroupDto; content.ShouldNotBe(null); content.Name.ShouldBe("ProductGroupTwo"); }
public void DeleteProductGroup_SuccessfulDelete_ReturnsNoContent() { _uowMock.Setup(uow => uow.ProductGroupRepository.ProductGroupExists("ProductGroup")) .Returns(Task.FromResult(true)); _uowMock.Setup(uow => uow.Commit()).Returns(Task.FromResult(true)); var controller = new ProductGroupsController(_uowMock.Object, _mapper, _typeHelperService.Object); var result = controller.DeleteProductGroup("ProductGroup").Result as NoContentResult; result.ShouldNotBe(null); result.StatusCode.ShouldBe(204); }
public void AddProductGroup_AlreadyExistingProductGroup_ReturnsConflict() { _uowMock.Setup(uow => uow.ProductGroupRepository.ProductGroupExists("GroupOne")) .Returns(Task.FromResult(true)); var controller = new ProductGroupsController(_uowMock.Object, _mapper, _typeHelperService.Object); var result = controller.AddProductGroup(new CreateProductGroupDto { Name = "GroupOne", Products = { 2, 3 } }).Result as StatusCodeResult; result.StatusCode.ShouldBe(409); }