Esempio n. 1
0
        public void Get_PagingSet_CorrectDtosReturned()
        {
            const uint offset = 1;
            const uint limit  = 2;

            var entities = SeedHelper.CreateTestProducts().ToList();

            var productServiceMock = new Mock <IProductService>();

            productServiceMock
            .Setup(service => service.GetAll(It.Is <PagingParam?>(pg => pg != null && pg.Value.Limit == limit && pg.Value.Offset == offset)))
            .Returns(entities);

            var tested = new ProductsController(ServiceMockHelper.CreateLoggerMock <ProductsController>(), productServiceMock.Object, Utils.MappingHelper.CreateMapper());

            var actionResult = tested.Get(offset, limit).Result;

            productServiceMock.VerifyAll();

            Assert.IsInstanceOf <OkObjectResult>(actionResult);

            var resultData = ((IEnumerable <Product>)((OkObjectResult)actionResult).Value).ToList();

            Dto_1_0_Helper.VerifyCollectionMatch(entities, resultData);
        }
Esempio n. 2
0
        public void Get_InvalidPagingParams_Returns400(uint?offset, uint?limit)
        {
            var tested = new ProductsController(ServiceMockHelper.CreateLoggerMock <ProductsController>(), new Mock <IProductService>().Object, ServiceMockHelper.CreateMapperMock());

            var result = tested.Get(offset, limit).Result;

            Assert.IsInstanceOf <BadRequestObjectResult>(result);
        }
        public async Task GetInt_ProductNotFound_Returns404()
        {
            var productServiceMock = new Mock <IProductService>();

            productServiceMock.Setup(service => service.Get(1))
            .Returns(Task.FromResult <ProductEntity?>(null));

            var tested = new ProductsController(ServiceMockHelper.CreateLoggerMock <ProductsController>(), productServiceMock.Object, ServiceMockHelper.CreateMapperMock());

            var result = await tested.Get(1);

            Assert.IsInstanceOf <NotFoundResult>(result.Result);
        }
        public async Task SetDescription_NotFound_Returns404()
        {
            var productServiceMock = new Mock <IProductService>();

            productServiceMock.Setup(service => service.SetDescription(1, null))
            .Returns(Task.FromResult(UpdateResult.NotFound));

            var tested = new ProductsController(ServiceMockHelper.CreateLoggerMock <ProductsController>(), productServiceMock.Object, ServiceMockHelper.CreateMapperMock());

            var result = await tested.SetDescription(1, null);

            productServiceMock.VerifyAll();
            Assert.IsInstanceOf <NotFoundResult>(result);
        }
        public async Task GetInt_ProductFound_Returns200AndProduct()
        {
            var productEntity      = new ProductEntity(5, "xxx", new Uri("https://domain.countrydomain"), 45, "skdfasdkfjal");
            var productServiceMock = new Mock <IProductService>();

            productServiceMock.Setup(service => service.Get(1))
            .Returns(Task.FromResult <ProductEntity?>(productEntity));

            var tested = new ProductsController(ServiceMockHelper.CreateLoggerMock <ProductsController>(), productServiceMock.Object, Utils.MappingHelper.CreateMapper());

            var result = (await tested.Get(1)).Result;

            productServiceMock.VerifyAll();
            Assert.IsInstanceOf <OkObjectResult>(result);
            Assert.IsTrue(((ProductDto)((OkObjectResult)result).Value).Equals(productEntity));
        }
        public void Get_ReturnsAll()
        {
            var entities = SeedHelper.CreateTestProducts().ToList();

            var productServiceMock = new Mock <IProductService>();

            productServiceMock.Setup(service => service.GetAll(null))
            .Returns(entities);

            var tested = new ProductsController(ServiceMockHelper.CreateLoggerMock <ProductsController>(), productServiceMock.Object, Utils.MappingHelper.CreateMapper());

            var result = tested.Get().ToList();

            productServiceMock.VerifyAll();
            Assert.AreEqual(entities.Count, result.Count);

            Dto_1_0_Helper.VerifyCollectionMatch(entities, result);
        }
Esempio n. 7
0
        public void Get_NoPagingRequested_ReturnsAll()
        {
            var entities = SeedHelper.CreateTestProducts().ToList();

            var productServiceMock = new Mock <IProductService>();

            productServiceMock.Setup(service => service.GetAll(null))
            .Returns(entities);

            var tested = new ProductsController(ServiceMockHelper.CreateLoggerMock <ProductsController>(), productServiceMock.Object, Utils.MappingHelper.CreateMapper());

            var actionResult = tested.Get(null, null).Result;

            productServiceMock.VerifyAll();
            Assert.IsInstanceOf <OkObjectResult>(actionResult);

            var resultData = ((IEnumerable <Product>)((OkObjectResult)actionResult).Value).ToList();

            Dto_1_0_Helper.VerifyCollectionMatch(entities, resultData);
        }