Exemplo n.º 1
0
        public async Task <CreateBatchArtifactOptionResponse> Post(CreateBatchArtifactOptionRequest request)
        {
            if (!await batchRepository.DoesBatchExist(request.BatchId))
            {
                throw Err.BatchNotFound(request.BatchId);
            }

            var batchArtifact = await batchRepository.GetBatchArtifact(request.BatchId, request.ArtifactName);

            if (batchArtifact == null)
            {
                throw Err.BatchArtifactNotFound(request.ArtifactName);
            }

            if (await batchRepository.DoesBatchArtifactOptionExist(request.BatchId, request.ArtifactName, request.OptionName))
            {
                throw Err.BatchArtifactOptionAlreadyExists(request.OptionName);
            }

            var batchArtifactOption = request.ConvertTo <BatchArtifactOption>();

            batchArtifactOption.BatchArtifactId = batchArtifact.Id;

            await batchRepository.CreateOrUpdateBatchArtifactOption(batchArtifactOption);

            return(new CreateBatchArtifactOptionResponse());
        }
Exemplo n.º 2
0
        public void Create_Batch_Artifact_Option_Should_Throw_With_Invalid_Batch_Id()
        {
            // Arrange
            batchRepository.DoesBatchExist(Arg.Any <string>())
            .Returns(false);

            var request = new CreateBatchArtifactOptionRequest
            {
                BatchId = TestBatchId
            };

            // Assert
            var exception = Assert.ThrowsAsync <HttpError>(() => Sut.Post(request));

            exception.ErrorCode.Should().Be(HttpStatusCode.NotFound.ToString());
            exception.Message.Should().Be("Batch TestBatch not found");
        }
Exemplo n.º 3
0
        public void Create_Batch_Artifact_Option_Should_Throw_With_Existing_Batch_Artifact_Option_Id()
        {
            // Arrange
            batchRepository.DoesBatchExist(Arg.Any <string>())
            .Returns(true);

            batchRepository.GetBatchArtifact(Arg.Any <string>(), Arg.Any <string>())
            .Returns(new BatchArtifact());

            batchRepository.DoesBatchArtifactOptionExist(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>())
            .Returns(true);

            var request = new CreateBatchArtifactOptionRequest
            {
                OptionName = TestBatchArtifactOptionName
            };

            // Assert
            var exception = Assert.ThrowsAsync <HttpError>(() => Sut.Post(request));

            exception.ErrorCode.Should().Be(HttpStatusCode.Conflict.ToString());
            exception.Message.Should().Be("Batch Artifact Option TestBatchArtifactOption already exists");
        }