Beispiel #1
0
        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));
        }
Beispiel #2
0
        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());
        }