public async Task It_Should_Create_StepOption() { // Arrange batchRepository.DoesBatchExist(Arg.Any <string>()) .Returns(true); stepRepository.Get(Arg.Any <string>(), Arg.Any <string>()).Returns(new Step { Id = 123 }); stepRepository.DoesStepOptionExist(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>()) .Returns(false); var request = CreateStepOptions.BuildAlways; request.BatchId = TestBatchId; request.StepName = TestStepName; // Act var response = await Sut.Post(request); // Assert response.Should().NotBeNull(); await stepRepository.Received().CreateOrUpdateStepOption(Arg.Is <StepOption>(a => a.StepId == 123 && a.Name == request.OptionName && a.Description == request.Description)); }
public async Task <CreateStepOptionResponse> Post(CreateStepOptionRequest 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 stepRepository.DoesStepOptionExist(request.BatchId, request.StepName, request.OptionName)) { throw Err.StepOptionAlreadyExists(request.OptionName); } var stepOption = request.ConvertTo <StepOption>(); stepOption.StepId = step.Id; await stepRepository.CreateOrUpdateStepOption(stepOption); return(new CreateStepOptionResponse()); }