public async Task UpdateLatestScan_Updates() { string hostId = Guid.NewGuid().ToString(); string storageAccountName = Guid.NewGuid().ToString(); string containerName = Guid.NewGuid().ToString(); var client = account.CreateBlobServiceClient(); var container = client.GetBlobContainerClient(HostContainerNames.Hosts); await container.CreateIfNotExistsAsync(); DateTime now = DateTime.UtcNow; DateTime past = now.AddMinutes(-1); var blob = GetBlockBlobReference(client, hostId, storageAccountName, containerName); await blob.UploadTextAsync(string.Format("{{ 'LatestScan' : '{0}' }}", past.ToString("o"))); var manager = new StorageBlobScanInfoManager(hostId, client); await manager.UpdateLatestScanAsync(storageAccountName, containerName, now); var scanInfo = GetBlockBlobReference(client, hostId, storageAccountName, containerName).DownloadText(); var scanInfoJson = JObject.Parse(scanInfo); var storedTime = (DateTime)scanInfoJson["LatestScan"]; Assert.AreEqual(now, storedTime); Assert.AreEqual(now, await manager.LoadLatestScanAsync(storageAccountName, containerName)); }
public async Task UpdateLatestScan_Inserts() { string hostId = Guid.NewGuid().ToString(); string storageAccountName = Guid.NewGuid().ToString(); string containerName = Guid.NewGuid().ToString(); var container = blobServiceClient.GetBlobContainerClient(HostContainerNames.Hosts); await container.CreateIfNotExistsAsync(); DateTime now = DateTime.UtcNow; var manager = new StorageBlobScanInfoManager(hostId, blobServiceClient); await manager.UpdateLatestScanAsync(storageAccountName, containerName, now); var scanInfo = GetBlockBlobReference(blobServiceClient, hostId, storageAccountName, containerName).DownloadText(); var scanInfoJson = JObject.Parse(scanInfo); var storedTime = (DateTime)(scanInfoJson["LatestScan"]); Assert.AreEqual(now, storedTime); Assert.AreEqual(now, await manager.LoadLatestScanAsync(storageAccountName, containerName)); }