Beispiel #1
0
        public async Task <UpdateStepVariableResponse> Put(UpdateStepVariableRequest 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 existingStepVariable =
                await stepRepository.GetStepVariable(step.Id, request.VariableName);

            if (existingStepVariable == null)
            {
                throw Err.StepVariableNotFound(request.VariableName);
            }

            var stepVariable = request.ConvertTo <StepVariable>();

            stepVariable.Id     = existingStepVariable.Id;
            stepVariable.StepId = step.Id;

            await stepRepository.CreateOrUpdateStepVariable(stepVariable);

            return(new UpdateStepVariableResponse());
        }
        public void Update_StepVariable_Should_Throw_With_Invalid_Batch_Id()
        {
            // Arrange
            batchRepository.DoesBatchExist(Arg.Any <string>())
            .Returns(false);

            var request = new UpdateStepVariableRequest
            {
                BatchId = TestBatchId
            };

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

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

            stepRepository.Get(Arg.Any <string>(), Arg.Any <string>()).ReturnsNull();

            var request = new UpdateStepVariableRequest
            {
                StepName = TestStepName
            };

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

            exception.ErrorCode.Should().Be(HttpStatusCode.NotFound.ToString());
            exception.Message.Should().Be("Step TestStep not found");
        }