public async Task <CreateCommandVariableResponse> Post(CreateCommandVariableRequest 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 command = await commandRepository.Get(step.Id, request.CommandName); if (command == null) { throw Err.CommandNotFound(request.CommandName); } if (await commandRepository.DoesCommandVariableExist(request.BatchId, request.StepName, request.CommandName, request.VariableName)) { throw Err.CommandVariableAlreadyExists(request.VariableName); } var commandVariable = request.ConvertTo <CommandVariable>(); commandVariable.CommandId = command.Id; await commandRepository.CreateOrUpdateCommandVariable(commandVariable); return(new CreateCommandVariableResponse()); }
public async Task It_Should_Get_Step() { // Arrange batchRepository.DoesBatchExist(Arg.Any <string>()) .Returns(true); var step = TestData.Entities.Steps.Build; step.BatchId = TestStepName; stepRepository.Get(Arg.Any <string>(), Arg.Any <string>()).Returns(step); var request = new GetStepRequest { BatchId = TestBatchId, StepName = TestStepName }; // Act var response = await Sut.Get(request); // Assert response.Should().BeEquivalentTo(TestData.DomainModels.Steps.Build, o => o.ExcludingMissingMembers()); response.StepName.Should().Be(TestData.DomainModels.Steps.Build.Name); }
public async Task <CreateStepArtifactResponse> Post(CreateStepArtifactRequest 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.DoesStepArtifactExist(request.BatchId, request.StepName, request.ArtifactName)) { throw Err.StepArtifactAlreadyExists(request.ArtifactName); } var stepArtifact = request.ConvertTo <StepArtifact>(); stepArtifact.StepId = step.Id; await stepRepository.CreateStepArtifact(stepArtifact); return(new CreateStepArtifactResponse()); }
public async Task <CreateStepOptionResponse> Post(CreateStepOptionRequest 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.DoesStepOptionExist(request.BatchId, request.StepName, request.OptionName)) { throw Err.StepOptionAlreadyExists(request.OptionName); } var stepOption = request.ConvertTo <StepOption>(); stepOption.StepId = step.Id; await stepRepository.CreateOrUpdateStepOption(stepOption); return(new CreateStepOptionResponse()); }
public async Task <CreateCommandResponse> Post(CreateCommandRequest 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 commandRepository.DoesCommandExist(request.BatchId, request.StepName, request.CommandName)) { throw Err.CommandAlreadyExists(request.CommandName); } var command = request.ConvertTo <Core.Entities.Command>(); command.StepId = step.Id; await commandRepository.Create(command); return(new CreateCommandResponse()); }
public async Task <GetStepResponse> Get(GetStepRequest 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); } return(step.ConvertTo <GetStepResponse>()); }
public async Task It_Should_Create_CommandVariable() { // Arrange batchRepository.DoesBatchExist(Arg.Any <string>()) .Returns(true); stepRepository.Get(Arg.Any <string>(), Arg.Any <string>()).Returns(new Step()); commandRepository.Get(Arg.Any <ulong>(), Arg.Any <string>()).Returns(new Command { Id = 123 }); commandRepository.DoesCommandVariableExist(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>()) .Returns(false); var request = CreateCommandVariables.Extract; request.BatchId = TestBatchId; request.StepName = TestStepName; request.CommandName = TestCommandName; // Act var response = await Sut.Post(request); // Assert response.Should().NotBeNull(); await commandRepository.Received().CreateOrUpdateCommandVariable(Arg.Is <CommandVariable>(a => a.CommandId == 123 && a.Name == request.VariableName && a.Description == request.Description)); }
public async Task It_Should_Create_StepOption() { // Arrange batchRepository.DoesBatchExist(Arg.Any <string>()) .Returns(true); stepRepository.Get(Arg.Any <string>(), Arg.Any <string>()).Returns(new Step { Id = 123 }); stepRepository.DoesStepOptionExist(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>()) .Returns(false); var request = CreateStepOptions.BuildAlways; request.BatchId = TestBatchId; request.StepName = TestStepName; // Act var response = await Sut.Post(request); // Assert response.Should().NotBeNull(); await stepRepository.Received().CreateOrUpdateStepOption(Arg.Is <StepOption>(a => a.StepId == 123 && a.Name == request.OptionName && a.Description == request.Description)); }
public async Task It_Should_Create_Command() { // Arrange batchRepository.DoesBatchExist(Arg.Any <string>()) .Returns(true); stepRepository.Get(Arg.Any <string>(), Arg.Any <string>()) .Returns(new Step { Id = 123 }); commandRepository.DoesCommandExist(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>()) .Returns(false); var request = CreateCommands.Test; request.BatchId = TestBatchId; // Act var response = await Sut.Post(request); // Assert response.Should().NotBeNull(); await commandRepository.Received().Create(Arg.Is <Command>(a => a.StepId == 123 && a.Name == request.CommandName && a.Description == request.Description && a.Options.Count == request.Options.Count && a.Variables.Count == request.Variables.Count)); }