Пример #1
0
        public void UtilizationHashWithSingleConfigHashEntrySerializesCorrectly()
        {
            var vendors       = new Dictionary <string, IVendorModel>();
            var config        = new UtilitizationConfig(null, null, 2048);
            var settingsModel = new UtilizationSettingsModel(4, 1024 * 1024 * 1024, "lo-calhost", "lo-calhost.domain.com", new List <string> {
                "1.2.3.4", "5.6.7.8"
            }, null, vendors, config);

            // ACT
            var actualJson = JsonConvert.SerializeObject(settingsModel);

            var expectedObject = new Dictionary <string, object>
            {
                { "metadata_version", 5 },
                { "logical_processors", 4 },
                { "total_ram_mib", 1024 },
                { "hostname", "lo-calhost" },
                { "full_hostname", "lo-calhost.domain.com" },
                { "ip_address", new[] { "1.2.3.4", "5.6.7.8" } },
                {
                    "config", new Dictionary <string, object>
                    {
                        { "total_ram_mib", 2048 }
                    }
                }
            };
            var expectedJson = JsonConvert.SerializeObject(expectedObject);

            Assert.AreEqual(expectedJson, actualJson, string.Format("Expected {0}, but was {1}.", expectedJson, JsonConvert.SerializeObject(settingsModel)));
        }
Пример #2
0
        public void when_default_fixture_values_are_used_then_serializes_correctly()
        {
            var vendors = new Dictionary <string, IVendorModel>
            {
                { "aws", new AwsVendorModel("myZone", "myInstanceId", "myInstanceType") },
                { "azure", new AzureVendorModel("myLocation", "myName", "myVmId", "myVmSize") },
                { "gcp", new GcpVendorModel("myId", "myMachineType", "myName", "myZone") },
                { "pcf", new PcfVendorModel("myInstanceGuid", "myInstanceIp", "myMemoryLimit") },
                { "docker", new DockerVendorModel("myBootId") },
                { "kubernetes", new KubernetesVendorModel("10.96.0.1") }
            };
            var config        = new UtilitizationConfig("loc-alhost", 2, 2048);
            var settingsModel = new UtilizationSettingsModel(4, 1024 * 1024 * 1024, "lo-calhost", "lo-calhost.domain.com", new List <string> {
                "1.2.3.4", "5.6.7.8"
            }, null, vendors, config);

            // ACT
            var actualJson = JsonConvert.SerializeObject(settingsModel);

            var expectedObject = new Dictionary <string, object>
            {
                { "metadata_version", 5 },
                { "logical_processors", 4 },
                { "total_ram_mib", 1024 },
                { "hostname", "lo-calhost" },
                { "full_hostname", "lo-calhost.domain.com" },
                { "ip_address", new[] { "1.2.3.4", "5.6.7.8" } },
                {
                    "config", new Dictionary <string, object>
                    {
                        { "hostname", "loc-alhost" },
                        { "logical_processors", 2 },
                        { "total_ram_mib", 2048 }
                    }
                },
                {
                    "vendors", new Dictionary <string, object>
                    {
                        {
                            "aws", new Dictionary <string, object>
                            {
                                { "availabilityZone", "myZone" },
                                { "instanceId", "myInstanceId" },
                                { "instanceType", "myInstanceType" }
                            }
                        },
                        {
                            "azure", new Dictionary <string, object>
                            {
                                { "location", "myLocation" },
                                { "name", "myName" },
                                { "vmId", "myVmId" },
                                { "vmSize", "myVmSize" }
                            }
                        },
                        {
                            "gcp", new Dictionary <string, object>
                            {
                                { "id", "myId" },
                                { "machineType", "myMachineType" },
                                { "name", "myName" },
                                { "zone", "myZone" }
                            }
                        },
                        {
                            "pcf", new Dictionary <string, object>
                            {
                                { "cf_instance_guid", "myInstanceGuid" },
                                { "cf_instance_ip", "myInstanceIp" },
                                { "memory_limit", "myMemoryLimit" }
                            }
                        },
                        {
                            "docker", new Dictionary <string, object>
                            {
                                { "id", "myBootId" }
                            }
                        },
                        {
                            "kubernetes", new Dictionary <string, object>
                            {
                                { "kubernetes_service_host", "10.96.0.1" }
                            }
                        }
                    }
                }
            };
            var expectedJson = JsonConvert.SerializeObject(expectedObject);

            Assert.AreEqual(expectedJson, actualJson, string.Format("Expected {0}, but was {1}.", expectedJson, JsonConvert.SerializeObject(settingsModel)));
        }