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()); }
public void Create_StepVariable_Should_Throw_With_Invalid_Batch_Id() { // Arrange batchRepository.DoesBatchExist(Arg.Any <string>()) .Returns(false); var request = new CreateStepVariableRequest { BatchId = TestBatchId }; // Act / Assert var exception = Assert.ThrowsAsync <HttpError>(() => Sut.Post(request)); exception.ErrorCode.Should().Be(HttpStatusCode.NotFound.ToString()); exception.Message.Should().Be("Batch TestBatch not found"); }
public void Create_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 CreateStepVariableRequest { StepName = TestStepName }; // Act / Assert var exception = Assert.ThrowsAsync <HttpError>(() => Sut.Post(request)); exception.ErrorCode.Should().Be(HttpStatusCode.NotFound.ToString()); exception.Message.Should().Be("Step TestStep not found"); }
public void Create_StepVariable_Should_Throw_With_Existing_Variable_Id() { // Arrange batchRepository.DoesBatchExist(Arg.Any <string>()) .Returns(true); stepRepository.Get(Arg.Any <string>(), Arg.Any <string>()).Returns(new Step()); stepRepository.DoesStepVariableExist(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>()) .Returns(true); var request = new CreateStepVariableRequest { VariableName = TestStepVariableName }; // Act / Assert var exception = Assert.ThrowsAsync <HttpError>(() => Sut.Post(request)); exception.ErrorCode.Should().Be(HttpStatusCode.Conflict.ToString()); exception.Message.Should().Be("Step Variable TestStepVariable already exists"); }