Ejemplo n.º 1
0
        public async Task It_Should_Create_StepVariable()
        {
            // Arrange
            batchRepository.DoesBatchExist(Arg.Any <string>())
            .Returns(true);

            stepRepository.Get(Arg.Any <string>(), Arg.Any <string>()).Returns(new Step
            {
                Id = 123
            });

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

            var request = CreateStepVariables.Profile;

            request.BatchId  = TestBatchId;
            request.StepName = TestStepName;

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

            // Assert
            response.Should().NotBeNull();
            await stepRepository.Received().CreateOrUpdateStepVariable(Arg.Is <StepVariable>(a =>
                                                                                             a.StepId == 123 &&
                                                                                             a.Name == request.VariableName &&
                                                                                             a.Description == request.Description));
        }
Ejemplo n.º 2
0
        public async Task <CreateStepVariableResponse> Post(CreateStepVariableRequest 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);
            }

            if (await stepRepository.DoesStepVariableExist(request.BatchId, request.StepName, request.VariableName))
            {
                throw Err.StepVariableAlreadyExists(request.VariableName);
            }

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

            stepVariable.StepId = step.Id;

            await stepRepository.CreateOrUpdateStepVariable(stepVariable);

            return(new CreateStepVariableResponse());
        }