public void Create_BatchOption_Should_Throw_With_Invalid_Batch_Id() { // Arrange batchRepository.DoesBatchExist(Arg.Any <string>()) .Returns(false); var request = new CreateBatchOptionRequest { BatchId = TestBatchId }; // Act / Assert var exception = Assert.ThrowsAsync <HttpError>(() => Sut.Post(request)); exception.ErrorCode.Should().Be(HttpStatusCode.NotFound.ToString()); exception.Message.Should().Be("Batch TestBatch not found"); }
public async Task <CreateBatchOptionResponse> Post(CreateBatchOptionRequest request) { if (!await batchRepository.DoesBatchExist(request.BatchId)) { throw Err.BatchNotFound(request.BatchId); } if (await batchRepository.DoesBatchOptionExist(request.BatchId, request.OptionName)) { throw Err.BatchOptionAlreadyExists(request.OptionName); } var batchOption = request.ConvertTo <BatchOption>(); await batchRepository.CreateOrUpdateBatchOption(batchOption); return(new CreateBatchOptionResponse()); }
public void Create_BatchOption_Should_Throw_With_Existing_Option_Name() { // Arrange batchRepository.DoesBatchExist(Arg.Any <string>()) .Returns(true); batchRepository.DoesBatchOptionExist(Arg.Any <string>(), Arg.Any <string>()) .Returns(true); var request = new CreateBatchOptionRequest { OptionName = TestBatchOptionName }; // Act / Assert var exception = Assert.ThrowsAsync <HttpError>(() => Sut.Post(request)); exception.ErrorCode.Should().Be(HttpStatusCode.Conflict.ToString()); exception.Message.Should().Be("Batch Option TestBatchOption already exists"); }