Exemplo n.º 1
0
        public async Task CreateMaterialManufacturingAsync_ShouldReturn_EntityNotFound_When_SmartContractNotFound()
        {
            // arrange
            var command = new CreateMaterialManufacturingCommand();

            _blockchainRepositoryMock.Setup(
                x => x.GetSmartContractByTypeAsync(
                    It.IsAny <string>(),
                    It.IsAny <CancellationToken>()))
            .ReturnsAsync((SmartContract)null);

            // act
            var result = await _sub
                         .CreateMaterialManufacturingAsync(command, CancellationToken.None);

            // assert
            result.Should().NotBeNull();
            result.Should().BeOfType <OneOf <MaterialManufacturingResponseModel, EntityNotFound> >();
            result.IsT1.Should().BeTrue();
        }
Exemplo n.º 2
0
        public async Task <IActionResult> AddMaterialManufacturing(
            [FromBody] CreateMaterialManufacturingCommand command,
            CancellationToken cancellationToken)
        {
            var validationResult = await new CreateMaterialManufacturingCommandValidator()
                                   .ValidateAsync(command, cancellationToken);

            if (!validationResult.IsValid)
            {
                var error = new ErrorResponseModel(
                    validationResult.ToString(","),
                    nameof(EntityNotValid));
                return(BadRequest(error));
            }

            var result = await _materialManufacturingService
                         .CreateMaterialManufacturingAsync(command, cancellationToken);

            return(result.Match <IActionResult>(
                       entity
                       => Created($"api/v1.0/material-manufacturing/{entity.Id}", entity),
                       notFound => BadRequest(new ErrorResponseModel(notFound.Message, nameof(EntityNotFound)))
                       ));
        }