public async Task <DeleteCommandOptionResponse> Delete(DeleteCommandOptionRequest 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);
            }

            var existingCommandOption =
                await commandRepository.GetCommandOption(command.Id, request.OptionName);

            if (existingCommandOption == null)
            {
                throw Err.CommandOptionNotFound(request.OptionName);
            }

            await commandRepository.DeleteCommandOption(existingCommandOption.Id);

            return(new DeleteCommandOptionResponse());
        }
Exemple #2
0
        public void Delete_Command_Option_Should_Throw_With_Invalid_Command_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.GetCommandOption(Arg.Any <ulong>(), Arg.Any <string>())
            .ReturnsNull();

            var request = new DeleteCommandOptionRequest
            {
                OptionName = TestCommandOptionName
            };

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

            exception.ErrorCode.Should().Be(HttpStatusCode.NotFound.ToString());
            exception.Message.Should().Be("Command Option TestCommandOption not found");
        }
Exemple #3
0
        public async Task It_Should_Delete_Command_Option()
        {
            // 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());

            var existingCommandOption = new CommandOption
            {
                Id = 123
            };

            commandRepository.GetCommandOption(Arg.Any <ulong>(), Arg.Any <string>())
            .Returns(existingCommandOption);

            var request = new DeleteCommandOptionRequest();

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

            // Assert
            response.Should().NotBeNull();
            await commandRepository.Received().DeleteCommandOption(Arg.Is <ulong>(a =>
                                                                                  a == existingCommandOption.Id));
        }
Exemple #4
0
        public void Delete_Command_Option_Should_Throw_With_Invalid_Batch_Id()
        {
            // Arrange
            batchRepository.DoesBatchExist(Arg.Any <string>())
            .Returns(false);

            var request = new DeleteCommandOptionRequest
            {
                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");
        }