public void Delete_Command_Variable_Should_Throw_With_Invalid_Command_Variable_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.GetCommandVariable(Arg.Any <ulong>(), Arg.Any <string>())
            .ReturnsNull();

            var request = new DeleteCommandVariableRequest
            {
                VariableName = TestCommandVariableName
            };

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

            exception.ErrorCode.Should().Be(HttpStatusCode.NotFound.ToString());
            exception.Message.Should().Be("Command Variable TestCommandVariable not found");
        }
        public async Task It_Should_Delete_Command_Variable()
        {
            // 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 existingCommandVariable = new CommandVariable
            {
                Id = 123
            };

            commandRepository.GetCommandVariable(Arg.Any <ulong>(), Arg.Any <string>())
            .Returns(existingCommandVariable);

            var request = new DeleteCommandVariableRequest();

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

            // Assert
            response.Should().NotBeNull();
            await commandRepository.Received().DeleteCommandVariable(Arg.Is <ulong>(a =>
                                                                                    a == existingCommandVariable.Id));
        }
        public async Task <DeleteCommandVariableResponse> Delete(DeleteCommandVariableRequest 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 existingCommandVariable =
                await commandRepository.GetCommandVariable(command.Id, request.VariableName);

            if (existingCommandVariable == null)
            {
                throw Err.CommandVariableNotFound(request.VariableName);
            }

            await commandRepository.DeleteCommandVariable(existingCommandVariable.Id);

            return(new DeleteCommandVariableResponse());
        }
        public void Delete_Command_Variable_Should_Throw_With_Invalid_Batch_Id()
        {
            // Arrange
            batchRepository.DoesBatchExist(Arg.Any <string>())
            .Returns(false);

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