コード例 #1
0
        public async Task UpdateProductWhichIsNotInDb()
        {
            var id = Guid.NewGuid();
            var contextProvider = new ProductContextTestProvider();

            using var context = contextProvider.GetContext();
            contextProvider.AddProduct(new Database.Entities.Product(id, "Name1", "Number1", 11, 22));
            var handler      = new UpdateProductHandler(context, new ProductMapper());
            var productCount = context.Products.Count();

            var result = await handler.Handle(_request);

            var productCountAfterOperation = context.Products.Count();

            productCount.ShouldBe(1);
            productCountAfterOperation.ShouldBe(1);
            result.ShouldBeNull();
            var productDb = context.Products.SingleOrDefault(x => x.Id == id);

            productDb.ShouldNotBeNull();
            productDb.Number.ShouldBe("Number1");
            productDb.Name.ShouldBe("Name1");
            productDb.Quantity.ShouldBe(11);
            productDb.Id.ShouldBe(id);
        }
コード例 #2
0
        public async Task Should_Update_A_Product_Description()
        {
            var command = new UpdateProduct
            {
                Code     = Fixture.Products[0].Code,
                Barcodes = new List <string> {
                    "000"
                },
                Description       = "Implants",
                UnitOfMeasurement = "Box",
                CategoryCode      = Fixture.Categories[0].Code
            };
            await _handler.Handle(command);

            Assert.AreEqual("Implants", _context.Products.Find(1).Description);
        }
コード例 #3
0
        public async Task UpdateProductWhenDbIsEmpty()
        {
            using var context = new ProductContextTestProvider().GetContext();
            var handler      = new UpdateProductHandler(context, new ProductMapper());
            var productCount = context.Products.Count();

            var result = await handler.Handle(_request);

            var productCountAfterOperation = context.Products.Count();

            productCount.ShouldBe(0);
            productCountAfterOperation.ShouldBe(0);
            result.ShouldBeNull();
        }
コード例 #4
0
        public async void UpdateProductHandlerShouldReturnId()
        {
            var sut      = new UpdateProductHandler(_context);
            var category = await _context.Categories.FirstOrDefaultAsync();

            var result = await sut.Handle(new UpdateProductCommand {
                Description = "Zmieniono",
                Name        = "Ryzen 4600fx",
                Category    = category.Adapt <CategoryViewModel>(),
                Price       = 1200
            },
                                          CancellationToken.None);

            var changed = await _context.Products.FirstAsync(x => x.Id == result);

            result.Should().BeOfType(typeof(int));
            changed.Description.Should().Be("Zmieniono");
        }
コード例 #5
0
        public async Task UpdateProduct()
        {
            var contextProvider = new ProductContextTestProvider();

            using var context = contextProvider.GetContext();
            contextProvider.AddProduct(new Database.Entities.Product(_request.Id, "Name1", "Number1", 11, 22));
            var handler      = new UpdateProductHandler(context, new ProductMapper());
            var productCount = context.Products.Count();

            var result = await handler.Handle(_request);

            var productCountAfterOperation = context.Products.Count();

            productCount.ShouldBe(1);
            productCountAfterOperation.ShouldBe(1);
            result.ShouldNotBeNull();
            result.Number.ShouldBe("Number");
            result.Name.ShouldBe("Name");
            result.Quantity.ShouldBe(17);
            result.Id.ShouldBe(_request.Id);
        }
コード例 #6
0
        public async Task UpdateProduct_Success_ReturnUnit()
        {
            // Arrange
            // Mock data for product
            var category = new Category()
            {
                CategoryId = Constants.CategoryId,
                Name       = "Phone",
                Thumbnail  = "no-image.jpg"
            };

            var products = new List <Product>()
            {
                new Product()
                {
                    ProductId      = Constants.ProductId,
                    BrandName      = "Pineapple",
                    ProductName    = "PinePhone X",
                    CategoryId     = category.CategoryId,
                    Price          = 1200,
                    Stock          = 12,
                    Sku            = "12312",
                    Category       = category,
                    ProductOptions = new List <ProductOption>()
                    {
                        new ProductOption()
                        {
                            ProductOptionId = Guid.NewGuid(),
                            OptionKey       = "Color",
                            OptionValues    = "Black, Product Red, White"
                        }
                    },
                    Images     = "no-images",
                    CreateDate = DateTime.Now,
                    CreatedBy  = Constants.UserId.ToString()
                }
            };

            _fuhoDbContext.Products.AddRange(products);
            _fuhoDbContext.SaveChanges();

            // Mock signle upload file
            var fileMock = new Mock <IFormFile>();
            //Setup mock file using a memory stream
            var content  = "Hello World from a Fake File";
            var fileName = "test.png";
            var ms       = new MemoryStream();
            var writer   = new StreamWriter(ms);

            writer.Write(content);
            writer.Flush();
            ms.Position = 0;
            fileMock.Setup(_ => _.OpenReadStream()).Returns(ms);
            fileMock.Setup(_ => _.FileName).Returns(fileName);
            fileMock.Setup(_ => _.Length).Returns(ms.Length);

            var mockImage = _fileSystemService.Setup(x => x.SingleUpdate(fileMock.Object, fileName)).ReturnsAsync(fileName);


            var updateProductCommand = new UpdateProductCommand()
            {
                BrandName      = "Test",
                ProductName    = "Test",
                CategoryId     = Constants.CategoryId,
                ProductId      = Constants.ProductId,
                Price          = 1000,
                Stock          = 10,
                Sku            = "123123",
                ProductOptions = new List <ProductOption>
                {
                    new ProductOption
                    {
                        ProductOptionId = Guid.NewGuid(),
                        OptionKey       = "Color",
                        OptionValues    = "Black, Product Red, White"
                    }
                },
                File   = fileMock.Object,
                UserId = Constants.UserId.ToString()
            };

            // Act
            var sut    = new UpdateProductHandler(_fuhoDbContext, _fileSystemService.Object, _logger.Object);
            var result = await sut.Handle(updateProductCommand, CancellationToken.None);

            // Result
            Assert.IsType <Unit>(result);
        }