コード例 #1
0
        public async Task It_Should_Create_StepArtifact_Option()
        {
            // Arrange
            batchRepository.DoesBatchExist(Arg.Any <string>())
            .Returns(true);

            stepRepository.Get(Arg.Any <string>(), Arg.Any <string>()).Returns(new Step());

            stepRepository.GetStepArtifact(Arg.Any <ulong>(), Arg.Any <string>()).Returns(new StepArtifact
            {
                Id = 123
            });

            stepRepository.DoesStepArtifactOptionExist(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>())
            .Returns(false);

            var request = CreateStepArtifactOptions.Compress;

            // Act
            var response = await Sut.Post(request);

            // Assert
            response.Should().NotBeNull();
            await stepRepository.Received().CreateOrUpdateStepArtifactOption(Arg.Is <StepArtifactOption>(a =>
                                                                                                         a.StepArtifactId == 123 &&
                                                                                                         a.Name == request.OptionName &&
                                                                                                         a.Description == request.Description));
        }
コード例 #2
0
        public async Task <CreateStepArtifactOptionResponse> Post(CreateStepArtifactOptionRequest request)
        {
            if (!await batchRepository.DoesBatchExist(request.BatchId))
            {
                throw Err.BatchNotFound(request.BatchId);
            }

            var step = await stepRepository.Get(request.BatchId, request.StepName);

            if (step == null)
            {
                throw Err.StepNotFound(request.StepName);
            }

            var existingStepArtifact =
                await stepRepository.GetStepArtifact(step.Id, request.ArtifactName);

            if (existingStepArtifact == null)
            {
                throw Err.StepArtifactNotFound(request.ArtifactName);
            }

            if (await stepRepository.DoesStepArtifactOptionExist(request.BatchId, request.StepName, request.ArtifactName, request.OptionName))
            {
                throw Err.StepArtifactOptionAlreadyExists(request.OptionName);
            }

            var stepArtifactOption = request.ConvertTo <StepArtifactOption>();

            stepArtifactOption.StepArtifactId = existingStepArtifact.Id;

            await stepRepository.CreateOrUpdateStepArtifactOption(stepArtifactOption);

            return(new CreateStepArtifactOptionResponse());
        }