public async Task It_Should_Create_CommandOption() { // 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.DoesCommandOptionExist(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>()) .Returns(false); var request = CreateCommandOptions.Debug; request.BatchId = TestBatchId; request.StepName = TestStepName; request.CommandName = TestCommandName; // Act var response = await Sut.Post(request); // Assert response.Should().NotBeNull(); await commandRepository.Received().CreateOrUpdateCommandOption(Arg.Is <CommandOption>(a => a.CommandId == 123 && a.Name == request.OptionName && a.Description == request.Description)); }
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()); }