Beispiel #1
0
        public void DeserializationTransform1()
        {
            using(var ms = new MemoryStream())
               {
                var s = new PODSlimSerializer();

                var originalData = new PODTest_Ver1
                {
                    Name = "Xerson Person",
                    Description = "Some description",
                    Age = 25
                };

                s.Serialize(ms, originalData);
                ms.Seek(0, SeekOrigin.Begin);

                var convertedData = s.Deserialize(ms, new PODTestVersionUpgradeStrategy());

                Assert.IsTrue( convertedData is PODTest_Ver2);

                var ver2 = convertedData as PODTest_Ver2;

                Assert.AreEqual( originalData.Name, ver2.Name);
                Assert.AreEqual( originalData.Description, ver2.Description);
                Assert.AreEqual( originalData.Age, ver2.AgeAsOfToday);
                Assert.AreEqual( DateTime.Now.AddYears(-originalData.Age).Year, ver2.DOB.Year);
               }
        }
Beispiel #2
0
        public void ComplexObjectWithArrays_1()
        {
            using(var ms = new MemoryStream())
              {
            var s = new PODSlimSerializer();

            var data = new DataObject();
            data.Populate();
            s.Serialize(ms, data);

            ms.Seek(0, SeekOrigin.Begin);

            var result = s.Deserialize(ms);

            Assert.IsTrue( data.Equals( result));

              }
        }
Beispiel #3
0
        public void RootSimpleWriteRead_nullabletimespan_2()
        {
            using(var ms = new MemoryStream())
               {
                var s = new PODSlimSerializer();

                TimeSpan? originalData = null;

                s.Serialize(ms, originalData);
                ms.Seek(0, SeekOrigin.Begin);

                var convertedData = s.Deserialize(ms);
                Assert.AreEqual(originalData, convertedData);
               }
        }
Beispiel #4
0
        public void RootSimpleWriteRead_string()
        {
            using(var ms = new MemoryStream())
               {
                var s = new PODSlimSerializer();

                var originalData = "hello Dolly!";

                s.Serialize(ms, originalData);
                ms.Seek(0, SeekOrigin.Begin);

                var convertedData = s.Deserialize(ms);
                Assert.AreEqual(originalData, convertedData);
               }
        }
Beispiel #5
0
        public void RootCompositeWriteRead_tuple()
        {
            using(var ms = new MemoryStream())
               {
                var s = new PODSlimSerializer();

                    var originalData = new Tuple<int, string>(5,"yes");

                    s.Serialize(ms, originalData);

                    ms.Seek(0, SeekOrigin.Begin);

                    var convertedData = (Tuple<int, string>)s.Deserialize(ms);

                    Assert.IsFalse( object.ReferenceEquals(originalData, convertedData) );

                    Assert.AreEqual(5, convertedData.Item1);
                    Assert.AreEqual("yes", convertedData.Item2);
               }
        }
Beispiel #6
0
        public void RootSimpleWriteRead_nullabledecimal_1()
        {
            using(var ms = new MemoryStream())
               {
                var s = new PODSlimSerializer();

                decimal? originalData = 125000m;

                s.Serialize(ms, originalData);
                ms.Seek(0, SeekOrigin.Begin);

                var convertedData = s.Deserialize(ms);
                Assert.AreEqual(originalData, convertedData);
               }
        }
Beispiel #7
0
        public void RootCompositeWriteRead_PersonList()
        {
            using(var ms = new MemoryStream())
            {
                var s = new PODSlimSerializer();

                var originalData = new List<TestPerson>
                                    {
                                        new TestPerson{ Name = "Kolyan", DOB = DateTime.Now, Assets=2000000, IsRegistered=true, Luck=150.89},
                                        new TestPerson{ Name = "Zmeyan", DOB = DateTime.Now.AddYears(-25), Assets=50000000, IsRegistered=false, Luck=283.4},

                                    };
                s.Serialize(ms, originalData);

                ms.Seek(0, SeekOrigin.Begin);

                var convertedData = (List<TestPerson>)s.Deserialize(ms);

                Assert.IsFalse( object.ReferenceEquals(originalData, convertedData) );

                Assert.AreEqual(originalData.Count, convertedData.Count);

                Assert.IsTrue (originalData[0].Equals( convertedData[0] ) );

                Assert.IsTrue (originalData[1].Equals( convertedData[1] ) );
            }
        }
