コード例 #1
0
        public void CannotConvertJsonPayloadMissingNameToImage()
        {
            var missingFixture = @"{
                                    ""image"" : {
                                        ""status"": ""ACTIVE"",
                                        ""updated"": ""2014-06-30T16:56:32Z"",
                                        ""created"": ""2014-05-30T16:56:32Z"",
                                        ""minDisk"": 10,
                                        ""progress"": 100,
                                        ""minRam"": 512,
                                        ""links"": [
                                            {
                                                ""href"": ""http://someuri.com/v2/images/12345"",
                                                ""rel"": ""self""
                                            },
                                            {
                                                ""href"": ""http://someuri.com/images/12345"",
                                                ""rel"": ""bookmark""
                                            }
                                        ],
                                        ""id"": ""12345""
                                    }
                                }";

            var converter = new ComputeImagePayloadConverter();

            converter.ConvertImage(missingFixture);
        }
コード例 #2
0
        public void CannotConvertJsonPayloadWithBadMetadataToImage()
        {
            var created        = DateTime.Parse("2014-05-30T16:56:32Z").ToUniversalTime();
            var updated        = DateTime.Parse("2014-06-30T16:56:32Z").ToUniversalTime();
            var missingFixture = @"{
                                    ""image"" : {
                                        ""name"": ""image1"",
                                        ""status"": ""ACTIVE"",
                                        ""updated"": ""2014-06-30T16:56:32Z"",
                                        ""created"": ""2014-05-30T16:56:32Z"",
                                        ""minDisk"": 10,
                                        ""minRam"": 512,
                                        ""progress"": 100,
                                        ""links"": [
                                            {
                                                ""href"": ""http://someuri.com/v2/images/12345"",
                                                ""rel"": ""self""
                                            },
                                            {
                                                ""href"": ""http://someuri.com/images/12345"",
                                                ""rel"": ""bookmark""
                                            }
                                        ],
                                        ""metadata"": {
                                            ""kernel_id"": { ""NotExpectyed"" : ""SomeBadValue"" },
                                            ""ramdisk_id"": ""98765""
                                        },
                                        ""id"": ""12345""
                                    }
                                }";

            var converter = new ComputeImagePayloadConverter();

            converter.ConvertImage(missingFixture);
        }
コード例 #3
0
        public void CannotConvertNonObjectJsonToImage()
        {
            var nonObjectJson = @"[]";

            var converter = new ComputeImagePayloadConverter();

            converter.ConvertImage(nonObjectJson);
        }
コード例 #4
0
        public void CannotConvertInvalidJsonToImage()
        {
            var badJsonFixture = @"{ NOT JSON";

            var converter = new ComputeImagePayloadConverter();

            converter.ConvertImage(badJsonFixture);
        }
コード例 #5
0
        public void CannotConvertJsonPayloadEmptyObjectToImage()
        {
            var emptyObjectFixture = @"{ }";

            var converter = new ComputeImagePayloadConverter();

            converter.ConvertImage(emptyObjectFixture);
        }
コード例 #6
0
        public void CanConvertJsonPayloadMissingMetadataToImage()
        {
            var created        = DateTime.Parse("2014-05-30T16:56:32Z").ToUniversalTime();
            var updated        = DateTime.Parse("2014-06-30T16:56:32Z").ToUniversalTime();
            var missingFixture = @"{
                                    ""image"" : {
                                        ""name"": ""image1"",
                                        ""status"": ""ACTIVE"",
                                        ""updated"": ""2014-06-30T16:56:32Z"",
                                        ""created"": ""2014-05-30T16:56:32Z"",
                                        ""minDisk"": 10,
                                        ""minRam"": 512,
                                        ""progress"": 100,
                                        ""links"": [
                                            {
                                                ""href"": ""http://someuri.com/v2/images/12345"",
                                                ""rel"": ""self""
                                            },
                                            {
                                                ""href"": ""http://someuri.com/images/12345"",
                                                ""rel"": ""bookmark""
                                            }
                                        ],
                                        ""id"": ""12345""
                                    }
                                }";

            var converter = new ComputeImagePayloadConverter();
            var image     = converter.ConvertImage(missingFixture);

            Assert.IsNotNull(image);
            Assert.AreEqual("image1", image.Name);
            Assert.AreEqual("ACTIVE", image.Status);
            Assert.AreEqual("12345", image.Id);
            Assert.AreEqual(512, image.MinimumRamSize);
            Assert.AreEqual(10, image.MinimumDiskSize);
            Assert.AreEqual(100, image.UploadProgress);
            Assert.AreEqual(created.ToLongTimeString(), image.CreateDate.ToLongTimeString());
            Assert.AreEqual(updated.ToLongTimeString(), image.LastUpdated.ToLongTimeString());
            Assert.AreEqual(new Uri("http://someuri.com/images/12345"), image.PermanentUri);
            Assert.AreEqual(new Uri("http://someuri.com/v2/images/12345"), image.PublicUri);
            Assert.AreEqual(0, image.Metadata.Count);
        }
コード例 #7
0
        public void CanConvertJsonPayloadToImage()
        {
            var imageName      = "myimage";
            var imageId        = "12345";
            var imagePublicUri = "http://www.server.com/v2/images/12345";
            var imagePermUri   = "http://www.server.com/images/12345";
            var minRam         = 512;
            var minDisk        = 10;
            var progress       = 100;
            var status         = "ACTIVE";

            var lastUpdate  = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(10));
            var createdDate = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(100));
            var created     = createdDate.ToLongTimeString();
            var updated     = lastUpdate.ToLongTimeString();

            var computeFlavorJsonResponseFixture = CreateImageJsonFixtrue(imageName, imageId, imagePermUri, imagePublicUri,
                                                                          status, minDisk.ToString(), minRam.ToString(), progress.ToString(), created, updated);

            var converter = new ComputeImagePayloadConverter();
            var image     = converter.ConvertImage(computeFlavorJsonResponseFixture);

            Assert.IsNotNull(image);
            Assert.AreEqual(imageName, image.Name);
            Assert.AreEqual(imageId, image.Id);
            Assert.AreEqual(minRam, image.MinimumRamSize);
            Assert.AreEqual(progress, image.UploadProgress);
            Assert.AreEqual(minDisk, image.MinimumDiskSize);
            Assert.AreEqual(status, image.Status);
            Assert.AreEqual(lastUpdate.ToLongTimeString(), image.LastUpdated.ToLongTimeString());
            Assert.AreEqual(createdDate.ToLongTimeString(), image.CreateDate.ToLongTimeString());
            Assert.AreEqual(new Uri(imagePermUri), image.PermanentUri);
            Assert.AreEqual(new Uri(imagePublicUri), image.PublicUri);
            Assert.AreEqual(2, image.Metadata.Count);
            Assert.AreEqual("nokernel", image.Metadata["kernel_id"]);
            Assert.AreEqual("98765", image.Metadata["ramdisk_id"]);
        }