コード例 #1
0
        public static void TestAddingKeyValuePairsCollectionAfterInitialization()
        {
            var employees = new JsonObject();

            employees.AddRange(EmployeesDatabase.GetTenBestEmployees());

            CheckEmployeesAreDifferent(employees);
        }
コード例 #2
0
        public static void TestAddingKeyValuePairAfterInitialization()
        {
            var employees = new JsonObject();

            foreach (KeyValuePair <string, JsonNode> employee in EmployeesDatabase.GetTenBestEmployees())
            {
                employees.Add(employee);
            }

            CheckEmployeesAreDifferent(employees);
        }
コード例 #3
0
        public static void TestAddingKeyValuePair()
        {
            var employees = new JsonObject
            {
                EmployeesDatabase.GetNextEmployee(),
                EmployeesDatabase.GetNextEmployee(),
                EmployeesDatabase.GetNextEmployee(),
                EmployeesDatabase.GetNextEmployee(),
            };

            CheckEmployeesAreDifferent(employees);
        }
コード例 #4
0
ファイル: JsonArrayTests.cs プロジェクト: zhongjn/corefx
        public static void TestCreatingJsonArrayFromCollectionOfString()
        {
            var employeesIds = new JsonArray(EmployeesDatabase.GetTenBestEmployees().Select(employee => employee.Key));

            JsonString prevId = new JsonString();

            foreach (JsonNode employeeId in employeesIds)
            {
                var employeeIdString = (JsonString)employeeId;
                Assert.NotEqual(prevId, employeeIdString);
                prevId = employeeIdString;
            }
        }
コード例 #5
0
        public static void TestAquiringAllValues()
        {
            var employees = new JsonObject(EmployeesDatabase.GetTenBestEmployees());
            IReadOnlyCollection <JsonNode> employeesWithoutId = employees.GetPropertyValues();

            Assert.Equal(10, employees.GetPropertyNames().Count);
            Assert.Equal(10, employees.GetPropertyValues().Count);

            foreach (JsonNode employee in employeesWithoutId)
            {
                Assert.IsType <JsonObject>(employee);
            }
        }
コード例 #6
0
ファイル: JsonNodeTestData.cs プロジェクト: zhongjn/corefx
        /// <summary>
        /// Returns following JsonObject:
        /// {
        ///     { "name" : "John" }
        ///     { "phone numbers" : { "work" :  "425-555-0123", "home": "425-555-0134"  } }
        ///     {
        ///         "reporting employees" :
        ///         {
        ///             "software developers" :
        ///             {
        ///                 "full time employees" : /JsonObject of 3 employees fromk database/
        ///                 "intern employees" : /JsonObject of 2 employees fromk database/
        ///             },
        ///             "HR" : /JsonObject of 10 employees fromk database/
        ///         }
        /// </summary>
        /// <returns></returns>
        public static JsonObject GetManager()
        {
            var manager = GetNextEmployee().Value as JsonObject;

            manager.Add
            (
                "phone numbers",
                new JsonObject()
            {
                { "work", "425-555-0123" }, { "home", "425-555-0134" }
            }
            );

            manager.Add
            (
                "reporting employees", new JsonObject()
            {
                {
                    "software developers", new JsonObject()
                    {
                        {
                            "full time employees", new JsonObject()
                            {
                                EmployeesDatabase.GetNextEmployee(),
                                EmployeesDatabase.GetNextEmployee(),
                                EmployeesDatabase.GetNextEmployee(),
                            }
                        },
                        {
                            "intern employees", new JsonObject()
                            {
                                EmployeesDatabase.GetNextEmployee(),
                                EmployeesDatabase.GetNextEmployee(),
                            }
                        }
                    }
                },
                {
                    "HR", new JsonObject()
                    {
                        {
                            "full time employees", new JsonObject(EmployeesDatabase.GetTenBestEmployees())
                        }
                    }
                }
            }
            );

            return(manager);
        }
コード例 #7
0
ファイル: JsonArrayTests.cs プロジェクト: zhongjn/corefx
        public static void TestAddingToJsonArray()
        {
            var employeesIds = new JsonArray();

            foreach (KeyValuePair <string, JsonNode> employee in EmployeesDatabase.GetTenBestEmployees())
            {
                employeesIds.Add(employee.Key);
            }

            JsonString prevId = new JsonString();

            foreach (JsonNode employeeId in employeesIds)
            {
                var employeeIdString = (JsonString)employeeId;
                Assert.NotEqual(prevId, employeeIdString);
                prevId = employeeIdString;
            }
        }
コード例 #8
0
 public static void TestModifyingJsonObjectKeyRemoveAdd()
 {
     JsonObject manager            = EmployeesDatabase.GetManager();
     JsonObject reportingEmployees = manager.GetJsonObjectPropertyValue("reporting employees");
コード例 #9
0
        public static void TestAssignmentDefinition()
        {
            JsonNode employee = EmployeesDatabase.GetNextEmployee().Value;

            Assert.IsType <JsonObject>(employee);
        }