public async Task InsertAndGet() { // create tables StorageManager storageManager = new StorageManager(TestConstants.AzureStorageConnectionString, TableNames.TableType.Download, RunId.GenerateTestRunId()); await storageManager.CreateTables(); // fetch agencies from a region var obaClient = new Client(TestConstants.OBAApiKey, TestConstants.OBARegionsListUri); var region = new Region() { Id = "1", RegionName = "Puget Sound", ObaBaseUrl = "http://api.pugetsound.onebusaway.org/" }; List <Agency> agencies = (await obaClient.GetAllAgenciesAsync(region)).ToList(); // stick them into the store await storageManager.AgencyStore.Insert(agencies, region.Id); // get them from the store IEnumerable <AgencyEntity> agencyEntities = await storageManager.AgencyStore.GetAllAgencies(region.Id); // clean up await storageManager.DeleteDataTables(); // check the retrieved records Assert.IsNotNull(agencyEntities); Assert.AreEqual(agencyEntities.Count(), agencies.Count); HashSet <string> id1 = new HashSet <string>(agencyEntities.Select(o => o.Id)); HashSet <string> id2 = new HashSet <string>(agencies.Select(o => o.Id)); Assert.IsTrue(id1.IsSubsetOf(id2)); Assert.IsTrue(id2.IsSubsetOf(id1)); HashSet <string> name1 = new HashSet <string>(agencyEntities.Select(o => o.Name)); HashSet <string> name2 = new HashSet <string>(agencies.Select(o => o.Name)); Assert.IsTrue(name1.IsSubsetOf(name2)); Assert.IsTrue(name2.IsSubsetOf(name1)); HashSet <string> rawContent1 = new HashSet <string>(agencyEntities.Select(o => o.RawContent)); HashSet <string> rawContent2 = new HashSet <string>(agencies.Select(o => o.RawContent)); Assert.IsTrue(rawContent1.IsSubsetOf(rawContent2)); Assert.IsTrue(rawContent2.IsSubsetOf(rawContent1)); }
/// <summary> /// Uploads input data and then send API post for AutoBookRequest /// </summary> /// <param name="autoBookInterface"></param> /// <param name="autoBook"></param> public void UploadInputFilesAndCreateAutoBookRequest(IReadOnlyCollection <AutoBookInstanceConfiguration> autoBookInstanceConfigurations, double storageGB) { _auditEventRepository.Insert(AuditEventFactory.CreateAuditEventForInformationMessage(0, 0, $"AutoDistributed - {nameof(UploadInputFilesAndCreateAutoBookRequest)}")); using var scope = _repositoryFactory.BeginRepositoryScope(); var runRepository = scope.CreateRepository <IRunRepository>(); bool startedRun = false; try { // Update scenario status to Starting, Scenario.StartedDateTime has already been set RunManager.UpdateScenarioStatuses(_repositoryFactory, _auditEventRepository, RunId, new List <Guid>() { ScenarioId }, new List <ScenarioStatuses>() { ScenarioStatuses.Starting }); var run = runRepository.Find(RunId); // Get run _auditEventRepository.Insert(AuditEventFactory.CreateAuditEventForInformationMessage(0, 0, $"AutoDistributed - about to enter input handler")); _autoBookInputHandler.Handle(run, ScenarioId); // Upload input data _auditEventRepository.Insert(AuditEventFactory.CreateAuditEventForInformationMessage(0, 0, $"AutoDistributed - uploaded files for run: {RunId.ToString()} scenario: {ScenarioId.ToString()}")); // Create AutoBookRequest bool loggedNotifyFinished = false; try { _auditEventRepository.Insert(AuditEventFactory.CreateAuditEventForGameplanPipelineStart(0, 0, PipelineEventIDs.STARTED_NOTIFYING_AUTOBOOK_API, RunId, ScenarioId, null, null)); _pipelineAuditEventRepository.Add(PipelineEventHelper.CreatePipelineAuditEvent(AuditEventTypes.GamePlanRun, PipelineEventIDs.STARTED_NOTIFYING_AUTOBOOK_API, RunId, ScenarioId, null)); _auditEventRepository.Insert(AuditEventFactory.CreateAuditEventForInformationMessage(0, 0, $"AutoDistributed - Create AutBookRequest for run: {run.Id} scenario: {ScenarioId}")); var result = CreateAutoBookRequest(autoBookInstanceConfigurations); _auditEventRepository.Insert(AuditEventFactory.CreateAuditEventForInformationMessage(0, 0, $"AutoDistributed - Created AutBookRequest for run: {run.Id} scenario: {ScenarioId}, result: {result}")); _auditEventRepository.Insert(AuditEventFactory.CreateAuditEventForGameplanPipelineEnd(0, 0, PipelineEventIDs.FINISHED_NOTIFYING_AUTOBOOK_API, RunId, ScenarioId, null, null, null, null)); _pipelineAuditEventRepository.Add(PipelineEventHelper.CreatePipelineAuditEvent(AuditEventTypes.GamePlanRun, PipelineEventIDs.FINISHED_NOTIFYING_AUTOBOOK_API, RunId, ScenarioId, null)); loggedNotifyFinished = true; } catch (System.Exception exception) { if (!loggedNotifyFinished) { _auditEventRepository.Insert(AuditEventFactory.CreateAuditEventForGameplanPipelineEnd(0, 0, PipelineEventIDs.FINISHED_NOTIFYING_AUTOBOOK_API, RunId, ScenarioId, null, null, exception.Message, exception)); _pipelineAuditEventRepository.Add(PipelineEventHelper.CreatePipelineAuditEvent(AuditEventTypes.GamePlanRun, PipelineEventIDs.FINISHED_NOTIFYING_AUTOBOOK_API, RunId, ScenarioId, exception.Message)); } throw; } finally { _pipelineAuditEventRepository.SaveChanges(); } // Flag as InProgress RunManager.UpdateScenarioStatuses(_repositoryFactory, _auditEventRepository, RunId, new List <Guid>() { ScenarioId }, new List <ScenarioStatuses>() { ScenarioStatuses.InProgress }); startedRun = true; } catch { throw; } finally { // Clean up failure if (!startedRun) { _pipelineAuditEventRepository.SaveChanges(); } } }
public async Task InsertAndGet() { // create tables StorageManager storageManager = new StorageManager(TestConstants.AzureStorageConnectionString, TableNames.TableType.Download, RunId.GenerateTestRunId()); await storageManager.CreateTables(); // fetch regions var obaClient = new Client(TestConstants.OBAApiKey, TestConstants.OBARegionsListUri); var regionsList = await obaClient.GetAllRegionsAsync(); // stick it into store await storageManager.RegionStore.Insert(regionsList.Regions); // get the list from the store IEnumerable <RegionEntity> regionEntities = storageManager.RegionStore.GetAllRegions(); // clean up await storageManager.DeleteDataTables(); // check the retrieved records Assert.AreEqual(regionEntities.Count(), regionsList.Regions.Count); HashSet <string> id1 = new HashSet <string>(regionsList.Regions.Select(o => o.Id)); HashSet <string> id2 = new HashSet <string>(regionEntities.Select(o => o.Id)); Assert.IsTrue(id1.IsSubsetOf(id2)); Assert.IsTrue(id2.IsSubsetOf(id1)); HashSet <string> name1 = new HashSet <string>(regionsList.Regions.Select(o => o.RegionName)); HashSet <string> name2 = new HashSet <string>(regionEntities.Select(o => o.RegionName)); Assert.IsTrue(name1.IsSubsetOf(name2)); Assert.IsTrue(name2.IsSubsetOf(name1)); HashSet <string> url1 = new HashSet <string>(regionsList.Regions.Select(o => o.ObaBaseUrl)); HashSet <string> url2 = new HashSet <string>(regionEntities.Select(o => o.ObaBaseUrl)); Assert.IsTrue(url1.IsSubsetOf(url2)); Assert.IsTrue(url2.IsSubsetOf(url1)); HashSet <string> raw1 = new HashSet <string>(regionsList.Regions.Select(o => o.RawContent)); HashSet <string> raw2 = new HashSet <string>(regionEntities.Select(o => o.RawContent)); Assert.IsTrue(raw1.IsSubsetOf(raw2)); Assert.IsTrue(raw2.IsSubsetOf(raw1)); }