public void TestDeleteContainerMetadata()
        {
            IObjectStorageProvider provider = new CloudFilesProvider(Bootstrapper.Settings.TestIdentity);
            string containerName = TestContainerPrefix + Path.GetRandomFileName();

            ObjectStore result = provider.CreateContainer(containerName);
            Assert.AreEqual(ObjectStore.ContainerCreated, result);

            Dictionary<string, string> metadata = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
            {
                { "Key1", "Value 1" },
                { "Key2", "Value ²" },
                { "Key3", "Value 3" },
                { "Key4", "Value 4" },
            };

            provider.UpdateContainerMetadata(containerName, new Dictionary<string, string>(metadata, StringComparer.OrdinalIgnoreCase));

            Dictionary<string, string> actualMetadata = provider.GetContainerMetaData(containerName);
            Console.WriteLine("Container Metadata");
            foreach (KeyValuePair<string, string> pair in actualMetadata)
                Console.WriteLine("    {0}: {1}", pair.Key, pair.Value);

            CheckMetadataCollections(metadata, actualMetadata);

            /* Check the overload which takes a single key
             */
            // remove Key3 first to make sure we still have a ² character in a remaining value
            metadata.Remove("Key3");
            provider.DeleteContainerMetadata(containerName, "Key3");

            actualMetadata = provider.GetContainerMetaData(containerName);
            Console.WriteLine("Container Metadata after removing Key3");
            foreach (KeyValuePair<string, string> pair in actualMetadata)
                Console.WriteLine("    {0}: {1}", pair.Key, pair.Value);

            CheckMetadataCollections(metadata, actualMetadata);

            /* Check the overload which takes multiple keys
             */
            metadata.Remove("Key2");
            metadata.Remove("Key4");
            provider.DeleteContainerMetadata(containerName, new[] { "Key2", "Key4" });

            actualMetadata = provider.GetContainerMetaData(containerName);
            Console.WriteLine("Container Metadata after removing Key2, Key4");
            foreach (KeyValuePair<string, string> pair in actualMetadata)
                Console.WriteLine("    {0}: {1}", pair.Key, pair.Value);

            CheckMetadataCollections(metadata, actualMetadata);

            /* Check that duplicate removal is a NOP
             */
            metadata.Remove("Key2");
            metadata.Remove("Key4");
            provider.DeleteContainerMetadata(containerName, new[] { "Key2", "Key4" });

            actualMetadata = provider.GetContainerMetaData(containerName);
            Console.WriteLine("Container Metadata after removing Key2, Key4");
            foreach (KeyValuePair<string, string> pair in actualMetadata)
                Console.WriteLine("    {0}: {1}", pair.Key, pair.Value);

            CheckMetadataCollections(metadata, actualMetadata);

            /* Cleanup
             */
            provider.DeleteContainer(containerName, deleteObjects: true);
        }
 public void Should_Add_MetaData_For_Container()
 {
     var metaData = new Dictionary<string, string>();
     metaData.Add("X-Container-Meta-XXXX", "Test");
     var provider = new CloudFilesProvider();
     provider.UpdateContainerMetadata(containerName, metaData, identity: _testIdentity);
 }
        public void TestUpdateContainerMetadata()
        {
            IObjectStorageProvider provider = new CloudFilesProvider(Bootstrapper.Settings.TestIdentity);
            string containerName = TestContainerPrefix + Path.GetRandomFileName();

            ObjectStore result = provider.CreateContainer(containerName);
            Assert.AreEqual(ObjectStore.ContainerCreated, result);

            Dictionary<string, string> metadata = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
            {
                { "Key1", "Value 1" },
                { "Key2", "Value ²" },
            };

            provider.UpdateContainerMetadata(containerName, new Dictionary<string, string>(metadata, StringComparer.OrdinalIgnoreCase));

            Dictionary<string, string> actualMetadata = provider.GetContainerMetaData(containerName);
            Console.WriteLine("Container Metadata");
            foreach (KeyValuePair<string, string> pair in actualMetadata)
                Console.WriteLine("    {0}: {1}", pair.Key, pair.Value);

            CheckMetadataCollections(metadata, actualMetadata);

            metadata["Key2"] = "Value 2";
            Dictionary<string, string> updatedMetadata = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
            {
                { "Key2", "Value 2" }
            };
            provider.UpdateContainerMetadata(containerName, new Dictionary<string, string>(updatedMetadata, StringComparer.OrdinalIgnoreCase));

            actualMetadata = provider.GetContainerMetaData(containerName);
            Console.WriteLine("Container Metadata");
            foreach (KeyValuePair<string, string> pair in actualMetadata)
                Console.WriteLine("    {0}: {1}", pair.Key, pair.Value);

            CheckMetadataCollections(metadata, actualMetadata);

            provider.DeleteContainer(containerName, deleteObjects: true);
        }
        public void TestContainerInvalidHeaderKeyCharacters()
        {
            IObjectStorageProvider provider = new CloudFilesProvider(Bootstrapper.Settings.TestIdentity);
            string containerName = TestContainerPrefix + Path.GetRandomFileName();

            ObjectStore result = provider.CreateContainer(containerName);
            Assert.AreEqual(ObjectStore.ContainerCreated, result);

            List<char> validKeyCharList = new List<char>();
            for (char i = MinHeaderKeyCharacter; i <= MaxHeaderKeyCharacter; i++)
            {
                if (!SeparatorCharacters.Contains(i) && !NotSupportedCharacters.Contains(i))
                    validKeyCharList.Add(i);
            }

            for (int i = char.MinValue; i <= char.MaxValue; i++)
            {
                if (validKeyCharList.BinarySearch((char)i) >= 0)
                    continue;

                string invalidKey = new string((char)i, 1);

                try
                {
                    provider.UpdateContainerMetadata(
                        containerName,
                        new Dictionary<string, string>
                        {
                            { invalidKey, "Value" }
                        });
                    Assert.Fail("Should throw an exception for invalid keys.");
                }
                catch (ArgumentException)
                {
                    if (i >= MinHeaderKeyCharacter && i <= MaxHeaderKeyCharacter)
                        StringAssert.Contains(SeparatorCharacters, invalidKey);
                }
                catch (NotSupportedException)
                {
                    StringAssert.Contains(NotSupportedCharacters, invalidKey);
                }
            }

            provider.DeleteContainer(containerName, deleteObjects: true);
        }
        public void TestContainerHeaderKeyCharacters()
        {
            IObjectStorageProvider provider = new CloudFilesProvider(Bootstrapper.Settings.TestIdentity);
            string containerName = TestContainerPrefix + Path.GetRandomFileName();

            ObjectStore result = provider.CreateContainer(containerName);
            Assert.AreEqual(ObjectStore.ContainerCreated, result);

            List<char> keyCharList = new List<char>();
            for (char i = MinHeaderKeyCharacter; i <= MaxHeaderKeyCharacter; i++)
            {
                if (!SeparatorCharacters.Contains(i) && !NotSupportedCharacters.Contains(i))
                    keyCharList.Add(i);
            }

            string key = TestKeyPrefix + new string(keyCharList.ToArray());
            Console.WriteLine("Expected key: {0}", key);

            provider.UpdateContainerMetadata(
                containerName,
                new Dictionary<string, string>
                {
                    { key, "Value" }
                });

            Dictionary<string, string> metadata = provider.GetContainerMetaData(containerName);
            Assert.IsNotNull(metadata);

            string value;
            Assert.IsTrue(metadata.TryGetValue(key, out value));
            Assert.AreEqual("Value", value);

            provider.UpdateContainerMetadata(
                containerName,
                new Dictionary<string, string>
                {
                    { key, null }
                });

            metadata = provider.GetContainerMetaData(containerName);
            Assert.IsNotNull(metadata);
            Assert.IsFalse(metadata.TryGetValue(key, out value));

            provider.DeleteContainer(containerName, deleteObjects: true);
        }
 public void Should_Add_MetaData_For_Container()
 {
     var metaData = new Dictionary<string, string>();
     metaData.Add("key1", "value1");
     metaData.Add("key2", "value2");
     metaData.Add("key3", "value3");
     metaData.Add("key4", "value4");
     var provider = new CloudFilesProvider();
     provider.UpdateContainerMetadata(containerName, metaData, identity: _testIdentity);
 }
 public void Should_Add_Headers_For_Container()
 {
     var metaData = new Dictionary<string, string>();
     metaData.Add("Movie", "Batman");
     metaData.Add("Genre", "Action");
     var provider = new CloudFilesProvider();
     provider.UpdateContainerMetadata(containerName, metaData, identity: _testIdentity);
 }