public override async Task <ProductDto> Update(Product entity, string id)
 {
     try
     {
         if (entity.id != id)
         {
             throw new BusinessException("id must be the same in request and payload");
         }
         return(await Task.Run(() =>
         {
             ProductManagementService.UpdateProduct(id, entity);
             if (ProductManagementService.HasErrors())
             {
                 throw new BusinessException(ProductManagementService.ServiceErrorMessage());
             }
             return WrapItem(entity);
         }));
     }
     catch (NotFoundException ex)
     {
         throw new BusinessException("Error retrieving item", ex);
     }
     catch (Exception ex)
     {
         throw new InternalException("Error retrieving item", ex);
     }
 }
 public void InsertNullProductWillThrow(ProductManagementService sut)
 {
     // Fixture setup
     // Exercise system and verify outcome
     Assert.Throws<ArgumentNullException>(() =>
         sut.InsertProduct(null));
     // Teardown
 }
 public void SutIsProductManagementService(ProductManagementService sut)
 {
     // Fixture setup
     // Exercise system
     // Verify outcome
     Assert.IsAssignableFrom<IProductManagementService>(sut);
     // Teardown
 }
Esempio n. 4
0
 public void SutIsProductManagementService(ProductManagementService sut)
 {
     // Fixture setup
     // Exercise system
     // Verify outcome
     Assert.IsAssignableFrom <IProductManagementService>(sut);
     // Teardown
 }
Esempio n. 5
0
 public void InsertNullProductWillThrow(ProductManagementService sut)
 {
     // Fixture setup
     // Exercise system and verify outcome
     Assert.Throws <ArgumentNullException>(() =>
                                           sut.InsertProduct(null));
     // Teardown
 }
 public void DeleteProductWillDeleteProductFromRepository(int id, [Frozen]Mock<ProductRepository> repMock, ProductManagementService sut)
 {
     // Fixture setup
     // Exercise system
     sut.DeleteProduct(id);
     // Verify outcome
     repMock.Verify(r => r.DeleteProduct(id));
     // Teardown
 }
 public void RepositoryIsCorrect([Frozen]ProductRepository expectedRepository, ProductManagementService sut)
 {
     // Fixture setup
     // Exercise system
     ProductRepository result = sut.Repository;
     // Verify outcome
     Assert.Equal(expectedRepository, result);
     // Teardown
 }
 public void ContractMapperIsCorrect([Frozen]IContractMapper expectedMapper, ProductManagementService sut)
 {
     // Fixture setup
     // Exercise system
     IContractMapper result = sut.ContractMapper;
     // Verify outcome
     Assert.Equal(expectedMapper, result);
     // Teardown
 }
Esempio n. 9
0
        public void MapperIsCorrect([Frozen] IContractMapper expectedMapper, ProductManagementService sut)
        {
            // Fixture setup
            // Exercise system
            IContractMapper result = sut.Mapper;

            // Verify outcome
            Assert.Equal(expectedMapper, result);
            // Teardown
        }
        public void ValidateProductManagementService_GetAllProducts()
        {
            var testDbContext            = CreateInMemoryDBContextWithData();
            var mapper                   = CreateAutoMapper();
            var mockValidationService    = new Mock <IProductValidationService>();
            var productManagementService = new ProductManagementService(testDbContext, mapper, mockValidationService.Object);
            var results                  = productManagementService.GetProducts(null);
            var resultsCount             = results.Count();
            var secondItem               = results.ToList()[1];

            Assert.Equal(2, resultsCount);
            Assert.Equal("C2", secondItem.Code);
        }
 public override async Task <ProductDto> GetById(string id)
 {
     try
     {
         return(WrapItem(await Task.Run(() => ProductManagementService.GetProduct(id))));
     }
     catch (NotFoundException ex)
     {
         throw new BusinessException("Error retrieving item", ex);
     }
     catch (Exception ex)
     {
         throw new InternalException("Error retrieving item", ex);
     }
 }
        public void ValidateProductManagementService_CreateProduct()
        {
            var testDbContext = CreateInMemoryDBContext();
            var mapper        = CreateAutoMapper();
            var testProduct   = new ProductDTO()
            {
                Id    = 0,
                Code  = "test1",
                Name  = "Prod 1",
                Price = 120
            };
            var mockValidationService    = new Mock <IProductValidationService>();
            var productManagementService = new ProductManagementService(testDbContext, mapper, mockValidationService.Object);

            Assert.Equal(1, productManagementService.CreateProduct(testProduct));
        }
