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 LoadLatestScan_NoContainer_ReturnsNull()
        {
            string hostId             = Guid.NewGuid().ToString();
            string storageAccountName = Guid.NewGuid().ToString();
            string containerName      = Guid.NewGuid().ToString();

            // by default there is no table in this client
            var manager = new StorageBlobScanInfoManager(hostId, blobServiceClient);

            var result = await manager.LoadLatestScanAsync(storageAccountName, containerName);

            Assert.Null(result);
        }
        public async Task LoadLatestScan_NoBlob_ReturnsNull()
        {
            string hostId             = Guid.NewGuid().ToString();
            string storageAccountName = Guid.NewGuid().ToString();
            string containerName      = Guid.NewGuid().ToString();

            var container = blobServiceClient.GetBlobContainerClient(HostContainerNames.Hosts);
            await container.CreateIfNotExistsAsync();

            var manager = new StorageBlobScanInfoManager(hostId, blobServiceClient);

            var result = await manager.LoadLatestScanAsync(storageAccountName, containerName);

            Assert.Null(result);
        }
        public async Task LoadLatestScan_NoBlob_ReturnsNull()
        {
            string hostId             = Guid.NewGuid().ToString();
            string storageAccountName = Guid.NewGuid().ToString();
            string containerName      = Guid.NewGuid().ToString();

            var account   = new FakeStorageAccount();
            var client    = account.CreateBlobClient();
            var container = client.GetContainerReference(HostContainerNames.Hosts);

            container.CreateIfNotExists();

            var manager = new StorageBlobScanInfoManager(hostId, client);

            var result = await manager.LoadLatestScanAsync(storageAccountName, containerName);

            Assert.Null(result);
        }
        public async Task LoadLatestScan_Returns_Timestamp()
        {
            string hostId             = "host-" + Guid.NewGuid().ToString();
            string storageAccountName = "account=" + Guid.NewGuid().ToString();
            string containerName      = "container-" + Guid.NewGuid().ToString();

            var container = blobServiceClient.GetBlobContainerClient(HostContainerNames.Hosts);
            await container.CreateIfNotExistsAsync();

            DateTime now  = DateTime.UtcNow;
            var      blob = GetBlockBlobReference(blobServiceClient, hostId, storageAccountName, containerName);
            await blob.UploadTextAsync(string.Format("{{ \"LatestScan\" : \"{0}\" }}", now.ToString("o")));

            var manager = new StorageBlobScanInfoManager(hostId, blobServiceClient);

            var result = await manager.LoadLatestScanAsync(storageAccountName, containerName);

            Assert.AreEqual(now, result);
        }
        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));
        }