public async Task UpdateLatestScan_Updates()
        {
            string hostId             = Guid.NewGuid().ToString();
            string storageAccountName = Guid.NewGuid().ToString();
            string containerName      = Guid.NewGuid().ToString();

            var account   = new XFakeStorageAccount();
            var client    = account.CreateCloudBlobClient();
            var container = client.GetContainerReference(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.Equal(now, storedTime);
            Assert.Equal(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();

            var account = new XFakeStorageAccount();
            var client  = account.CreateCloudBlobClient();

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

            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 XFakeStorageAccount();
            var client    = account.CreateCloudBlobClient();
            var container = client.GetContainerReference(HostContainerNames.Hosts);
            await container.CreateIfNotExistsAsync();

            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 account   = new XFakeStorageAccount();
            var client    = account.CreateCloudBlobClient();
            var container = client.GetContainerReference(HostContainerNames.Hosts);
            await container.CreateIfNotExistsAsync();

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

            var manager = new StorageBlobScanInfoManager(hostId, client);

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

            Assert.Equal(now, result);
        }