Ejemplo n.º 1
0
        public void TestCreateJSONArrayParams()
        {
            // The expected JSON String
            String expected = "\"cars\": [Saab,Volvo,BMW]";
            // The actual JSON String
            String actual = JSONWriter.CreateJSONArray("cars", "Saab", "Volvo", "BMW");

            // Ensure the expected JSON String and the actual JSON String are equal
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 2
0
        public void TestCreateJSONArrayList()
        {
            // The key of the JSON array
            String key = "cars";
            // The values within the array
            List <String> elements = new List <String>(new String[] { "Saab", "Volvo", "BMW" });
            // The expected JSON String
            String expected = "\"cars\": [Saab,Volvo,BMW]";
            // The actual JSON String
            String actual = JSONWriter.CreateJSONArray(key, elements);

            // 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));
        }
Ejemplo n.º 5
0
        /// <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));
        }