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); }
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); }
public void CannotConvertNonObjectJsonToImage() { var nonObjectJson = @"[]"; var converter = new ComputeImagePayloadConverter(); converter.ConvertImage(nonObjectJson); }
public void CannotConvertInvalidJsonToImage() { var badJsonFixture = @"{ NOT JSON"; var converter = new ComputeImagePayloadConverter(); converter.ConvertImage(badJsonFixture); }
public void CannotConvertJsonPayloadEmptyObjectToImage() { var emptyObjectFixture = @"{ }"; var converter = new ComputeImagePayloadConverter(); converter.ConvertImage(emptyObjectFixture); }
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); }
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"]); }