public async void ListOfProductsWillBeNotNull()
        {
            var            mapper         = InfrastructureFunctions.GetMapperInstance();
            ProductService productService = new ProductService(DbContext, mapper);

            Assert.NotNull(await productService.GetAllAsync());
        }
        public async void GetProductWithWrongName()
        {
            var            mapper         = InfrastructureFunctions.GetMapperInstance();
            ProductService productService = new ProductService(DbContext, mapper);
            var            result         = await productService.GetByAsync("x");

            Assert.Null(result);
        }
        public void UpdateProductWithWrongId()
        {
            var            mapper         = InfrastructureFunctions.GetMapperInstance();
            ProductService productService = new ProductService(DbContext, mapper);
            var            product        = AddSampleProduct();

            product.Id = -1;
            var productDto = mapper.Map <Product, UpdateProductDto>(product);

            Assert.Throws <DbUpdateConcurrencyException>(() => productService.Update(productDto, true));
        }
        public async void CheckResultTypeOfGetProductForIndexPageMethod()
        {
            var            mapper         = InfrastructureFunctions.GetMapperInstance();
            ProductService productService = new ProductService(DbContext, mapper);

            AddSampleProducts();
            var result = await productService.GetProductForIndexPage();

            Assert.IsType <List <ProductIndexPageDetailDto> >(await productService.GetProductForIndexPage());
            Assert.NotNull(result);
            Assert.NotEmpty(result);
        }
        public async void GetProductById()
        {
            AddSampleProducts();
            var            mapper         = InfrastructureFunctions.GetMapperInstance();
            ProductService productService = new ProductService(DbContext, mapper);
            var            result         = await productService.GetByAsync(1);

            var          mapperOrginalObject = mapper.Map <GetAllProductDto>(DbContext.Set <Product>().FirstAsync(c => c.Id == 1).Result);
            CompareLogic compareLogic        = new CompareLogic();
            var          resultComparer      = compareLogic.Compare(mapperOrginalObject, result);

            Assert.True(resultComparer.AreEqual);
        }
        public void UpdateProduct()
        {
            var            mapper         = InfrastructureFunctions.GetMapperInstance();
            ProductService productService = new ProductService(DbContext, mapper);
            var            product        = AddSampleProduct();

            product.Name   = "test1";
            product.Detail = "test2";
            var productDto       = mapper.Map <Product, UpdateProductDto>(product);
            var productDtoResult = productService.Update(productDto, true);

            Assert.Equal(productDto, productDtoResult);
        }
        public void RemoveProductWithObject()
        {
            AddSampleProduct();

            //arrange
            var mapperInstance = InfrastructureFunctions.GetMapperInstance();

            ProductService productService = new ProductService(DbContext, mapperInstance);

            //act
            productService.Remove(new RemoveProductDto()
            {
                Id = 1
            }, true);

            //assert
            Assert.Empty(DbContext.Set <Product>());
        }
 public async void InsertProductWithNullProperties()
 {
     var            mapper         = InfrastructureFunctions.GetMapperInstance();
     ProductService productService = new ProductService(DbContext, mapper);
     await Assert.ThrowsAsync <DbUpdateException>(() => productService.InsertAsync(new InsertProductDto(), CancellationToken.None, true));
 }