Esempio n. 13
0
        public void AddCustom()
        {
            var service = new ProductManagementService();

            service.AddCustom("JW 0417", new Models.BeerEntity("Glottal Stop", "JW 0417")
            {
                ABV         = 6.0,
                Name        = "John's Wort Ale",
                BrewYear    = 2017,
                Availablity = "Extremely limited release.",
                Description = "A highly custom beer light brown in color. Made with a helping of John's Wort, this beer is pleasant to the senses and goes down smooth.",
                Type        = "Ale",
                Glass       = "Pilsner",
                LabelUrl    = "http://i.imgur.com/8RVZWQ3.png"
            });
        }
        public async void TestCreateOrder()
        {
            DbContextOptions <CreaturesDbcontext> options = new DbContextOptionsBuilder <CreaturesDbcontext>().UseInMemoryDatabase("CreateProduct").Options;

            using (CreaturesDbcontext context = new CreaturesDbcontext(options))
            {
                Product p = new Product();
                p.ID = 1;
                ProductManagementService Service = new ProductManagementService(context);

                await Service.Create(p);

                var r = await context.Products.FirstOrDefaultAsync(c => c.ID == p.ID);

                Assert.Equal(p, r);
            }
        }
 public override async Task <ProductDto> Create(Product entity)
 {
     try
     {
         return(await Task.Run(() =>
         {
             ProductManagementService.CreateProduct(entity);
             if (ProductManagementService.HasErrors())
             {
                 throw new BusinessException(ProductManagementService.ServiceErrorMessage());
             }
             return WrapItem(entity);
         }));
     }
     catch (Exception ex)
     {
         throw new InternalException("Error retrieving item", ex);
     }
 }
        public async void TestupdateProduct()
        {
            DbContextOptions <CreaturesDbcontext> options = new DbContextOptionsBuilder <CreaturesDbcontext>().UseInMemoryDatabase("updateProduct").Options;

            using (CreaturesDbcontext context = new CreaturesDbcontext(options))
            {
                Product p = new Product();
                p.ID   = 1;
                p.Name = "unicorn";
                ProductManagementService Service = new ProductManagementService(context);
                await Service.Create(p);

                p.Name = "test";
                await Service.UpdateProduct(p);

                var expect = await context.Products.FirstOrDefaultAsync(c => c.ID == 1);

                Assert.Equal("test", expect.Name);
            }
        }
        public async void TestGetallProducts()
        {
            DbContextOptions <CreaturesDbcontext> options = new DbContextOptionsBuilder <CreaturesDbcontext>().UseInMemoryDatabase("GetProducts").Options;

            using (CreaturesDbcontext context = new CreaturesDbcontext(options))
            {
                Product p = new Product();
                p.ID = 1;
                Product pp = new Product();
                pp.ID = 2;
                ProductManagementService Service = new ProductManagementService(context);

                await Service.Create(p);

                await Service.Create(pp);

                var res = await Service.GetAllProducts();

                Assert.Equal(2, res.Count);
            }
        }
        public async void TestdeleteProduct()
        {
            DbContextOptions <CreaturesDbcontext> options = new DbContextOptionsBuilder <CreaturesDbcontext>().UseInMemoryDatabase("DeleteProduct").Options;

            using (CreaturesDbcontext context = new CreaturesDbcontext(options))
            {
                Product p = new Product();
                p.ID = 1;
                Product pp = new Product();
                pp.ID = 2;
                ProductManagementService Service = new ProductManagementService(context);

                await Service.Create(p);

                await Service.Create(pp);

                await Service.DeleteProduct(1);

                var expect = await context.Products.FirstOrDefaultAsync(c => c.ID == 1);

                Assert.Null(expect);
            }
        }
Esempio n. 19
0
 public void DeleteProductWillDeleteProductFromRepository(int id, [Frozen] Mock <ProductRepository> repMock, ProductManagementService sut)
 {
     // Fixture setup
     // Exercise system
     sut.DeleteProduct(id);
     // Verify outcome
     repMock.Verify(r => r.DeleteProduct(id));
     // Teardown
 }
Esempio n. 20
0
        public void ProductRepositoryIsCorrect([Frozen] ProductRepository expectedRepository, ProductManagementService sut)
        {
            // Fixture setup
            // Exercise system
            ProductRepository result = sut.ProductRepository;

            // Verify outcome
            Assert.Equal(expectedRepository, result);
            // Teardown
        }
Esempio n. 21
0
        public static void Main(string[] args)
        {
            ProductManagementService service = new ProductManagementService();

            service.ExecuteAll();
        }
 internal override async Task <IEnumerable <Product> > Get(Filter filter)
 {
     return(await ProductManagementService.FindProducts(filter));
 }
 internal override int GetTotalRecords()
 {
     return(ProductManagementService.GetTotalProducts());
 }
 public void ProductManagerTest()
 {
     _productManager = new ProductManagementService(Config["Values:DBConnectionString"], "Application");
 }