Beispiel #8
0
        public void RootCompositeWriteRead_BusinessFamily()
        {
            using(var ms = new MemoryStream())//new FileStream(@"c:\nfx\TEMP.POD", FileMode.Create))// new MemoryStream())
            {
                var s = new PODSlimSerializer();

                var originalData =
                            new TestBusinessFamily{
                                Husband = new TestPerson{ Name = "Kolyan Zver'", DOB = DateTime.Now, Assets=2000000, IsRegistered=true, Luck=150.5489},
                                Wife = new TestPerson{ Name = "Feiga Pozman", DOB = DateTime.Now, Assets=578, IsRegistered=false, Luck=250.489},
                                Kid = new TestPerson{ Name = "Mykola Zver'", DOB = DateTime.Now, Assets=12, IsRegistered=true, Luck=350.189},
                                Assets = 9000000000,
                                IsCertified = true
                            };

                    s.Serialize(ms, originalData);

                    ms.Seek(0, SeekOrigin.Begin);

                    var convertedData = s.Deserialize(ms);

                Assert.IsFalse( object.ReferenceEquals(originalData, convertedData) );

                Assert.IsTrue (originalData.Equals( convertedData ) );
            }
        }
Beispiel #9
0
        public void RootArrayWriteRead_5D()
        {
            using(var ms = new MemoryStream())
               {
                var s = new PODSlimSerializer();

                var originalData = new int[10,4,6,2,2];

                s.Serialize(ms, originalData);
                ms.Seek(0, SeekOrigin.Begin);

                var convertedData = s.Deserialize(ms);
                Assert.IsFalse(  object.ReferenceEquals(originalData, convertedData) );
                Assert.AreEqual(originalData, convertedData);
               }
        }
Beispiel #10
0
        public void RootArrayWriteRead_1D_nullabledatetime()
        {
            using(var ms = new MemoryStream())
               {
                var s = new PODSlimSerializer();

                var originalData = new DateTime?[100];
                var sd = DateTime.UtcNow;
                for(var i=0; i<originalData.Length; i++)
                    if ((i%2)==0)
                    {
                        originalData[i] = sd;
                        sd = sd.AddHours(i+(i*0.01));
                    }

                s.Serialize(ms, originalData);
                ms.Seek(0, SeekOrigin.Begin);

                var convertedData = s.Deserialize(ms);
                Assert.IsFalse(  object.ReferenceEquals(originalData, convertedData) );
                Assert.AreEqual(originalData, convertedData);
               }
        }
Beispiel #11
0
            /// <summary>
            /// Called only if this parcel is ParcelPayloadWrappingMode.Wrapped.
            /// Override to perform custom content deserialization, i.e. when particular store may use special format for data marshalling.
            /// Base implementation understands  Parcel.STANDARD_SLIM_PAYLOAD_FORMAT and Parcel.STANDARD_PODSLIM_PAYLOAD_FORMAT formats
            /// </summary>
            protected virtual object DoUnwrapPayload()
            {
                var wrapped = m_PayloadData as byte[];
                if (wrapped==null) return null;


                ISerializer serializer = null;
                if (m_WrappedPayloadFormat==STANDARD_SLIM_PAYLOAD_FORMAT)
                  serializer = new SlimSerializer( STANDARD_KNOWN_SERIALIZER_TYPES );
                else if (m_WrappedPayloadFormat==STANDARD_PODSLIM_PAYLOAD_FORMAT)
                  serializer = new PODSlimSerializer();
                else
                  throw new DistributedDataParcelSerializationException(
                              StringConsts.DISTRIBUTED_DATA_PARCEL_UNWRAP_FORMAT_ERROR.Args(GetType().FullName, m_WrappedPayloadFormat ?? StringConsts.NULL_STRING));
                
                try
                {
                  using(var ms = new System.IO.MemoryStream( wrapped ))
                    return serializer.Deserialize( ms );
                }
                catch(Exception error)
                {
                  throw new DistributedDataParcelSerializationException(
                             StringConsts.DISTRIBUTED_DATA_PARCEL_UNWRAP_DESER_ERROR.Args(GetType().FullName, error.ToMessageWithType())
                             , error);
                } 
            }