public async Task Create_ShallReturnAJob()
        {
            var mockClient = new Mock <IJobsClient>();
            var mockLogger = new Mock <ILogger <ClaraJobsApi> >();

            JobId.TryParse("jobid", out JobId jobId);
            PayloadId.TryParse("payloadid", out PayloadId payloadId);
            PipelineId.TryParse("pipelineid", out PipelineId pipelineId);

            mockClient.Setup(p => p.CreateJob(It.IsAny <PipelineId>(), It.IsAny <string>(), It.IsAny <JobPriority>()))
            .ReturnsAsync(new JobInfo
            {
                Name       = "bla bla job",
                JobId      = jobId,
                PayloadId  = payloadId,
                PipelineId = pipelineId
            });

            var service = new ClaraJobsApi(
                mockClient.Object, mockLogger.Object);

            var job = await service.Create(Guid.NewGuid().ToString(), "bla bla", JobPriority.Higher);

            Assert.Equal(jobId.ToString(), job.JobId);
            Assert.Equal(payloadId.ToString(), job.PayloadId);

            mockClient.Verify(
                p => p.CreateJob(It.IsAny <PipelineId>(), It.IsAny <string>(), JobPriority.Higher),
                Times.Exactly(1));

            mockLogger.VerifyLogging(LogLevel.Information, Times.Once());
            mockLogger.VerifyLogging(LogLevel.Error, Times.Never());
        }
        public void Create_ShallThrowOnBadPipelineId()
        {
            var mockClient = new Mock <IJobsClient>();
            var mockLogger = new Mock <ILogger <ClaraJobsApi> >();

            mockClient.Setup(p => p.CreateJob(It.IsAny <PipelineId>(), It.IsAny <string>()));

            var service = new ClaraJobsApi(mockClient.Object, mockLogger.Object);

            var exception = Assert.Throws <AggregateException>(() =>
            {
                service.Create("bad pipeline id", "bla bla", JobPriority.Higher).Wait();
            });

            Assert.IsType <ConfigurationException>(exception.InnerException);
            mockClient.Verify(
                p => p.CreateJob(It.IsAny <PipelineId>(), It.IsAny <string>(), JobPriority.Higher),
                Times.Never());

            mockLogger.VerifyLogging(LogLevel.Error, Times.Exactly(3));
        }
        public void Create_ShallRespectRetryPolicyOnFailure()
        {
            var mockClient = new Mock <IJobsClient>();
            var mockLogger = new Mock <ILogger <ClaraJobsApi> >();

            mockClient.Setup(p => p.CreateJob(It.IsAny <PipelineId>(), It.IsAny <string>(), It.IsAny <JobPriority>()))
            .Throws(new RpcException(Status.DefaultCancelled));

            var service = new ClaraJobsApi(mockClient.Object, mockLogger.Object);

            var exception = Assert.Throws <AggregateException>(() =>
            {
                service.Create("valid-pipeline-id", "bla bla", JobPriority.Lower).Wait();
            });

            Assert.IsType <RpcException>(exception.InnerException);
            mockClient.Verify(
                p => p.CreateJob(It.IsAny <PipelineId>(), It.IsAny <string>(), JobPriority.Lower),
                Times.Exactly(4));

            mockLogger.VerifyLogging(LogLevel.Error, Times.Exactly(3));
        }