public async Task <DeleteStepVariableResponse> Delete(DeleteStepVariableRequest 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); } await stepRepository.DeleteStepVariable(existingStepVariable.Id); return(new DeleteStepVariableResponse()); }
public async Task It_Should_Delete_Step_Variable() { // Arrange batchRepository.DoesBatchExist(Arg.Any <string>()) .Returns(true); stepRepository.Get(Arg.Any <string>(), Arg.Any <string>()) .Returns(new Step()); var existingStepVariable = new StepVariable { Id = 123 }; stepRepository.GetStepVariable(Arg.Any <ulong>(), Arg.Any <string>()) .Returns(existingStepVariable); var request = new DeleteStepVariableRequest(); // Act var response = await Sut.Delete(request); // Assert response.Should().NotBeNull(); await stepRepository.Received().DeleteStepVariable(Arg.Is <ulong>(a => a == existingStepVariable.Id)); }
public void Delete_Step_Variable_Should_Throw_With_Invalid_Batch_Id() { // Arrange batchRepository.DoesBatchExist(Arg.Any <string>()) .Returns(false); var request = new DeleteStepVariableRequest { BatchId = TestBatchId }; // Act / Assert var exception = Assert.ThrowsAsync <HttpError>(() => Sut.Delete(request)); exception.ErrorCode.Should().Be(HttpStatusCode.NotFound.ToString()); exception.Message.Should().Be("Batch TestBatch not found"); }
public void Delete_Step_Variable_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 DeleteStepVariableRequest { StepName = TestStepName }; // Act / Assert var exception = Assert.ThrowsAsync <HttpError>(() => Sut.Delete(request)); exception.ErrorCode.Should().Be(HttpStatusCode.NotFound.ToString()); exception.Message.Should().Be("Step TestStep not found"); }