public static void Serialize(ShortCacheObject o, Stream s) { StreamWriter sw = new StreamWriter(s); sw.WriteLine(o.StringProp); sw.WriteLine(o.IntProp); sw.Flush(); }
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); }
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); }
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(); } ); }); }
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 ); }