public async Task <CreateCommandOptionResponse> Post(CreateCommandOptionRequest 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.DoesCommandOptionExist(request.BatchId, request.StepName, request.CommandName, request.OptionName))
            {
                throw Err.CommandOptionAlreadyExists(request.OptionName);
            }

            var commandOption = request.ConvertTo <CommandOption>();

            commandOption.CommandId = command.Id;

            await commandRepository.CreateOrUpdateCommandOption(commandOption);

            return(new CreateCommandOptionResponse());
        }
Exemple #2
0
        public void Create_CommandOption_Should_Throw_With_Existing_Option_Id()
        {
            // 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());

            commandRepository.DoesCommandOptionExist(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>())
            .Returns(true);

            var request = new CreateCommandOptionRequest
            {
                OptionName = TestCommandOptionName
            };

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

            exception.ErrorCode.Should().Be(HttpStatusCode.Conflict.ToString());
            exception.Message.Should().Be("Command Option TestCommandOption already exists");
        }
Exemple #3
0
        public void Create_CommandOption_Should_Throw_With_Invalid_Batch_Id()
        {
            // Arrange
            batchRepository.DoesBatchExist(Arg.Any <string>())
            .Returns(false);

            var request = new CreateCommandOptionRequest
            {
                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");
        }
Exemple #4
0
        public void Create_CommandOption_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 CreateCommandOptionRequest
            {
                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");
        }