public static void TestAddingKeyValuePairsCollectionAfterInitialization() { var employees = new JsonObject(); employees.AddRange(EmployeesDatabase.GetTenBestEmployees()); CheckEmployeesAreDifferent(employees); }
public static void TestAddingKeyValuePairAfterInitialization() { var employees = new JsonObject(); foreach (KeyValuePair <string, JsonNode> employee in EmployeesDatabase.GetTenBestEmployees()) { employees.Add(employee); } CheckEmployeesAreDifferent(employees); }
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; } }
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); } }
/// <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); }
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; } }