Пример #1
0
        public void GetSingleProductGroup_ExistingProductGroup_ReturnsOkAndProductGroup()
        {
            _typeHelperService.Setup(t => t.TypeHasProperties <ProductGroupDto>(null)).Returns(true);

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

            var controller = new ProductGroupsController(_uowMock.Object, _mapper, _typeHelperService.Object);

            var result = controller.GetProductGroup("ProductGroupOne", null).Result as OkObjectResult;

            result.ShouldNotBe(null);
            result.StatusCode.ShouldBe(200);


            var value = result.Value as ExpandoObject;

            value.ShouldNotBe(null);
            var content = value as IDictionary <string, object>;

            value.ShouldNotBe(null);
            object name = "ProductGroupOne";

            content.TryGetValue("Name", out name).ShouldBe(true);
        }
Пример #2
0
        public void GetSingleProductGroup_UnexistingProductGroup_ReturnsNotFound()
        {
            _typeHelperService.Setup(t => t.TypeHasProperties <ProductGroupDto>(null)).Returns(true);

            _uowMock.Setup(uow => uow.ProductGroupRepository.GetProductGroupByName("ProductGroupOne"))
            .Returns(Task.FromResult(new ProductGroup {
                Name = "ProductGroupOne"
            }));

            var controller = new ProductGroupsController(_uowMock.Object, _mapper, _typeHelperService.Object);

            var result = controller.GetProductGroup("NonExistingGroup", null).Result as NotFoundResult;

            result.ShouldNotBe(null);
            result.StatusCode.ShouldBe(404);
        }