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); }
public CreateProductTests() { _context = ProductCatalogContextFactory.Create(); var mapper = MapperFactory.Create(); _handler = new CreateProductHandler(_context, mapper); }
public CreateProductHandlerTests() { _productsRepository = Substitute.For <IProductsRepository>(); _busPublisher = Substitute.For <IBusPublisher>(); _context = Substitute.For <ICorrelationContext>(); _commandHandler = new CreateProductHandler(_productsRepository, _busPublisher); _commandHandler = new CreateProductHandler(_productsRepository, _busPublisher); }
public CreateProductCommandTests() { _productRepositoryMock = new Mock <IRepository <ProductEntity> >(); _handler = new(_productRepositoryMock.Object); _createProductFaker = new Faker <CreateProductCommand>() .RuleFor(x => x.ProductCode, f => f.Random.AlphaNumeric(3)) .RuleFor(x => x.Price, f => f.Random.Decimal(10, 100)) .RuleFor(x => x.Stock, f => f.Random.Int(1, 20)); }
public async void CreatedProductShouldReturnId() { var sut = new CreateProductHandler(_context); var response = await sut .Handle( new CreateProductCommand { Name = "Intel i9-9900k", Description = "Nowy niezawodny", Category = 1.Adapt < CategoryViewModel > () }, CancellationToken.None);
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); }
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); }
public void AddsProductToRepository_RaisesIntegrationEvent() { var repository = new Mock <IProductRepository>(MockBehavior.Strict); repository.Setup(r => r.AddAsync(It.Is <Domain.Product>(p => ValidateEquality(p)))).Returns(Task.CompletedTask).Verifiable(); repository.Setup(r => r.SaveChanges()).Returns(Task.CompletedTask).Verifiable(); var busPublisher = new Mock <IBusPublisher>(MockBehavior.Strict); busPublisher.Setup(p => p.Publish <IProductCreated>(It.Is <IProductCreated>(e => ValidateEquality(e)))).Returns(Task.CompletedTask).Verifiable(); var handler = new CreateProductHandler(repository.Object, busPublisher.Object); var result = handler.HandleAsync(Cmd, new Mock <ICorrelationContext>().Object).GetAwaiter().GetResult(); Assert.IsTrue(result.Successful); repository.Verify(); busPublisher.Verify(); }
public async Task <ActionResult> Post( [FromServices] CreateProductHandler handler, [FromBody] CreateProductCommand command) { try { var result = (CommandResult)handler.handle(command); if (!result.Success) { return(BadRequest(result)); } return(Ok(result)); } catch (Exception e) { return(BadRequest(e)); } }
public string[] parseInput(String input) { CommandHandler commandHandler; List <string> list = input.Split(' ').ToList(); if (list.Contains(createProduct)) { commandHandler = new CreateProductHandler(); } else if (list.Contains(getProduct)) { commandHandler = new GetProductHandler(); } else if (list.Contains(createOrder)) { commandHandler = new CreateOrderHandler(); } else if (list.Contains(createCampaign)) { commandHandler = new CreateCampaignHandler(); } else if (list.Contains(getCampaign)) { commandHandler = new GetCampaignHandler(); } else if (list.Contains(increaseTime)) { commandHandler = new IncreaseTimeHandler(); } else { return(null); } Console.WriteLine(commandHandler.Execute(list)); return(null); }
public ProductController(IProductRepository repository, CreateProductHandler handler) { _repository = repository; _handler = handler; }
public CreateProductTest() { _createProductHandler = new CreateProductHandler(); }
public CreateOrderTest() { _createOrderHandler = new CreateOrderHandler(); _createProductHandler = new CreateProductHandler(); }
public CreateProductHandlerTests() { repository = Substitute.For <IProductsRepository>(); handler = new CreateProductHandler(repository); }
public GetProductTest() { _getProductHandler = new GetProductHandler(); _createProductHandler = new CreateProductHandler(); }