public IEnumerator TestStringEscapingInSerialization_WithJObject_DataSerializeCorrectly()
        {
            // this test should validate if we can escape correctly strings from user predefined values

            var sampleObject = new BaseJObject()
            {
                InnerObject = new SampleObject()
                {
                    AgentName  = "\"\\!@#$%^&*()+_=-{}{[]:\\\n\r\f\r ",
                    TestString = "\b\t\\\n\"''"
                }
            };
            var jObject      = new BacktraceJObject();
            var innerJObject = new BacktraceJObject();

            innerJObject.Add("AgentName", sampleObject.InnerObject.AgentName);
            innerJObject.Add("TestString", sampleObject.InnerObject.TestString);
            jObject.Add("InnerObject", innerJObject);


            var json       = jObject.ToJson();
            var jsonObject = JsonUtility.FromJson <BaseJObject>(json);

            Assert.IsNotNull(jsonObject);
            Assert.AreEqual(sampleObject.InnerObject.AgentName, jsonObject.InnerObject.AgentName);
            Assert.AreEqual(sampleObject.InnerObject.TestString, jsonObject.InnerObject.TestString);
            yield return(null);
        }
        public IEnumerator TestDataSerialization_WithOnlyJObject_DataSerializeCorrectly()
        {
            // this test should validate if we can start analysing new data type without previous data types
            var sampleObject = new BaseJObject()
            {
                InnerObject = new SampleObject()
                {
                    Active = true
                }
            };

            var sampleJObject = new BacktraceJObject();
            var innerJObject  = new BacktraceJObject();

            innerJObject.Add("Active", sampleObject.InnerObject.Active);
            sampleJObject.Add("InnerObject", innerJObject);


            var json       = sampleJObject.ToJson();
            var jsonObject = JsonUtility.FromJson <BaseJObject>(json);

            Assert.IsNotNull(jsonObject);
            Assert.IsNotNull(jsonObject.InnerObject);
            Assert.IsTrue(jsonObject.InnerObject.Active);
            yield return(null);
        }
        public IEnumerator TestDataSerialization_WithInnerJObjectAndComplexArray_DataSerializeCorrectly()
        {
            // this test should validate if we can start analysing new data type without previous data types
            var sampleObject = new BaseJObject()
            {
                InnerObject = new SampleObject()
                {
                    NumberArray = new int[] { 1, 2, 3, 4 }
                }
            };

            var sampleJObject = new BacktraceJObject();
            var innerJObject  = new BacktraceJObject();

            innerJObject.Add("NumberArray", sampleObject.InnerObject.NumberArray);
            sampleJObject.Add("InnerObject", innerJObject);


            var json       = sampleJObject.ToJson();
            var jsonObject = JsonUtility.FromJson <BaseJObject>(json);

            Assert.IsNotNull(jsonObject);
            Assert.IsNotNull(jsonObject.InnerObject);
            // validate number array
            for (int i = 0; i < jsonObject.InnerObject.NumberArray.Length; i++)
            {
                Assert.AreEqual(jsonObject.InnerObject.NumberArray[i], jsonObject.InnerObject.NumberArray[i]);
            }
            yield return(null);
        }
        public IEnumerator TestDataSerialization_WithAllTypeOfPossibleJsonTypes_DataSerializeCorrectly()
        {
            var sampleObject = new BaseJObject()
            {
                InnerObject = new SampleObject()
                {
                    Active       = true,
                    AgentName    = "Backtrace-unity",
                    IntNumber    = 1,
                    FloatNumber  = 12.123f,
                    DoubleNumber = 555.432d,
                    LongNumber   = 999,
                    NumberArray  = new int[] { 1, 2, 3, 4 },
                    StringArray  = new string[] { string.Empty, null, "foo", "bar" },
                    StringList   = new List <string> {
                        string.Empty, null, "foo", "bar"
                    }
                }
            };

            var sampleJObject = new BacktraceJObject();
            var innerJObject  = new BacktraceJObject();

            innerJObject.Add("AgentName", sampleObject.InnerObject.AgentName);
            innerJObject.Add("Active", sampleObject.InnerObject.Active);
            innerJObject.Add("IntNumber", sampleObject.InnerObject.IntNumber);
            innerJObject.Add("FloatNumber", sampleObject.InnerObject.FloatNumber);
            innerJObject.Add("DoubleNumber", sampleObject.InnerObject.DoubleNumber);
            innerJObject.Add("LongNumber", sampleObject.InnerObject.LongNumber);
            innerJObject.Add("NumberArray", sampleObject.InnerObject.NumberArray);
            innerJObject.Add("StringArray", sampleObject.InnerObject.StringArray);
            innerJObject.Add("StringList", sampleObject.InnerObject.StringList);

            sampleJObject.Add("InnerObject", innerJObject);


            var json       = sampleJObject.ToJson();
            var jsonObject = JsonUtility.FromJson <BaseJObject>(json);

            // validate number array
            var jsonInnerObject = jsonObject.InnerObject;

            for (int i = 0; i < sampleObject.InnerObject.NumberArray.Length; i++)
            {
                Assert.AreEqual(sampleObject.InnerObject.NumberArray[i], jsonInnerObject.NumberArray[i]);
            }
            // validate string array
            for (int i = 0; i < sampleObject.InnerObject.StringArray.Length; i++)
            {
                // handle empty strings
                var expectedValue = string.IsNullOrEmpty(sampleObject.InnerObject.StringArray[i]) ? string.Empty : sampleObject.InnerObject.StringArray[i];
                Assert.AreEqual(expectedValue, jsonInnerObject.StringArray[i]);
            }

            // validate string list
            for (int i = 0; i < sampleObject.InnerObject.StringList.Count; i++)
            {
                // handle empty strings
                var expectedValue = string.IsNullOrEmpty(sampleObject.InnerObject.StringList[i]) ? string.Empty : sampleObject.InnerObject.StringList[i];
                Assert.AreEqual(expectedValue, jsonInnerObject.StringList[i]);
            }


            Assert.AreEqual(sampleObject.InnerObject.AgentName, jsonObject.InnerObject.AgentName);
            Assert.AreEqual(sampleObject.InnerObject.Active, jsonObject.InnerObject.Active);
            Assert.AreEqual(sampleObject.InnerObject.IntNumber, jsonObject.InnerObject.IntNumber);
            Assert.AreEqual(sampleObject.InnerObject.FloatNumber, jsonObject.InnerObject.FloatNumber);
            Assert.AreEqual(sampleObject.InnerObject.DoubleNumber, jsonObject.InnerObject.DoubleNumber);
            Assert.AreEqual(sampleObject.InnerObject.LongNumber, jsonObject.InnerObject.LongNumber);
            yield return(null);
        }