Ejemplo n.º 1
0
 /// <summary>
 /// Deletes all logs of all levels.
 /// </summary>
 public void DeleteAllLogs()
 {
     foreach (var level in Enum.GetValues(typeof(LogLevel)).OfType <LogLevel>()
              .Where(l => l <LogLevel.Max && l> LogLevel.Min))
     {
         _blobs.DeleteContainerIfExist(LevelToContainer(level));
     }
 }
        public void CreatePutGetRangeDelete()
        {
            var privateContainerName = "test-" + Guid.NewGuid().ToString("N");

            BlobStorage.CreateContainerIfNotExist(privateContainerName);

            var blobNames = new[]
            {
                BlobName + "-0",
                BlobName + "-1",
                BlobName + "-2",
                BlobName + "-3"
            };

            var inputBlobs = new[]
            {
                new MyBlob(),
                new MyBlob(),
                new MyBlob(),
                new MyBlob()
            };

            for (int i = 0; i < blobNames.Length; i++)
            {
                BlobStorage.PutBlob(privateContainerName, blobNames[i], inputBlobs[i]);
            }

            string[] allEtags;
            var      allBlobs = BlobStorage.GetBlobRange <MyBlob>(privateContainerName, blobNames, out allEtags);

            Assert.AreEqual(blobNames.Length, allEtags.Length, "Wrong etags array length");
            Assert.AreEqual(blobNames.Length, allBlobs.Length, "Wrong blobs array length");

            for (int i = 0; i < allBlobs.Length; i++)
            {
                Assert.IsNotNull(allEtags[i], "Etag should have been set");
                Assert.IsTrue(allBlobs[i].HasValue, "Blob should have content");
                Assert.AreEqual(inputBlobs[i].MyGuid, allBlobs[i].Value.MyGuid, "Wrong blob content");
            }

            // Test missing blob
            var wrongBlobNames = new string[blobNames.Length + 1];

            Array.Copy(blobNames, wrongBlobNames, blobNames.Length);
            wrongBlobNames[wrongBlobNames.Length - 1] = "inexistent-blob";

            allBlobs = BlobStorage.GetBlobRange <MyBlob>(privateContainerName, wrongBlobNames, out allEtags);

            Assert.AreEqual(wrongBlobNames.Length, allEtags.Length, "Wrong etags array length");
            Assert.AreEqual(wrongBlobNames.Length, allBlobs.Length, "Wrong blobs array length");

            for (int i = 0; i < allBlobs.Length - 1; i++)
            {
                Assert.IsNotNull(allEtags[i], "Etag should have been set");
                Assert.IsTrue(allBlobs[i].HasValue, "Blob should have content");
                Assert.AreEqual(inputBlobs[i].MyGuid, allBlobs[i].Value.MyGuid, "Wrong blob content");
            }
            Assert.IsNull(allEtags[allEtags.Length - 1], "Etag should be null");
            Assert.IsFalse(allBlobs[allBlobs.Length - 1].HasValue, "Blob should not have a value");

            BlobStorage.DeleteContainerIfExist(privateContainerName);
        }