public void TestCreateJSONObjectElements() { // The expected JSON String String expected = "{ apple, banana, pear }"; // The actual JSON String String actual = JSONWriter.CreateJSONObject("apple", "banana", "pear"); // Ensure the expected JSON String and the actual JSON String are equal Assert.AreEqual(expected, actual); }
public void TestCreateJSONObjectKeyValue() { // The expected JSON String String expected = "{ \"name\": \"Dave\", \"age\": \"30\" }"; //The input data String name = JSONWriter.CreateKeyValue("name", "Dave"); String age = JSONWriter.CreateKeyValue("age", "30"); // The actual JSON String String actual = JSONWriter.CreateJSONObject(name, age); // Ensure the expected JSON String and the actual JSON String are equal Assert.AreEqual(expected, actual); }
/// <summary> /// This method will merge all the Fail MixBand JSON formatted strings for /// each given week within this object. The method will the ultimatley /// return a new JSON string which will contain the multi-week analysis. /// </summary> /// <returns>A well formed JSON string</returns> private String MergeFailMixBandJSON() { // Stores all the JSON strings for each week List <String> weeks = new List <String>(); // Loop over each week foreach (KeyValuePair <int, WeekAnalysis> pair in WeeklyAnalysis) { // Create the JSON String String json = pair.Value.CreateFailMixBandJSON(); // Add the string to the list of weeks weeks.Add(json); } // Create the name of the data structure String name = JSONWriter.CreateKeyValue("name", "Fail Events Mix-Band Usage"); // Create the children JSON array String children = JSONWriter.CreateJSONArray("children", weeks); // Create and return the final JSON object return(JSONWriter.CreateJSONObject(name, children)); }
/// <summary> /// This method will merge all the Fail RAT JSON formatted strings for each /// given device within this object. The method will ultimately return a /// new JSON string which will contain the multi-device analysis. /// </summary> /// <returns>A well formed JSON string</returns> private String MergeFailRATJSON() { // Stores all the JSON strings for each device List <String> devices = new List <String>(); // Loop over each week foreach (KeyValuePair <String, ProductAnalysis> pair in ProductsAnalysis) { // Create the JSON String String json = pair.Value.CreateFailRATJSON(); // Add the string to the list of weeks devices.Add(json); } // Create the name of the data structure String name = JSONWriter.CreateKeyValue("name", "Fail Events RAT Usage"); // Create the children JSON array String children = JSONWriter.CreateJSONArray("children", devices); // Create and return the final JSON object return(JSONWriter.CreateJSONObject(name, children)); }
/// <summary> /// This method will return a well formatted JSON String based upon the /// elements that are held within this object. /// </summary> /// <returns>A well formatted JSON String</returns> public override String ToString() { // List of each JSON cluster List <String> clusters = new List <String>(); // Loop over each of the clusters foreach (KeyValuePair <int, AnalysisResultsCollection> pair in this) { // Generate the cluster name String cluster_name = JSONWriter.CreateKeyValue("name", "Cluster " + pair.Key); // Used to store the children JSON array List <String> cluster_children = new List <String>(); // Loop over the children data (E.g. 2G, or 3G, or Freq1) foreach (KeyValuePair <String, AnalysisResults> results in pair.Value) { // Generate the name String name = JSONWriter.CreateKeyValue("name", results.Key); // Generate the Children array String children = JSONWriter.CreateJSONArray("children", results.Value.ToJSON()); // merge the two above together String element = JSONWriter.CreateJSONObject(name, children); // Add to the cluster cluster_children.Add(element); } // Merge all the children values into an Array String children_values = JSONWriter.CreateJSONArray("children", cluster_children); // Create the cluster JSON Object String cluster = JSONWriter.CreateJSONObject(cluster_name, children_values); // Add the cluster JSON object to all the known clusters clusters.Add(cluster); } // Format the key (either the device name or the week number) String key = GetDataKey(); // Format the children data String data = JSONWriter.CreateJSONArray("children", clusters); // Final Formatting of the string return(JSONWriter.CreateJSONObject(key, data)); }