Exemple #1
0
        public void TestUpdate()
        {
            IExternalSurrogate s1 = new CGuidSurrogate();
            IExternalSurrogate s2 = new CDateTimeSurrogate();
            IExternalSurrogate s3 = new CUtcDateTimeSurrogate();

            IExternalSurrogate accum = null;

            accum = CExternalSurrogatePair.Update(accum, null);
            Assert.IsNull(accum, "Updating NULL with NULL should result in NULL");

            accum = CExternalSurrogatePair.Update(accum, s1);
            Assert.AreSame(s1, accum, "After UPDATEing null with s1, the accumulator should be s1");

            accum = CExternalSurrogatePair.Update(accum, null);
            Assert.AreSame(s1, accum, "After UPDATEing the s1 accumulator with NULL, the accumulator should not have changed");


            accum = CExternalSurrogatePair.Update(accum, s2);
            Assert.AreEqual(typeof(CExternalSurrogatePair), accum.GetType(), "After UPDATEing accumulator with s2, the accumulator should now be a surrogate Pair.");

            Assert.AreSame(s1, (accum as CExternalSurrogatePair).Surrogate1, "The first surrogate of the Pair should be s1");
            Assert.AreSame(s2, (accum as CExternalSurrogatePair).Surrogate2, "The second surrogate of the Pair should be s2");


            accum = CExternalSurrogatePair.Update(accum, s3);
            Assert.AreEqual(typeof(CExternalSurrogatePair), accum.GetType(), "After UPDATEing accumulator with s3, the accumulator should still be a surrogate Pair.");

            Assert.AreEqual(typeof(CExternalSurrogatePair), (accum as CExternalSurrogatePair).Surrogate1.GetType(), "The Type of the first surrogate of the Pair should be a Pair");
            Assert.AreEqual(typeof(CUtcDateTimeSurrogate), (accum as CExternalSurrogatePair).Surrogate2.GetType(), "The Type of the second surrogate of the Pair should be the UTC Time surrogate");
        }
        public void TestUtcStringProperty()
        {
            // The default global property is FALSE for UTC strings.
            Assert.IsFalse(CSerializationContext.Global.UseFullUtcDateTimeStrings,
                           "The default global value of UtcStrings is FALSE.");

            var c = new CSerializationContext();

            Assert.IsFalse(c.UseFullUtcDateTimeStrings,
                           "Inheriting from the default global context should not use UtcStrings");

            CSerializationContext.Global.UseFullUtcDateTimeStrings = true;
            Assert.IsTrue(CSerializationContext.Global.UseFullUtcDateTimeStrings,
                          "The After setting the global context to Use Utc Strings, the prop should be TRUE.");
            Assert.IsTrue(c.UseFullUtcDateTimeStrings,
                          "Because the global context changed, the dependant context should also change.");

            c.UseFullUtcDateTimeStrings = false;
            Assert.IsFalse(c.UseFullUtcDateTimeStrings,
                           "Setting the dependant context to FALSE should be reflected in the prop-Getter");
            Assert.IsTrue(CSerializationContext.Global.UseFullUtcDateTimeStrings,
                          "Changing the Dependant context should not modify the Global context.");

            c.UseFullUtcDateTimeStrings = true; // This explicitly means that the dependant context should use strings.
            Assert.IsTrue(c.UseFullUtcDateTimeStrings,
                          "Setting the dependant context to TRUE should be reflected in the prop-Getter");

            CSerializationContext.Global.UseFullUtcDateTimeStrings = false;
            Assert.IsFalse(CSerializationContext.Global.UseFullUtcDateTimeStrings,
                           "Make sure that the GLOBAL property is set to FALSE");
            Assert.IsTrue(c.UseFullUtcDateTimeStrings,
                          "Make sure that the dependant context's override survives the modification of the Global value");

            var d        = new DateTime(2000, 7, 5, 1, 2, 3);
            var expected = d.ToString(CUtcDateTimeSurrogate.UTC_COMPLETE_DATE_TIME_FORMAT);

            var sur = new CUtcDateTimeSurrogate();
            var doc = new XmlDocument();

            doc.LoadXml("<root />");

            var retval = sur.Serialize(d, d.GetType(), doc.DocumentElement, null);

            Assert.AreEqual(expected,
                            doc.DocumentElement.InnerText,
                            "The UTC serialization didn't yield the correct string.");
            Assert.IsTrue(retval, "The surrogate should always indicate that it completely processed the object");

            var w = new CWorkingObject();

            retval = sur.Deserialize(w, doc.DocumentElement, null);
            Assert.AreEqual(d, w.WorkingObject, "The deserialized DateTime is incorrect.");
            Assert.IsTrue(retval, "The surrogate should always indicate that it completely processed the object");
        }