Exemplo n.º 1
0
        public async Task CanUpdateImageMetadata()
        {
            var imageId  = "12345";
            var created  = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(10));
            var updated  = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(1));
            var metadata = new Dictionary <string, string>()
            {
                { "item1", "value1" }, { "item2", "value2" }
            };
            var image = new ComputeImage(imageId, "tiny",
                                         new Uri("http://testcomputeendpoint.com/v2/1234567890/images/12345"),
                                         new Uri("http://testcomputeendpoint.com/1234567890/images/12345"), new Dictionary <string, string>(),
                                         "ACTIVE", created, updated, 10, 512, 100);

            this.simulator.Images.Add(image);

            var client = new ComputeServiceRestClient(GetValidContext(), this.ServiceLocator);

            var resp = await client.UpdateImageMetadata(imageId, metadata);

            Assert.AreEqual(HttpStatusCode.OK, resp.StatusCode);

            Assert.AreEqual(2, image.Metadata.Count);
            Assert.AreEqual("value1", image.Metadata["item1"]);
            Assert.AreEqual("value2", image.Metadata["item2"]);
        }
Exemplo n.º 2
0
        public async Task UpdateComputeImageMetadataIncludesAuthHeader()
        {
            var metadata = new Dictionary <string, string>()
            {
                { "item1", "value1" }, { "item2", "value2" }
            };
            var client =
                new ComputeServiceRestClient(GetValidContext(), this.ServiceLocator);

            await client.UpdateImageMetadata("12345", metadata);

            Assert.IsTrue(this.simulator.Headers.ContainsKey("X-Auth-Token"));
            Assert.AreEqual(this.authId, this.simulator.Headers["X-Auth-Token"]);
        }
Exemplo n.º 3
0
        public async Task UpdateComputeImageMetadataSetsCorrectContentType()
        {
            var metadata = new Dictionary <string, string>()
            {
                { "item1", "value1" }, { "item2", "value2" }
            };
            var imageId = "12345";
            var client  =
                new ComputeServiceRestClient(GetValidContext(), this.ServiceLocator);

            await client.UpdateImageMetadata(imageId, metadata);

            Assert.AreEqual("application/json", this.simulator.ContentType);
        }
Exemplo n.º 4
0
        public async Task UpdateComputeImageMetadataFormsCorrectUrlAndMethod()
        {
            var metadata = new Dictionary <string, string>()
            {
                { "item1", "value1" }, { "item2", "value2" }
            };
            var imageId = "12345";
            var client  =
                new ComputeServiceRestClient(GetValidContext(), this.ServiceLocator);

            await client.UpdateImageMetadata(imageId, metadata);

            Assert.AreEqual(string.Format("{0}/images/{1}/metadata", endpoint, imageId), this.simulator.Uri.ToString());
            Assert.AreEqual(HttpMethod.Post, this.simulator.Method);
        }