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 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); }