public DeleteProductCommandHandlerTest()
 {
     productRepository = new Mock <IProductRepository>();
     bus            = new Mock <IBus>();
     command        = new DeleteProductCommand(productId);
     product        = new Product();
     commandHandler = new DeleteProductCommandHandler(productRepository.Object, bus.Object);
 }
Ejemplo n.º 2
0
 public ProductsController(
     CreateProductCommandHandler createProductCommandHandler,
     DeleteProductCommandHandler deleteProductCommandHandler,
     GetAllProductQueryHandler getAllProductQueryHandler,
     GetByIdProductQueryHandler getByIdProductQueryHandler)
 {
     _createProductCommandHandler = createProductCommandHandler;
     _deleteProductCommandHandler = deleteProductCommandHandler;
     _getAllProductQueryHandler   = getAllProductQueryHandler;
     _getByIdProductQueryHandler  = getByIdProductQueryHandler;
 }
Ejemplo n.º 3
0
        public async Task Handle_GivenNotExistProductId_ThrowNotFoundExceptionAsync()
        {
            var command = new DeleteProductCommandHandler(_context);

            var notExistProduct = new DeleteProductCommand()
            {
                Id = 12
            };

            await Assert.ThrowsAsync <NotFoundException>(async() => await command.Handle(notExistProduct, CancellationToken.None));
        }
Ejemplo n.º 4
0
        public DeleteProductCommandHandlerTests()
        {
            _mediatoR = new Mock <IMediator>();

            var mockedProductRepository = new Mock <IProductRepository>();

            _mockUnitOfWork = new Mock <IUnitOfWork>();
            _mockUnitOfWork.Setup(x => x.ProductRepository).Returns(mockedProductRepository.Object);

            _deleteProductCommandHandler = new DeleteProductCommandHandler(_mockUnitOfWork.Object, _mediatoR.Object);
        }
Ejemplo n.º 5
0
        public async Task Handle_GivenExistProductId_SholudBeWithOutExceptionAsync()
        {
            var command = new DeleteProductCommandHandler(_context);

            var existProduct = new DeleteProductCommand()
            {
                Id = 1
            };

            var result = await command.Handle(existProduct, CancellationToken.None);

            Assert.IsType <Unit>(result);
        }
 public ProductController(ILogger <ProductController> logger,
                          CreateProductCommandHandler createProductCommandHandler,
                          DeleteProductCommandHandler deleteProductCommandHandler,
                          GetAllProductQueryHandler getAllProductQueryHandler,
                          GetByIdProductQueryHandler getByIdProductQueryHandler
                          )
 {
     _logger = logger;
     _createProductCommandHandler = createProductCommandHandler;
     _deleteProductCommandHandler = deleteProductCommandHandler;
     _getAllProductQueryHandler   = getAllProductQueryHandler;
     _getByIdProductQueryHandler  = getByIdProductQueryHandler;
 }
Ejemplo n.º 7
0
        public async void DeleteProductCommand_DeletesProduct()
        {
            // Arrange
            var createProduct = _fixture.Build <CreateProductCommand>().Create();
            var productId     =
                await new CreateProductCommandHandler(_petShopContext).Handle(createProduct, CancellationToken.None);

            // Act
            var mockHandler = new DeleteProductCommandHandler(_petShopContext);
            var result      = await mockHandler.Handle(
                new DeleteProductCommand { Id = productId }, CancellationToken.None);

            // Assert
            var productsCount  = _petShopContext.Products.Count(c => c.DeletedDateUtc == null);
            var deletedProduct = await _petShopContext.Products.FindAsync(productId);

            Assert.True(result);
            Assert.Equal(0, productsCount);
            Assert.NotNull(deletedProduct.DeletedDateUtc);
        }
Ejemplo n.º 8
0
        public async Task DeleteAsync()
        {
            var dataAccess = new ProductDataAccess(this.Context, Mapper());
            //Act
            var sutCreate    = new CreateProductCommandHandler(dataAccess);
            var resultCreate = await sutCreate.Handle(new CreateProductCommand
            {
                Data = ProductTestData.ProductDTO
            }, CancellationToken.None);


            //Act
            var sutDelete     = new DeleteProductCommandHandler(dataAccess);
            var outcomeDelete = await sutDelete.Handle(new DeleteProductCommand
            {
                Id = resultCreate.Data.Id
            }, CancellationToken.None);

            //Assert
            Assert.IsTrue(outcomeDelete.Succeeded);
        }