示例#1
0
        public void Test_AllFieldsEqual()
        {
            var r1 = new AllArowTypesRow {
                Bool3 = new bool[] { true, false, true }
            };
            var r2 = new AllArowTypesRow {
                Bool3 = new bool[] { true, false }
            };

            Aver.IsFalse(r1.AllFieldsEqual(r2));

            r1 = new AllArowTypesRow {
                Bool3 = new bool[] { true, false }
            };
            r2 = new AllArowTypesRow {
                Bool3 = new bool[] { true, false, true }
            };
            Aver.IsFalse(r1.AllFieldsEqual(r2));

            r1 = new AllArowTypesRow {
                Bool4 = new List <bool> {
                    true, false, true
                }
            };
            r2 = new AllArowTypesRow {
                Bool4 = new List <bool> {
                    false
                }
            };
            Aver.IsFalse(r1.AllFieldsEqual(r2));

            r1 = new AllArowTypesRow {
                Bool4 = new List <bool> {
                    true
                }
            };
            r2 = new AllArowTypesRow {
                Bool4 = new List <bool> {
                    false
                }
            };
            Aver.IsFalse(r1.AllFieldsEqual(r2));

            r1 = new AllArowTypesRow {
                Bool4 = new List <bool> {
                    true
                }
            };
            r2 = new AllArowTypesRow {
                Bool4 = new List <bool> {
                    true
                }
            };
            Aver.IsTrue(r1.AllFieldsEqual(r2));
        }
示例#2
0
        public void OneByOne()
        {
            var writer = SlimFormat.Instance.GetWritingStreamer();
            var reader = SlimFormat.Instance.GetReadingStreamer();
            var fail   = "";

            using (var ms = new MemoryStream())
            {
                for (var i = 0; i < CASES.Length; i++)
                {
                    var row1 = CASES[i];

                    Console.WriteLine("Test #{0}".Args(i));
                    Console.WriteLine("--------------------------------------------------");
                    Console.WriteLine(row1.ToJSON());


                    ms.Position = 0;

                    writer.BindStream(ms);
                    ArowSerializer.Serialize(row1, writer);
                    writer.UnbindStream();

                    ms.Position = 0;

                    var row2 = new AllArowTypesRow();
                    reader.BindStream(ms);
                    ArowSerializer.Deserialize(row2, reader);
                    reader.UnbindStream();

                    if (!row1.AllFieldsEqual(row2))
                    {
                        Console.WriteLine(row2.ToJSON());
                        Console.WriteLine("FAIL");
                        fail = "The test case #{0} has failed.\nJSON:\n{1}".Args(i, row1.ToJSON());
                    }
                    else
                    {
                        Console.WriteLine("PASS");
                    }

                    Console.WriteLine();
                }
                if (fail.IsNotNullOrWhiteSpace())
                {
                    Aver.Fail(fail);
                }
            }
        }
示例#3
0
        public bool AllFieldsEqual(AllArowTypesRow other)
        {
            foreach (var def in this.Schema)
            {
                var v1 = this.GetFieldValue(def);
                var v2 = other.GetFieldValue(def);
                if (v1 == null)
                {
                    if (v2 == null)
                    {
                        continue;
                    }
                    else
                    {
                        return(false);
                    }
                }

                if (v1 is IEnumerable)
                {
                    var ev1 = (IEnumerable)v1;
                    var ev2 = (IEnumerable)v2;

                    var e1 = ev1.GetEnumerator();
                    var e2 = ev2.GetEnumerator();

                    while (true)
                    {
                        var has1 = e1.MoveNext();
                        var has2 = e2.MoveNext();
                        if (has1 != has2)
                        {
                            return(false);
                        }
                        if (!has1)
                        {
                            break;
                        }

                        var cv1 = e1.Current;
                        var cv2 = e2.Current;
                        if (cv1 == null)
                        {
                            if (cv2 == null)
                            {
                                continue;
                            }
                            else
                            {
                                return(false);
                            }
                        }

                        if (!cv1.Equals(cv2))
                        {
                            return(false);
                        }
                    }
                    continue;
                }

                if (!v1.Equals(v2))
                {
                    return(false);
                }
            }

            return(true);
        }