コード例 #1
0
        public async Task DeleteProductCommandHandlerAsync_WithNullParameter_ThrowsException()
        {
            //Arrange
            DeleteProductCommandRequest command = null;

            //Act
            var actualException = await Assert.ThrowsAsync <Exception>(() => _deleteProductCommandHandler.Handle(command, new CancellationToken()));

            //Assert
            Assert.Equal(MessageConstants.DeleteProductCommandRequestNull, actualException.Message);
        }
コード例 #2
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));
        }
コード例 #3
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);
        }
コード例 #4
0
        public async Task DeleteProductCommandHandler_Success()
        {
            //Arrange
            productRepository.Setup(x => x.GetById(productId)).Returns(Task.FromResult(product));
            productRepository.Setup(x => x.SaveAllAsync()).Returns(Task.FromResult(true));

            //Act
            var action = await commandHandler.Handle(command, It.IsAny <CancellationToken>());

            //Assert
            Assert.Equal(Unit.Value, action);
            productRepository.Verify(x => x.Delete(product), Times.Once);
            bus.Verify(x => x.Publish(It.IsAny <ProductDeletedEvent>(), It.IsAny <CancellationToken>()), Times.Once);
        }
コード例 #5
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);
        }
コード例 #6
0
ファイル: TestProductCore.cs プロジェクト: MorneVenter/.NET
        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);
        }