Exemplo n.º 1
0
        public void ISerializable()
        {
            byte[] buffer = new byte[20480];
            var    writer = new BufferValueWriter(buffer);

            SerializableTester tester = new SerializableTester
            {
                Name    = "MONKEY!",
                Numbers = new[] { 1, 2, 4, 8, 16, 32 }
            };

            var test = new AsyncTest();

            tester.SerializeCalled += test.PassHandler;

            writer.Write(context, tester);
            writer.Flush();

            var reader     = new BufferValueReader(buffer);
            var serialized = SerializerExtensions.Read <SerializableTester> (reader, context);

            Assert.IsNotNull(serialized);
            Assert.AreEqual(tester.Name, serialized.Name);
            Assert.IsTrue(tester.Numbers.SequenceEqual(serialized.Numbers), "Numbers does not match");

            test.Assert(1000);
        }
Exemplo n.º 2
0
        // [Test] Testing core APIs that now have NETFX_CORE turned on everywhere
        public void Serializable()
        {
            var inner = new Exception("Inner exception");
            var ex    = new InvalidOperationException("Don't do this, fool.", inner);

            byte[] buffer = new byte[20480];
            var    writer = new BufferValueWriter(buffer);

            writer.Write(context, ex);
            writer.Flush();

            var reader = new BufferValueReader(buffer);

            InvalidOperationException ioex = SerializerExtensions.Read <InvalidOperationException> (reader, context);

            Assert.IsNotNull(ioex);
            Assert.AreEqual(ex.Message, ioex.Message);
            Assert.AreEqual(ex.StackTrace, ioex.StackTrace);

            Assert.IsNotNull(ioex.InnerException);
            Assert.AreEqual(inner.Message, ioex.InnerException.Message);
            Assert.AreEqual(inner.StackTrace, ioex.InnerException.StackTrace);
        }