コード例 #1
0
        public void TestServerMetadata()
        {
            IComputeProvider provider = Bootstrapper.CreateComputeProvider();

            Metadata initialMetadata = provider.ListServerMetadata(_server.Id);

            if (initialMetadata.Count > 0)
            {
                Console.WriteLine("Actual metadata");
                foreach (KeyValuePair <string, string> meta in initialMetadata)
                {
                    Console.WriteLine("  {0}: {1}", meta.Key, meta.Value);
                }

                Assert.Inconclusive("Expected the server to not have any initial metadata.");
            }

            Assert.IsTrue(provider.SetServerMetadataItem(_server.Id, "Item 1", "Value"));
            Assert.AreEqual("Value", provider.GetServerMetadataItem(_server.Id, "Item 1"));
            Assert.IsTrue(provider.SetServerMetadataItem(_server.Id, "Item 2", "Value ²"));
            Assert.AreEqual("Value ²", provider.GetServerMetadataItem(_server.Id, "Item 2"));

            // setting the same key overwrites the previous value
            Assert.IsTrue(provider.SetServerMetadataItem(_server.Id, "Item 1", "Value 1"));
            Assert.AreEqual("Value 1", provider.GetServerMetadataItem(_server.Id, "Item 1"));

            Assert.IsTrue(provider.DeleteServerMetadataItem(_server.Id, "Item 1"));
            Assert.IsFalse(provider.ListServerMetadata(_server.Id).ContainsKey("Item 1"));

            Metadata metadata = new Metadata()
            {
                { "Different", "Variables" },
            };

            Assert.IsTrue(provider.UpdateServerMetadata(_server.Id, metadata));
            Metadata actual = provider.ListServerMetadata(_server.Id);

            Assert.IsNotNull(actual);
            Assert.AreEqual(2, actual.Count);
            Assert.AreEqual("Value ²", actual["Item 2"]);
            Assert.AreEqual("Variables", actual["Different"]);

            // a slight tweak
            metadata["Different"] = "Values";
            Assert.IsTrue(provider.SetServerMetadata(_server.Id, metadata));
            actual = provider.ListServerMetadata(_server.Id);
            Assert.IsNotNull(actual);
            Assert.AreEqual(1, actual.Count);
            Assert.AreEqual("Values", actual["Different"]);

            Assert.IsTrue(provider.SetServerMetadata(_server.Id, new Metadata()));
            Assert.AreEqual(0, provider.ListServerMetadata(_server.Id).Count);
        }