Ejemplo n.º 1
0
        public void Complex_Object_Test()
        {
            Foo foo1 = new Foo {
                A = "A",
                B = "B",
                C = 1
            };

            foo1.FooField = foo1;

            Foo foo2 = new Foo {
                A = "A",
                B = "B",
                C = 1
            };

            foo2.FooField = foo2;
            var result = DeepComparer.Compare((object)foo1, (object)foo2);

            Assert.True(result);

            foo1.A = "AA";

            result = DeepComparer.Compare(foo1, foo2);

            Assert.False(result);
        }
Ejemplo n.º 2
0
        public void Array_Test()
        {
            var array1 = new string[] { "A", "B" };

            var array2 = new string[] { "A", "B" };

            var result = DeepComparer.Compare((object)array1, (object)array2);

            Assert.True(result);


            array1[1] = "C";

            result = DeepComparer.Compare(array1, array2);

            Assert.False(result);

            var obj1 = new int[2, 1, 3] {
                { { 1, 2, 3 } }, { { 4, 5, 6 } }
            };

            var obj2 = new int[2, 1, 3] {
                { { 1, 2, 3 } }, { { 4, 5, 6 } }
            };

            result = DeepComparer.Compare((object)obj1, (object)obj2);

            Assert.True(result);
        }
        public void Test1()
        {
            var o = new Test
            {
                String   = "MyTest",
                Integer  = 5,
                Float    = 4.5f,
                Children = new List <Test>
                {
                    new Test {
                        String = "Child1"
                    },
                    new Test {
                        String = "Child2"
                    }
                }
            };
            var formatter = new XmlFormatter();
            var m         = new MemoryStream();

            formatter.Serialize(m, o);
            m.Position = 0;
            System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
            var d = (Test)formatter.Deserialize(m);

            Assert.IsTrue(DeepComparer.Compare(o, d));
        }
Ejemplo n.º 4
0
        public void Request_Deserialize_Serialize()
        {
            var stream     = Assembly.GetExecutingAssembly().GetManifestResourceStream("WebApiContribTests.Data.Request");
            var serializer = new MessageContentHttpMessageSerializer();
            var request    = serializer.DeserializeToRequestAsync(stream).Result;

            var memoryStream = new MemoryStream();

            serializer.SerializeAsync(request, memoryStream).Wait();

            memoryStream.Position = 0;
            var request2 = serializer.DeserializeToRequestAsync(memoryStream).Result;
            var result   = DeepComparer.Compare(request, request2);

            if (result.Count() > 0)
            {
                Assert.Fail(string.Join("\r\n", result));
            }
        }
Ejemplo n.º 5
0
        public async Task Response_Deserialize_Serialize()
        {
            var stream     = Assembly.GetExecutingAssembly().GetManifestResourceStream("WebApiContribTests.Data.Response");
            var serializer = new MessageContentHttpMessageSerializer();
            var response   = await serializer.DeserializeToResponseAsync(stream);

            var memoryStream = new MemoryStream();
            await serializer.SerializeAsync(Task.FromResult(response), memoryStream);

            memoryStream.Position = 0;
            var response2 = await serializer.DeserializeToResponseAsync(memoryStream);

            var result = DeepComparer.Compare(response, response2);

            if (result.Count() > 0)
            {
                Assert.Fail(string.Join("\r\n", result));
            }
        }