public async Task InsertAndGet() { // create tables StorageManager storageManager = new StorageManager(TestConstants.AzureStorageConnectionString, TableNames.TableType.Download, RunId.GenerateTestRunId()); await storageManager.CreateTables(); // fetch a regionslist file Client obaClient = new Client(TestConstants.OBAApiKey, TestConstants.OBARegionsListUri); RegionsList regionsList = await obaClient.GetAllRegionsAsync(); // stick it into store await storageManager.RegionsListStore.Insert(regionsList); // get it from the store RegionsListEntity regionsListEntity = storageManager.RegionsListStore.Get(); // clean up await storageManager.DeleteDataTables(); // check the retrieved record Assert.IsNotNull(regionsListEntity); Assert.AreEqual(regionsListEntity.RawContent, regionsList.RegionsRawContent); Assert.AreEqual(regionsListEntity.RegionsServiceUri, TestConstants.OBARegionsListUri); Assert.AreEqual(regionsListEntity.RecordType, Enum.GetName(typeof(RecordType), RecordType.RegionsList)); Assert.AreEqual(TestConstants.OBARegionsListUri, regionsList.Uri); }
/// <summary> /// Stores a OBA Source model in Azure Tables /// </summary> /// <param name="regionsList">OBA Source model from the OBA client</param> /// <returns>task that stores the entity</returns> public async Task Insert(RegionsList regionsList) { // create a new storage entity RegionsListEntity regionsListEntity = new RegionsListEntity { RawContent = regionsList.RegionsRawContent, RecordType = RecordType.RegionsList.ToString(), RegionsServiceUri = regionsList.Uri }; // insert it await this.Insert(regionsListEntity); }
public async Task DownloadAndStore() { string runId = RunId.GenerateTestRunId(); // create storage managers StorageManager downloadStorage = new StorageManager(TestConstants.AzureStorageConnectionString, TableNames.TableType.Download, runId); StorageManager downloadMetadataStorage = new StorageManager(TestConstants.AzureStorageConnectionString, TableNames.TableType.DownloadMetadata, runId); // create OBA client Client obaClient = new Client(TestConstants.OBAApiKey, TestConstants.OBARegionsListUri); // create tables await downloadStorage.CreateTables(); await downloadMetadataStorage.CreateTables(); // download and store RegionsList regionsList = await DownloadRegionsList.DownloadAndStore(obaClient, downloadStorage, downloadMetadataStorage, runId); // get it from store RegionsListEntity regionsListEntity = downloadStorage.RegionsListStore.Get(); IEnumerable <DownloadMetadataEntity> downloadMetadataEntities = downloadMetadataStorage.DownloadMetadataStore.Get(runId); // clean up await downloadStorage.DeleteDataTables(); await downloadMetadataStorage.DownloadMetadataStore.Delete(runId); // check Assert.IsNotNull(regionsList); Assert.IsNotNull(regionsListEntity); Assert.IsNotNull(downloadMetadataEntities); Assert.AreEqual(regionsList.RegionsRawContent, regionsListEntity.RawContent); Assert.AreEqual(regionsList.Uri, TestConstants.OBARegionsListUri); Assert.AreEqual(regionsListEntity.RecordType, Enum.GetName(typeof(RecordType), RecordType.RegionsList)); Assert.AreEqual(TestConstants.OBARegionsListUri, regionsListEntity.RegionsServiceUri); Assert.AreEqual(downloadMetadataEntities.Count(), 1); Assert.AreEqual(downloadMetadataEntities.First().RecordType, RecordType.RegionsList.ToString()); Assert.AreEqual(downloadMetadataEntities.First().Count, 1); Assert.AreEqual(downloadMetadataEntities.First().AgencyId, string.Empty); Assert.AreEqual(downloadMetadataEntities.First().RegionId, string.Empty); Assert.AreEqual(downloadMetadataEntities.First().RunId, runId); }
public async Task DownloadAndStore() { // create download manager & have it download & store data string runId = RunId.GenerateTestRunId(); DownloadManager downloadManager = new DownloadManager( TestConstants.AzureStorageConnectionString, runId, TestConstants.OBAApiKey, TestConstants.OBARegionsListUri); await downloadManager.InitializeStorage(); await downloadManager.DownloadAndStore(); // fetch data for later verification StorageManager downloadStorage = new StorageManager(TestConstants.AzureStorageConnectionString, TableNames.TableType.Download, runId); StorageManager downloadMetadataStorage = new StorageManager(TestConstants.AzureStorageConnectionString, TableNames.TableType.DownloadMetadata, runId); IEnumerable <DownloadMetadataEntity> metadataEntities = downloadMetadataStorage.DownloadMetadataStore.Get(runId); RegionsListEntity regionsListEntity = downloadStorage.RegionsListStore.Get(); List <RegionEntity> regionEntities = downloadStorage.RegionStore.GetAllRegions().ToList(); List <AgencyEntity> agencyEntities = null; List <RouteEntity> routeEntities = null; List <StopEntity> stopEntities = null; int regionEntityIndex = -1; if (regionEntities != null && regionEntities.Count > 0) { // pick a random region entity regionEntityIndex = new Random().Next(regionEntities.Count); // fetch all agency entities for that region agencyEntities = (await downloadStorage.AgencyStore.GetAllAgencies(regionEntities[regionEntityIndex].Id)).ToList(); // fetch all stops for that region stopEntities = (await downloadStorage.StopStore.GetAllStops(regionEntities[regionEntityIndex].Id)).ToList(); } int agencyEntityIndex = -1; if (agencyEntities != null && agencyEntities.Count > 0) { // pick a random agency entity agencyEntityIndex = new Random().Next(agencyEntities.Count); // fetch all routes for that agency routeEntities = (await downloadStorage.RouteStore.GetAllRoutes(regionEntities[regionEntityIndex].Id, agencyEntities[agencyEntityIndex].Id)).ToList(); } // clean up await downloadManager.DeleteDownload(); // check Assert.IsNotNull(metadataEntities); Assert.IsNotNull(regionsListEntity); Assert.AreEqual(regionsListEntity.RecordType, RecordType.RegionsList.ToString()); Assert.AreEqual(regionsListEntity.RegionsServiceUri, TestConstants.OBARegionsListUri); IEnumerable <DownloadMetadataEntity> regionsListMetadata = from entity in metadataEntities where entity.RecordType == RecordType.RegionsList.ToString() select entity; Assert.IsNotNull(regionsListMetadata); Assert.AreEqual(regionsListMetadata.Count(), 1); Assert.AreEqual(regionsListMetadata.ElementAt(0).Count, 1); Assert.AreEqual(regionsListMetadata.ElementAt(0).RunId, runId); Assert.AreEqual(regionsListMetadata.ElementAt(0).AgencyId, string.Empty); Assert.AreEqual(regionsListMetadata.ElementAt(0).RegionId, string.Empty); Assert.IsNotNull(regionEntities); IEnumerable <DownloadMetadataEntity> regionMetadata = from entity in metadataEntities where entity.RecordType == RecordType.Region.ToString() select entity; Assert.IsNotNull(regionMetadata); Assert.AreEqual(regionMetadata.Count(), 1); Assert.AreEqual(regionMetadata.ElementAt(0).Count, regionEntities.Count); Assert.AreEqual(regionMetadata.ElementAt(0).RunId, runId); Assert.AreEqual(regionMetadata.ElementAt(0).AgencyId, string.Empty); Assert.AreEqual(regionMetadata.ElementAt(0).RegionId, string.Empty); Assert.IsNotNull(agencyEntities); IEnumerable <DownloadMetadataEntity> agencyMetadata = from entity in metadataEntities where entity.RecordType == RecordType.Agency.ToString() && entity.RegionId == regionEntities[regionEntityIndex].Id select entity; Assert.IsNotNull(agencyMetadata); Assert.AreEqual(agencyMetadata.Count(), 1); Assert.AreEqual(agencyMetadata.ElementAt(0).Count, agencyEntities.Count); Assert.AreEqual(agencyMetadata.ElementAt(0).RunId, runId); Assert.AreEqual(agencyMetadata.ElementAt(0).AgencyId, string.Empty); Assert.AreEqual(agencyMetadata.ElementAt(0).RegionId, regionEntities[regionEntityIndex].Id); Assert.IsNotNull(routeEntities); IEnumerable <DownloadMetadataEntity> routeMetadata = from entity in metadataEntities where entity.RecordType == RecordType.Route.ToString() && entity.RegionId == regionEntities[regionEntityIndex].Id && entity.AgencyId == agencyEntities[agencyEntityIndex].Id select entity; Assert.IsNotNull(routeMetadata); Assert.AreEqual(routeMetadata.Count(), 1); Assert.AreEqual(routeMetadata.ElementAt(0).Count, routeEntities.Count); Assert.AreEqual(routeMetadata.ElementAt(0).RunId, runId); Assert.AreEqual(routeMetadata.ElementAt(0).AgencyId, agencyEntities[agencyEntityIndex].Id); Assert.AreEqual(routeMetadata.ElementAt(0).RegionId, regionEntities[regionEntityIndex].Id); Assert.IsNotNull(stopEntities); IEnumerable <DownloadMetadataEntity> stopMetadata = from entity in metadataEntities where entity.RecordType == RecordType.Stop.ToString() && entity.RegionId == regionEntities[regionEntityIndex].Id select entity; Assert.IsNotNull(stopMetadata); Assert.AreEqual(stopMetadata.Count(), 1); Assert.AreEqual(stopMetadata.ElementAt(0).Count, stopEntities.Count); Assert.AreEqual(stopMetadata.ElementAt(0).RunId, runId); Assert.AreEqual(stopMetadata.ElementAt(0).AgencyId, string.Empty); Assert.AreEqual(stopMetadata.ElementAt(0).RegionId, regionEntities[regionEntityIndex].Id); }
/// <summary> /// Stores a regions list entity in Azure Tables /// </summary> /// <param name="regionsList">regions list entity</param> /// <returns>task that stores the entity</returns> public async Task Insert(RegionsListEntity regionsList) { await this.Table.ExecuteAsync(TableOperation.Insert(new EntityAdapter <RegionsListEntity>(regionsList))); }