public async Task It_Should_Create_StepArtifact() { // Arrange batchRepository.DoesBatchExist(Arg.Any <string>()) .Returns(true); stepRepository.Get(Arg.Any <string>(), Arg.Any <string>()).Returns(new Step { Id = 123 }); stepRepository.DoesStepArtifactExist(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>()) .Returns(false); var request = CreateStepArtifacts.Binaries; request.BatchId = TestBatchId; request.StepName = TestStepName; // Act var response = await Sut.Post(request); // Assert response.Should().NotBeNull(); await stepRepository.Received().CreateStepArtifact(Arg.Is <StepArtifact>(a => a.StepId == 123 && a.Name == request.ArtifactName && a.Description == request.Description && a.Options.Count == request.Options.Count)); }
public async Task <CreateStepArtifactResponse> Post(CreateStepArtifactRequest 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.DoesStepArtifactExist(request.BatchId, request.StepName, request.ArtifactName)) { throw Err.StepArtifactAlreadyExists(request.ArtifactName); } var stepArtifact = request.ConvertTo <StepArtifact>(); stepArtifact.StepId = step.Id; await stepRepository.CreateStepArtifact(stepArtifact); return(new CreateStepArtifactResponse()); }