Exemple #1
0
        /// <summary>
        /// Create and store a new metadata record
        /// </summary>
        /// <param name="runId">uniquely identifies a run of the OBA service</param>
        /// <param name="regionId">uniquely identifies a region</param>
        /// <param name="agencyId">uniquely identifies an agency</param>
        /// <param name="recordType">type of record to store</param>
        /// <param name="count">number of records stored</param>
        /// <returns>a task that inserts a new metadata record</returns>
        public async Task Insert(string runId, string regionId, string agencyId, RecordType recordType, int count)
        {
            DownloadMetadataEntity entity = new DownloadMetadataEntity()
            {
                RunId      = runId,
                RegionId   = regionId,
                AgencyId   = agencyId,
                RecordType = recordType.ToString(),
                Count      = count
            };

            List <DownloadMetadataEntity> entities = new List <DownloadMetadataEntity>();

            entities.Add(entity);
            await this.Insert(entities);
        }
        public async Task InsertAndGet()
        {
            // create tables
            string         runId          = RunId.GenerateTestRunId();
            StorageManager storageManager = new StorageManager(TestConstants.AzureStorageConnectionString, TableNames.TableType.DownloadMetadata, runId);
            await storageManager.CreateTables();

            // create a bogus download metadata entity
            DownloadMetadataEntity entity = new DownloadMetadataEntity()
            {
                RunId      = runId,
                RegionId   = "abcd",
                AgencyId   = "1234",
                RecordType = RecordType.Stop.ToString(),
                Count      = 666
            };

            // stick it into store
            List <DownloadMetadataEntity> entities = new List <DownloadMetadataEntity>();

            entities.Add(entity);
            await storageManager.DownloadMetadataStore.Insert(entities);

            // get it from the store
            IEnumerable <DownloadMetadataEntity> retrievedEntities1 = storageManager.DownloadMetadataStore.Get(runId);

            // clean up
            await storageManager.DownloadMetadataStore.Delete(runId);

            // get it from the store again
            IEnumerable <DownloadMetadataEntity> retrievedEntities2 = storageManager.DownloadMetadataStore.Get(runId);

            // check the retrieved records
            Assert.IsNotNull(retrievedEntities1);
            Assert.AreEqual(retrievedEntities1.Count(), entities.Count);
            Assert.IsNull(retrievedEntities2);
            Assert.AreEqual(entity.RunId, retrievedEntities1.First().RunId);
            Assert.AreEqual(entity.RegionId, retrievedEntities1.First().RegionId);
            Assert.AreEqual(entity.AgencyId, retrievedEntities1.First().AgencyId);
            Assert.AreEqual(entity.RecordType, retrievedEntities1.First().RecordType);
            Assert.AreEqual(entity.Count, retrievedEntities1.First().Count);
        }