public void CanConvertJsonPayloadToFlavor()
        {
            var flavorName      = "m1.tiny";
            var flavorId        = "1";
            var flavorPublicUri = "http://www.server.com/v2/flavors/1";
            var flavorPermUri   = "http://www.server.com/flavors/1";
            var flavorRam       = "512";
            var flavorDisk      = "10";
            var flavorVcpus     = "2";

            var computeFlavorJsonResponseFixture = CreateFlavorJsonFixtrue(flavorName, flavorId, flavorRam, flavorDisk,
                                                                           flavorVcpus, flavorPermUri, flavorPublicUri);

            var converter = new ComputeFlavorPayloadConverter();
            var flavor    = converter.ConvertFlavor(computeFlavorJsonResponseFixture);

            Assert.IsNotNull(flavor);
            Assert.AreEqual(flavorName, flavor.Name);
            Assert.AreEqual(flavorId, flavor.Id);
            Assert.AreEqual(flavorRam, flavor.Ram);
            Assert.AreEqual(flavorVcpus, flavor.Vcpus);
            Assert.AreEqual(flavorDisk, flavor.Disk);
            Assert.AreEqual(new Uri(flavorPermUri), flavor.PermanentUri);
            Assert.AreEqual(new Uri(flavorPublicUri), flavor.PublicUri);
        }
        public void CanConvertJsonPayloadMissingDiskToFlavor()
        {
            var missingFixture = @"{
                                    ""flavor"": {
                                        ""name"": ""m1.tiny"",
                                        ""id"": ""1"",
                                        ""links"": [
                                            {
                                                ""href"": ""http://someuri.com/v2/flavors/1"",
                                                ""rel"": ""self""
                                            },
                                            {
                                                ""href"": ""http://someuri.com/flavors/1"",
                                                ""rel"": ""bookmark""
                                            }
                                        ],
                                        ""ram"": 512,
                                        ""vcpus"": 2
                                    }
                                }";

            var converter = new ComputeFlavorPayloadConverter();
            var flavor    = converter.ConvertFlavor(missingFixture);

            Assert.IsNotNull(flavor);
            Assert.AreEqual("m1.tiny", flavor.Name);
            Assert.AreEqual("1", flavor.Id);
            Assert.AreEqual("512", flavor.Ram);
            Assert.AreEqual("2", flavor.Vcpus);
            Assert.AreEqual(new Uri("http://someuri.com/flavors/1"), flavor.PermanentUri);
            Assert.AreEqual(new Uri("http://someuri.com/v2/flavors/1"), flavor.PublicUri);
        }
        public void CanParseValidFlavorsJsonPayloadWithMultipleFlavors()
        {
            var validMultipleFlavorsJsonFixture = @"{{ ""flavors"": [ {0} ] }}";
            var firstFlavor = CreateFlavorSummaryJsonFixtrue("m1.tiny", "1", "http://server.com/flavors/1",
                                                             "http://server.com/v2/flavors/1");
            var secondFlavor = CreateFlavorSummaryJsonFixtrue("m1.small", "2", "http://server.com/flavors/2",
                                                              "http://server.com/v2/flavors/2");

            var validMultipleFlavorsJson = string.Format(validMultipleFlavorsJsonFixture,
                                                         string.Join(",", new List <string>()
            {
                firstFlavor, secondFlavor
            }));

            var converter = new ComputeFlavorPayloadConverter();
            var flavors   = converter.ConvertFlavors(validMultipleFlavorsJson).ToList();

            Assert.AreEqual(2, flavors.Count());
            var flv1 =
                flavors.First(o => string.Equals(o.Name, "m1.tiny", StringComparison.InvariantCultureIgnoreCase));
            var flv2 =
                flavors.First(o => string.Equals(o.Name, "m1.small", StringComparison.InvariantCultureIgnoreCase));

            Assert.IsNotNull(flv1);
            Assert.IsNotNull(flv2);

            Assert.AreEqual("1", flv1.Id);
            Assert.AreEqual(new Uri("http://server.com/flavors/1"), flv1.PermanentUri);
            Assert.AreEqual(new Uri("http://server.com/v2/flavors/1"), flv1.PublicUri);

            Assert.AreEqual("2", flv2.Id);
            Assert.AreEqual(new Uri("http://server.com/flavors/2"), flv2.PermanentUri);
            Assert.AreEqual(new Uri("http://server.com/v2/flavors/2"), flv2.PublicUri);
        }
        public void CannotConvertJsonPayloadMissingNameToFlavor()
        {
            var missingTokenFixture = @"{
                                    ""flavor"": {
                                        ""name"" : ""m1.tiny"",
                                        ""links"": [
                                            {
                                                ""href"": ""http://someuri.com/v2/flavors/1"",
                                                ""rel"": ""self""
                                            },
                                            {
                                                ""href"": ""http://someuri.com/flavors/1"",
                                                ""rel"": ""bookmark""
                                            }
                                        ],
                                        ""ram"": 512,
                                        ""vcpus"": 2,
                                        ""disk"": 10
                                    }
                                }";

            var converter = new ComputeFlavorPayloadConverter();

            converter.ConvertFlavor(missingTokenFixture);
        }
        public void CannotConvertNonObjectJsonToFlavor()
        {
            var nonObjectJson = @"[]";

            var converter = new ComputeFlavorPayloadConverter();

            converter.ConvertFlavor(nonObjectJson);
        }
        public void CannotConvertJsonPayloadEmptyObjectToFlavor()
        {
            var emptyObjectFixture = @"{ }";

            var converter = new ComputeFlavorPayloadConverter();

            converter.ConvertFlavor(emptyObjectFixture);
        }
        public void CannotConvertInvalidJsonToFlavor()
        {
            var badJsonFixture = @"{ NOT JSON";

            var converter = new ComputeFlavorPayloadConverter();

            converter.ConvertFlavor(badJsonFixture);
        }
        public void CanParseAnEmptyFlavorsPayload()
        {
            var payload = string.Empty;

            var converter  = new ComputeFlavorPayloadConverter();
            var containers = converter.ConvertFlavors(payload).ToList();

            Assert.AreEqual(0, containers.Count());
        }
        public void CanParseValidFlavorsPayloadWithEmptyJsonArray()
        {
            var emptyJsonArray = @"{ ""flavors"": [ ] }";

            var converter  = new ComputeFlavorPayloadConverter();
            var containers = converter.ConvertFlavors(emptyJsonArray).ToList();

            Assert.AreEqual(0, containers.Count());
        }
 public void CannotParseInvalidFlavorsJsonPayload()
 {
     var converter = new ComputeFlavorPayloadConverter();
     converter.ConvertFlavors("[ { \"SomeAtrib\" }]");
 }
 public void CannotParseANullFlavorsPayload()
 {
     var converter = new ComputeFlavorPayloadConverter();
     converter.ConvertFlavors(null);
 }
        public void CanParseAnEmptyFlavorsPayload()
        {
            var payload = string.Empty;

            var converter = new ComputeFlavorPayloadConverter();
            var containers = converter.ConvertFlavors(payload).ToList();

            Assert.AreEqual(0, containers.Count());
        }
        public void CanParseValidFlavorsPayloadWithEmptyJsonArray()
        {
            var emptyJsonArray = @"{ ""flavors"": [ ] }";

            var converter = new ComputeFlavorPayloadConverter();
            var containers = converter.ConvertFlavors(emptyJsonArray).ToList();

            Assert.AreEqual(0, containers.Count());
        }
        public void CanConvertValidFlavorsJsonPayloadWithSingleFlavor()
        {
            var validFlavorsJsonFixture = @"{{ ""flavors"": [ {0} ] }}";
            var firstFlavor = CreateFlavorSummaryJsonFixtrue("m1.tiny", "1", "http://server.com/flavors/1",
                "http://server.com/v2/flavors/1");
            var validMultipleFlavorsJson = string.Format(validFlavorsJsonFixture, firstFlavor);

            var converter = new ComputeFlavorPayloadConverter();
            var flavors = converter.ConvertFlavors(validMultipleFlavorsJson).ToList();

            Assert.AreEqual(1, flavors.Count());
            var flv1 =
                flavors.First(o => string.Equals(o.Name, "m1.tiny", StringComparison.InvariantCultureIgnoreCase));
           
            Assert.IsNotNull(flv1);

            Assert.AreEqual("1", flv1.Id);
            Assert.AreEqual(new Uri("http://server.com/flavors/1"), flv1.PermanentUri);
            Assert.AreEqual(new Uri("http://server.com/v2/flavors/1"), flv1.PublicUri);
        }
        public void CannotConvertNonObjectJsonToFlavor()
        {
            var nonObjectJson = @"[]";

            var converter = new ComputeFlavorPayloadConverter();
            converter.ConvertFlavor(nonObjectJson);
        }
        public void CannotConvertInvalidJsonToFlavor()
        {
            var badJsonFixture = @"{ NOT JSON";

            var converter = new ComputeFlavorPayloadConverter();
            converter.ConvertFlavor(badJsonFixture);
        }
        public void CannotConvertJsonPayloadEmptyObjectToFlavor()
        {
            var emptyObjectFixture = @"{ }";

            var converter = new ComputeFlavorPayloadConverter();
            converter.ConvertFlavor(emptyObjectFixture);
        }
        public void CannotConvertJsonPayloadMissingNameToFlavor()
        {
            var missingTokenFixture = @"{
                                    ""flavor"": {
                                        ""name"" : ""m1.tiny"",
                                        ""links"": [
                                            {
                                                ""href"": ""http://someuri.com/v2/flavors/1"",
                                                ""rel"": ""self""
                                            },
                                            {
                                                ""href"": ""http://someuri.com/flavors/1"",
                                                ""rel"": ""bookmark""
                                            }
                                        ],
                                        ""ram"": 512,
                                        ""vcpus"": 2,
                                        ""disk"": 10
                                    }
                                }";

            var converter = new ComputeFlavorPayloadConverter();
            converter.ConvertFlavor(missingTokenFixture);
        }
 public void CannotParseInvalidFlavorsPayload()
 {
     var converter = new ComputeFlavorPayloadConverter();
     converter.ConvertFlavors("NOT JSON");
 }
        public void CannotParseInvalidFlavorsPayload()
        {
            var converter = new ComputeFlavorPayloadConverter();

            converter.ConvertFlavors("NOT JSON");
        }
        public void CannotParseInvalidFlavorsJsonPayload()
        {
            var converter = new ComputeFlavorPayloadConverter();

            converter.ConvertFlavors("[ { \"SomeAtrib\" }]");
        }
        public void CannotParseANullFlavorsPayload()
        {
            var converter = new ComputeFlavorPayloadConverter();

            converter.ConvertFlavors(null);
        }
        public void CanConvertJsonPayloadToFlavor()
        {
            var flavorName = "m1.tiny";
            var flavorId = "1";
            var flavorPublicUri = "http://www.server.com/v2/flavors/1";
            var flavorPermUri = "http://www.server.com/flavors/1";
            var flavorRam = "512";
            var flavorDisk = "10";
            var flavorVcpus = "2";

            var computeFlavorJsonResponseFixture = CreateFlavorJsonFixtrue(flavorName, flavorId, flavorRam, flavorDisk,
                flavorVcpus, flavorPermUri, flavorPublicUri);

            var converter = new ComputeFlavorPayloadConverter();
            var flavor = converter.ConvertFlavor(computeFlavorJsonResponseFixture);
            Assert.IsNotNull(flavor);
            Assert.AreEqual(flavorName, flavor.Name);
            Assert.AreEqual(flavorId, flavor.Id);
            Assert.AreEqual(flavorRam, flavor.Ram);
            Assert.AreEqual(flavorVcpus, flavor.Vcpus);
            Assert.AreEqual(flavorDisk, flavor.Disk);
            Assert.AreEqual(new Uri(flavorPermUri), flavor.PermanentUri);
            Assert.AreEqual(new Uri(flavorPublicUri), flavor.PublicUri);
        }
        public void CanConvertJsonPayloadMissingDiskToFlavor()
        {
            var missingFixture = @"{
                                    ""flavor"": {
                                        ""name"": ""m1.tiny"",
                                        ""id"": ""1"",
                                        ""links"": [
                                            {
                                                ""href"": ""http://someuri.com/v2/flavors/1"",
                                                ""rel"": ""self""
                                            },
                                            {
                                                ""href"": ""http://someuri.com/flavors/1"",
                                                ""rel"": ""bookmark""
                                            }
                                        ],
                                        ""ram"": 512,
                                        ""vcpus"": 2
                                    }
                                }";

            var converter = new ComputeFlavorPayloadConverter();
            var flavor = converter.ConvertFlavor(missingFixture);
            Assert.IsNotNull(flavor);
            Assert.AreEqual("m1.tiny", flavor.Name);
            Assert.AreEqual("1", flavor.Id);
            Assert.AreEqual("512", flavor.Ram);
            Assert.AreEqual("2", flavor.Vcpus);
            Assert.AreEqual(new Uri("http://someuri.com/flavors/1"), flavor.PermanentUri);
            Assert.AreEqual(new Uri("http://someuri.com/v2/flavors/1"), flavor.PublicUri);
        }