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"); }
/// <summary> /// Construct the Pair using Two separate surrogates. /// </summary> /// <param name="_surrogate1">The 1st surrogate</param> /// <param name="_surrogate2">The 2nd surrogate</param> public CExternalSurrogatePair(IExternalSurrogate _surrogate1, IExternalSurrogate _surrogate2) { if (_surrogate1 == null || _surrogate2 == null) { throw new ArgumentNullException("Not allowed to construct a SurrogatePair with any NULL surrogates."); } Surrogate1 = _surrogate1; Surrogate2 = _surrogate2; }
/// <summary> /// This static method acts as an "accumulator" where, as new surrogates are "found" /// that should be called in turn for a given Type, new Pairs are called and connected /// to each other. /// </summary> /// <param name="_working"> /// The "Working" variable that is being "accumulated into" /// </param> /// <param name="_next"> /// The "next" IExternalSurrogate that should be "accumulated into" the working /// surrogate /// </param> /// <returns> /// An IExternalSurrogate representing the "current" state of the "accumulator" /// </returns> public static IExternalSurrogate Update(IExternalSurrogate _working, IExternalSurrogate _next) { if (_working == null) { return(_next); } if (_next == null) { return(_working); } return(new CExternalSurrogatePair(_working, _next)); }