public async Task <CommandResponseDto> UpdateProductOption(UpdateProductOptionCommand command)
        {
            try
            {
                await _mediator.Send(command);
            }
            catch (Exception ex)
            {
                return(CommandResponseDto.Fail(GetErrorMessage(ex)));
            }

            return(CommandResponseDto.Success);
        }
        public async Task CreateProductOptionShouldReturnErrorWhenFail()
        {
            // Arrange
            _productOptionService.Setup(x => x.CreateProductOption(It.IsAny <CreateProductOptionCommand>())).ReturnsAsync(CommandResponseDto.Fail("Error message!"));

            var controller = new ProductOptionsController(_productOptionService.Object);

            // Act
            var response = await controller.CreateOption(Guid.NewGuid(), new ProductOptionRequestDto());

            // Assert
            Assert.IsInstanceOfType(response, typeof(BadRequestErrorMessageResult));
            Assert.AreEqual(((BadRequestErrorMessageResult)response).Message, "Error message!");
        }
Esempio n. 3
0
        public async Task UpdateProductShouldReturnErrorWhenFail()
        {
            // Arrange
            _productInterface.Setup(x => x.UpdateProduct(It.IsAny <UpdateProductCommand>())).ReturnsAsync(CommandResponseDto.Fail("Error update message!"));

            var controller = new ProductsController(_productInterface.Object);

            // Act
            var response = await controller.Update(Guid.NewGuid(), new Business.Dtos.Product.Request.ProductRequestDto());

            // Assert
            Assert.IsInstanceOfType(response, typeof(BadRequestErrorMessageResult));
            Assert.AreEqual(((BadRequestErrorMessageResult)response).Message, "Error update message!");
        }