public async Task CanGetExportDataFailure(string message) { var customHeaders = new HeaderDictionary(); var scheduleRequest = new ScheduleJobRequest { Url = "some url", Filename = "dummy" }; var ms = new MemoryStream(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(scheduleRequest))); var fileStreamResult = new FileStreamResult(ms, ContentTypeConstants.ApplicationJson); var context = GetMockHangfireContext(typeof(ExportJobTests), TestContext.TestName, message); var exception = new Exception(message); Mock <IApiClient> apiClient = new Mock <IApiClient>(); apiClient.Setup(a => a.SendRequest <CompactionExportResult>(It.IsAny <ScheduleJobRequest>(), customHeaders)).Throws(exception); Mock <ITransferProxy> transferProxy = new Mock <ITransferProxy>(); transferProxy.Setup(t => t.Upload(It.IsAny <Stream>(), It.IsAny <string>())).Verifiable(); transferProxy.Setup(t => t.Download(It.IsAny <string>())).Returns(() => Task.FromResult(fileStreamResult)); Mock <ITransferProxyFactory> transferProxyFactory = new Mock <ITransferProxyFactory>(); transferProxyFactory.Setup(x => x.NewProxy(It.IsAny <TransferProxyType>())).Returns(transferProxy.Object); Mock <Logging.ILoggerFactory> logger = new Mock <Logging.ILoggerFactory>(); var exportJob = new ExportJob(apiClient.Object, transferProxyFactory.Object, logger.Object); await Assert.ThrowsExceptionAsync <Exception>(() => exportJob.GetExportData(Guid.NewGuid(), customHeaders, context)); ms.Dispose(); }
public void CanGetExportDataSuccess(string message) { var customHeaders = new HeaderDictionary(); var scheduleRequest = new ScheduleJobRequest { Url = "some url", Filename = "dummy" }; var context = GetMockHangfireContext(typeof(ExportJobTests), TestContext.TestName, message); Mock <IApiClient> apiClient = new Mock <IApiClient>(); apiClient.Setup(a => a.SendRequest <CompactionExportResult>(scheduleRequest, customHeaders)).ReturnsAsync(new CompactionExportResult()); Mock <ITransferProxy> transferProxy = new Mock <ITransferProxy>(); transferProxy.Setup(t => t.Upload(It.IsAny <Stream>(), It.IsAny <string>())).Verifiable(); Mock <ITransferProxyFactory> transferProxyFactory = new Mock <ITransferProxyFactory>(); transferProxyFactory.Setup(x => x.NewProxy(It.IsAny <TransferProxyType>())).Returns(transferProxy.Object); Mock <Logging.ILoggerFactory> logger = new Mock <Logging.ILoggerFactory>(); var exportJob = new ExportJob(apiClient.Object, transferProxyFactory.Object, logger.Object); var result = exportJob.GetExportData(Guid.NewGuid(), customHeaders, context); }