public void Then_The_Bearer_Token_Is_Not_Added_If_Local( ImporterConfiguration config) { //Arrange var configuration = new Mock <IOptions <ImporterConfiguration> >(); config.DataLoaderBaseUrlsAndIdentifierUris = "https://test.local/"; configuration.Setup(x => x.Value).Returns(config); var response = new HttpResponseMessage { Content = new StringContent(""), StatusCode = HttpStatusCode.Accepted }; var httpMessageHandler = SetupMessageHandlerMock(response, $"{config.DataLoaderBaseUrlsAndIdentifierUris}ops/dataload"); var client = new HttpClient(httpMessageHandler.Object); var service = new ImportDataService(client, configuration.Object, Mock.Of <IAzureClientCredentialHelper>(), new ImporterEnvironment("LOCAL")); //Act service.Import(); //Assert httpMessageHandler.Protected() .Verify <Task <HttpResponseMessage> >( "SendAsync", Times.Once(), ItExpr.Is <HttpRequestMessage>(c => c.Method.Equals(HttpMethod.Post) && c.RequestUri.AbsoluteUri.Equals($"{config.DataLoaderBaseUrlsAndIdentifierUris}ops/dataload") && c.Headers.Authorization == null), ItExpr.IsAny <CancellationToken>() ); }
public void StartImport() { var svc = new ImportDataService <Task>(); Assert.DoesNotThrow(() => svc.Start(null)); Assert.DoesNotThrow(() => svc.ForceWait()); }
public BaseGameController( ApplicationService applicationService, ImportDataService importDataService, ExportDataService exportDataService) { _applicationService = applicationService ?? throw new ArgumentNullException(nameof(applicationService)); _importDataService = importDataService ?? throw new ArgumentNullException(nameof(importDataService)); _exportDataService = exportDataService ?? throw new ArgumentNullException(nameof(exportDataService)); }
public void SetWorkerParamsNullAndStartImporter() { var svc = new ImportDataService <Task>(); Assert.DoesNotThrow(() => svc.PassWorkerParams(null)); Assert.DoesNotThrow(() => svc.Start(null)); Assert.DoesNotThrow(() => svc.ForceWait()); Assert.DoesNotThrow(() => svc.Stop(null)); }
public IActionResult StartSync() { try { async Task WorkItem(CancellationToken token) { var guid = Guid.NewGuid().ToString(); var svc = new ImportDataService <Task>(); try { svc.PassWorkerParams(new List <TypedParameter> { new TypedParameter(typeof(int), 50) }); svc.PassSourceParams(new List <TypedParameter> { new TypedParameter(typeof(int), 500) }); svc.Start(null); svc.ForceWait(); _logger.LogInformation($"Queued Background Task {guid} is complete. 3/3"); } catch (Exception ex) { _logger.LogCritical($"Error in Redmine import service {nameof(svc)}. Query guid is: {guid}"); _logger.LogCritical(ex.Message, ex); } //for (int delayLoop = 0; delayLoop < 3; delayLoop++) //{ // _logger.LogInformation( // $"Queued Background Task {guid} is running. {delayLoop}/3"); // await Task.Delay(TimeSpan.FromSeconds(5), token); //} // } Queue.QueueBackgroundWorkItem(WorkItem); //Repository.TryBeginSync(); return(Ok()); } catch (Exception ex) { return(StatusCode(500, new { error = ex.Message, ex = ex, displayText = "Unexpected error happened." })); } }
public void SetSourceParamsAndStartImporter() { var svc = new ImportDataService <Task>(); Assert.DoesNotThrow(() => svc.PassSourceParams(new List <TypedParameter> { new TypedParameter(typeof(int), 5) })); Assert.DoesNotThrow(() => svc.Start(null)); Assert.DoesNotThrow(() => svc.ForceWait()); Assert.DoesNotThrow(() => svc.Stop(null)); }
// GET: ImportData public Task <ActionResult> Import() { return(DoTask(_ => { var importDataWriter = new ImportDataWriter(_dbContext); var importDataReader = new ImportDataReader(_dbContext); var fileReaderService = new ImportDataService(importDataWriter); fileReaderService.PopulateCSVToEntity(); var statsCalculator = new StatsCalculatorService(importDataReader); var model = statsCalculator.CalculateStatsData(); return View("Index", model); })); }
private async Task MigrateAsync() { string currentAppDirectory = AppDomain.CurrentDomain.BaseDirectory; string jobFolderName = GetJobFolderName(); string jobFolderPath = Path.Combine(currentAppDirectory, jobFolderName); string xmlDataPath = Path.Combine(jobFolderPath, "data.xml"); string logFilePath = Path.Combine(jobFolderPath, "Logs"); MigrationStatusMessage = "Migration in process..."; string migrationError = null; await Task.Factory.StartNew(() => { try { ExportDataService exportDataService = new ExportDataService(); CreateFolderIfNotExists(jobFolderPath); CrmServiceClient sourceCrmService = GetCrmService(SelectedSourceConnection); exportDataService.ExportData(sourceCrmService, SelectedConfiguration.Name, jobFolderPath); CrmServiceClient targetCrmService = GetCrmService(SelectedTargetConnection); ImportDataService importDataService = new ImportDataService(); CreateFolderIfNotExists(logFilePath); importDataService.ImportData(targetCrmService, xmlDataPath, logFilePath, null); } catch (Exception ex) { migrationError = ex.Message; } }); if (!string.IsNullOrWhiteSpace(migrationError)) { MigrationStatusMessage = "Migration failed. Error:- " + migrationError; } else { MigrationStatusMessage = "Migration complete! Please review the Logs for any errors encountered."; Process.Start(jobFolderPath); } }
public void Then_The_Dataload_Is_Called_For_Multiple_Endpoints( string authToken, ImporterConfiguration config) { //Arrange var azureClientCredentialHelper = new Mock <IAzureClientCredentialHelper>(); azureClientCredentialHelper .Setup(x => x.GetAccessTokenAsync(It.Is <string>(c => c.StartsWith("tenant")))) .ReturnsAsync(authToken); var configuration = new Mock <IOptions <ImporterConfiguration> >(); var urls = new List <string> { "https://local.url1/|tenant1", "https://local.url2/|tenant2", "https://local.url3/|tenant3", "https://local.url4/|tenant4" }; config.DataLoaderBaseUrlsAndIdentifierUris = string.Join(",", urls); configuration.Setup(x => x.Value).Returns(config); var response = new HttpResponseMessage { Content = new StringContent(""), StatusCode = HttpStatusCode.Accepted }; var httpMessageHandler = SetupMessageHandlerMock(response, $"/ops/dataload"); var client = new HttpClient(httpMessageHandler.Object); var service = new ImportDataService(client, configuration.Object, azureClientCredentialHelper.Object, new ImporterEnvironment("TEST")); //Act service.Import(); //Assert foreach (var url in urls) { var dataUrl = url.Split("|").First(); httpMessageHandler.Protected() .Verify <Task <HttpResponseMessage> >( "SendAsync", Times.Once(), ItExpr.Is <HttpRequestMessage>(c => c.Method.Equals(HttpMethod.Post) && c.RequestUri.AbsoluteUri.Equals($"{dataUrl}ops/dataload") && c.Headers.Authorization.Scheme.Equals("Bearer") && c.Headers.FirstOrDefault(h => h.Key.Equals("X-Version")).Value.Single() == "1.0" && c.Headers.Authorization.Parameter.Equals(authToken)), ItExpr.IsAny <CancellationToken>() ); } }
//[TestMethod] public void TestImportData() { //Arrange string connectionStr = ConfigurationManager.ConnectionStrings["CRMTarget"].ConnectionString; CrmServiceClient crmServiceClient = new CrmServiceClient(connectionStr); ImportDataService importDataService = new ImportDataService(); string xmlDataPath = ConfigurationManager.AppSettings["ImportDataFile"]; string logFilePath = ConfigurationManager.AppSettings["LogFilePath"]; //Act importDataService.ImportData(crmServiceClient, xmlDataPath, logFilePath, null); //Assert // Assert.IsTrue(true); }
// POST: api/ImportData public HttpResponseMessage Post(string fileType, string fileId, string user_id) { HttpResponseMessage response = null; Object result = null; JavaScriptSerializer js = new JavaScriptSerializer(); ImportDataService service = new ImportDataService(); var httpRequest = HttpContext.Current.Request; if (httpRequest.Files.Count > 0) { foreach (string file in httpRequest.Files) { var postedFile = httpRequest.Files[file]; if (fileType == "1") // บัตรพนักงาน { result = service.importFile(fileType, fileId, user_id, postedFile); } else if (fileType == "2") // คะแนนกิจกรรม { result = service.importFileScore(fileType, fileId, user_id, postedFile); } else if (fileType == "3") // คะแนนแลกพ้อย { result = service.importFileScore(fileType, fileId, user_id, postedFile); } else if (fileType == "4") // user role { result = service.importUserRole(fileType, fileId, user_id, postedFile); } string json = js.Serialize(result); response = Request.CreateResponse(HttpStatusCode.OK); response.Content = new StringContent(json, System.Text.Encoding.UTF8, "application/json"); } } return(response); }
public void Then_The_Dataload_Endpoint_Is_Called( string authToken, ImporterConfiguration config) { //Arrange var azureClientCredentialHelper = new Mock <IAzureClientCredentialHelper>(); azureClientCredentialHelper .Setup(x => x.GetAccessTokenAsync(It.Is <string>(c => c.StartsWith("tenant")))) .ReturnsAsync(authToken); var configuration = new Mock <IOptions <ImporterConfiguration> >(); var dataUrl = "https://test.local/"; config.DataLoaderBaseUrlsAndIdentifierUris = $"{dataUrl}|tenant"; configuration.Setup(x => x.Value).Returns(config); var response = new HttpResponseMessage { Content = new StringContent(""), StatusCode = HttpStatusCode.Accepted }; var httpMessageHandler = SetupMessageHandlerMock(response, $"{dataUrl}ops/dataload"); var client = new HttpClient(httpMessageHandler.Object); var service = new ImportDataService(client, configuration.Object, azureClientCredentialHelper.Object, new ImporterEnvironment("TEST")); //Act service.Import(); //Assert httpMessageHandler.Protected() .Verify <Task <HttpResponseMessage> >( "SendAsync", Times.Once(), ItExpr.Is <HttpRequestMessage>(c => c.Method.Equals(HttpMethod.Post) && c.RequestUri.AbsoluteUri.Equals($"{dataUrl}ops/dataload") && c.Headers.Authorization.Scheme.Equals("Bearer") && c.Headers.Authorization.Parameter.Equals(authToken)), ItExpr.IsAny <CancellationToken>() ); }
public ImportController(ImportDataService importDataService) { _importDataService = importDataService; }