public void CreateProduct_Command_ShouldBe_Throw_Exception_When_ProductAlreadyExists()
        {
            _productRepositoryMock.Setup(x => x.AnyAsync(It.IsAny <Expression <Func <ProductEntity, bool> > >()))
            .ReturnsAsync(true);

            Assert.ThrowsAsync <ProductAlreadyExistsException>(async() =>
            {
                await _handler.Handle(_createProductFaker.Generate(), CancellationToken.None);
            }).Wait();
        }
        public async Task Should_Create_A_Product()
        {
            var command = new CreateProduct
            {
                Description       = "Implants",
                UnitOfMeasurement = "Box",
                CategoryCode      = Fixture.Categories[0].Code
            };
            var newProductCode = await _handler.Handle(command);

            Assert.IsNotNull(_context.Products.Find(newProductCode));
            Assert.AreEqual(command.Description, _context.Products.Find(newProductCode).Description);
        }
        public async Task CreateProductTest()
        {
            var request = new CreateProductCommand()
            {
                Number   = "Number",
                Name     = "Name",
                Quantity = 17
            };

            using var context = new ProductContextTestProvider().GetContext();
            var handler      = new CreateProductHandler(context, new ProductMapper());
            var productCount = context.Products.Count();

            var result = await handler.Handle(request);

            var productCountAfterOperation = context.Products.Count();

            result.ShouldNotBeNull();
            result.Number.ShouldBe("Number");
            result.Name.ShouldBe("Name");
            result.Quantity.ShouldBe(17);
            result.Id.ShouldNotBeNull();
            productCount.ShouldBe(0);
            productCountAfterOperation.ShouldBe(1);
        }
Exemplo n.º 4
0
        public void CreateProductHandlerData_ShouldbeTrue_WhenCreated()
        {
            IRepository <Product>          repository = new Mock <IRepository <Product> >().Object;
            ILogger <CreateProductHandler> logger     = new Mock <ILogger <CreateProductHandler> >().Object;
            IMediator mediator = new Mock <IMediator>().Object;

            CreateProductHandler productHandler = new CreateProductHandler(repository, logger, mediator);

            var result = productHandler.Handle(new Dtos.Requests.CreateProductRequest {
                ProductCode = "P1", Price = 10, Stock = 10
            }, new System.Threading.CancellationToken()).Result;

            Assert.True(result.Data);
        }
Exemplo n.º 5
0
        public async Task CreateProduct_Success_ReturnUnit()
        {
            // Arrange
            // 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.SingleUpload(fileMock.Object)).ReturnsAsync("test");


            var createProductCommand = new CreateProductCommand()
            {
                BrandName      = "Pineapple",
                ProductName    = "PinePhone X",
                CategoryId     = Constants.CategoryId,
                Price          = 1200,
                Stock          = 12,
                Sku            = "12312",
                ProductOptions = new List <ProductOption>
                {
                    new ProductOption
                    {
                        ProductOptionId = Guid.NewGuid(),
                        OptionKey       = "Color",
                        OptionValues    = "Black, Product Red, White"
                    }
                },
                File = fileMock.Object
            };

            // Act
            var sut    = new CreateProductHandler(_fuhoDbContext, _fileSystemService.Object);
            var result = await sut.Handle(createProductCommand, CancellationToken.None);

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