Example #1
0
                public static void Serialize(ShortCacheObject o, Stream s)
                {
                    StreamWriter sw = new StreamWriter(s);

                    sw.WriteLine(o.StringProp);
                    sw.WriteLine(o.IntProp);
                    sw.Flush();
                }
Example #2
0
                public static ShortCacheObject Deserialize(ShortCacheObject item, Stream s)
                {
                    StreamReader sr = new StreamReader(s);

                    ShortCacheObject sco = item;

                    sco.StringProp = sr.ReadLine();

                    // this is expected to fail in the DeserializeCacheFail case
                    sco.IntProp = Int32.Parse(sr.ReadLine());
                    return(sco);
                }
Example #3
0
                public object Deserialize(LoadContext id, Type objectType, Stream stream)
                {
                    if (FailDeserializeMessage != null)
                    {
                        throw new FormatException(FailDeserializeMessage);
                    }
                    StreamReader sr = new StreamReader(stream);

                    ShortCacheObject sco = CreateInstance(id.Identity);

                    sco.StringProp = sr.ReadLine();

                    // this is expected to fail in the DeserializeCacheFail case
                    sco.IntProp = Int32.Parse(sr.ReadLine());
                    return(sco);
                }
Example #4
0
        public void TestRefreshOfLoadFail()
        {
            ShortCacheObject val = null;

            ShortCacheObject.FailDeserializeMessage = "expected fail.";

            ShortCacheObject.SCOLoadRequest.Error = new InvalidCastException();


            val = DataManager.Current.Load <ShortCacheObject>(ShortCacheObject.DefaultIdentifier,
                                                              (v) =>
            {
                ShortCacheObject.SCOLoadRequest.Error = null;
                Assert.Fail("Load should have failed.");
                TestComplete();
            },
                                                              (ex) =>
            {
                string oldDefault = ShortCacheObject.DefaultStringValue;

                // we should not get a value.
                //
                Assert.AreNotEqual(val.StringProp, oldDefault);
                ShortCacheObject.DefaultStringValue = DateTime.Now.ToString();

                ShortCacheObject.FailDeserializeMessage = null;
                ShortCacheObject.SCOLoadRequest.Error   = null;

                // now request a new value via refresh.
                //
                DataManager.Current.Refresh <ShortCacheObject>(ShortCacheObject.DefaultIdentifier,
                                                               (v2) =>
                {
                    Assert.AreEqual(v2.StringProp, ShortCacheObject.DefaultStringValue);
                    ShortCacheObject.DefaultStringValue = oldDefault;
                    TestComplete();
                },
                                                               (ex2) =>
                {
                    Assert.Fail(ex2.Message);
                    TestComplete();
                }

                                                               );
            });
        }
Example #5
0
        public void TestRegisterProxy()
        {
            int propValue = 999;

            ShortCacheObject sco = new ShortCacheObject("Proxy");

            sco.IntProp = propValue;
            Assert.AreNotEqual(propValue, ShortCacheObject.DefaultIntValue);

            DataManager.Current.RegisterProxy <ShortCacheObject>(sco, true,
                                                                 (obj) =>
            {
                Assert.AreNotEqual(propValue, obj.IntProp);
                Assert.AreEqual(ShortCacheObject.DefaultIntValue, obj.IntProp);
                Assert.AreEqual(ShortCacheObject.DefaultIntValue, sco.IntProp);
                TestComplete();
            },
                                                                 false
                                                                 );
        }