Exemple #1
0
        public static async Task CheckStorage()
        {
            var storageData = CreateStorageData();
            var storage     = new BinaryStorage();

            foreach (var kvp in storageData)
            {
                var blobId = kvp.Key;
                Assert.Null(await storage.GetBlobIfExists(blobId));
                var blocks = kvp.Value.Item2;
                for (var i = 0; i < blocks.Length; i++)
                {
                    await storage.WriteBlock(blocks[i].Item2, blobId, i, blocks[i].Item1);
                }

                await storage.WriteBlob(blobId, kvp.Value.Item1, blocks.Select(tuple => tuple.Item1).ToArray());
            }

            foreach (var kvp in storageData)
            {
                var blobId   = kvp.Key;
                var blobInfo = await storage.GetBlobIfExists(blobId);

                Assert.NotNull(blobInfo);
                Assert.Equal(kvp.Value.Item1, blobInfo.OriginalSize);
                Assert.InRange(blobInfo.UploadDate, DateTime.UtcNow.AddMinutes(-2), DateTime.UtcNow);
                Assert.Equal(kvp.Value.Item2.Select(tuple => tuple.Item1).ToArray(), blobInfo.BlockKeys);

                for (var i = 0; i < blobInfo.BlockKeys.Length; i++)
                {
                    var blockKey = blobInfo.BlockKeys[i];
                    Assert.Equal(kvp.Value.Item2[i].Item1, blockKey);

                    var blockContent = await storage.RetrieveBlock(blobId, blockKey);

                    Assert.Equal(kvp.Value.Item2[i].Item2, blockContent);
                }
            }
        }