/// <summary> /// Compare the <see cref="IValueUpdater"/> with another object to /// determine equality. /// </summary> /// <param name="o"> /// The object to compare with. /// </param> /// <returns> /// <b>true</b> iff this <see cref="IValueUpdater"/> and the passed /// object are quivalent <b>IValueUpdater</b>s. /// </returns> public override bool Equals(object o) { if (o is CompositeUpdater) { CompositeUpdater that = (CompositeUpdater)o; return(m_extractor.Equals(that.m_extractor) && m_updater.Equals(that.m_updater)); } return(false); }
public void TestReflectionUpdater() { IValueUpdater updater = new ReflectionUpdater("field"); IValueUpdater updater1 = new ReflectionUpdater("field"); IValueUpdater updater2 = new CompositeUpdater("field"); Assert.IsNotNull(updater); Assert.AreEqual(updater, updater1); Assert.AreNotEqual(updater, updater2); Assert.AreEqual(updater.ToString(), updater1.ToString()); Assert.AreEqual(updater.GetHashCode(), updater1.GetHashCode()); ReflectionTestType o = new ReflectionTestType(); int value = 100; o.field = 0; updater.Update(o, value); Assert.AreEqual(o.field, value); updater.Update(o, value * 2); Assert.AreEqual(o.field, value * 2); try { updater.Update(null, value); } catch (Exception e) { Assert.IsInstanceOf(typeof(ArgumentNullException), e); } updater = new ReflectionUpdater("Property"); o.Property = 1; updater.Update(o, value); Assert.AreEqual(o.Property, value); updater = new ReflectionUpdater("SetMethod"); o = new ReflectionTestType(); updater.Update(o, value); Assert.AreEqual(o.field, value); try { updater = new ReflectionUpdater("InvalidMember"); updater.Update(o, value); } catch (Exception e) { Assert.IsInstanceOf(typeof(ArgumentException), e.InnerException); } }
public void TestCompositeUpdater() { IValueUpdater updater = new CompositeUpdater("field"); IValueUpdater updater1 = new CompositeUpdater("field"); IValueUpdater updater2 = new ReflectionUpdater("field"); Assert.IsNotNull(updater); Assert.AreEqual(updater, updater1); Assert.AreNotEqual(updater, updater2); Assert.AreEqual(updater.ToString(), updater1.ToString()); Assert.AreEqual(updater.GetHashCode(), updater1.GetHashCode()); IValueExtractor extractor = (updater as CompositeUpdater).Extractor; Assert.IsNotNull(extractor); IValueUpdater updter = (updater as CompositeUpdater).Updater; Assert.IsNotNull(updter); Assert.IsInstanceOf(typeof(IdentityExtractor), extractor); Assert.IsInstanceOf(typeof(ReflectionUpdater), updter); ReflectionTestType o = new ReflectionTestType(); int value = 100; o.field = 0; updater.Update(o, value); Assert.AreEqual(o.field, value); updater = new CompositeUpdater("InnerMember.field"); IValueExtractor ext = new ChainedExtractor("InnerMember"); IValueUpdater upd = new ReflectionUpdater("field"); updater1 = new CompositeUpdater(ext, upd); Assert.IsNotNull(updater); Assert.AreEqual(updater, updater1); Assert.AreEqual(updater.ToString(), updater1.ToString()); Assert.AreEqual(updater.GetHashCode(), updater1.GetHashCode()); updater.Update(o, value); Assert.AreEqual(o.InnerMember.field, value); }
public void TestUpdaterSerialization() { ConfigurablePofContext ctx = new ConfigurablePofContext("assembly://Coherence.Tests/Tangosol.Resources/s4hc-test-config.xml"); Assert.IsNotNull(ctx); CompositeUpdater compositeUpdater = new CompositeUpdater("name"); ReflectionUpdater reflectionUpdater = new ReflectionUpdater("member"); Stream stream = new MemoryStream(); ctx.Serialize(new DataWriter(stream), compositeUpdater); ctx.Serialize(new DataWriter(stream), reflectionUpdater); stream.Position = 0; Assert.AreEqual(compositeUpdater, ctx.Deserialize(new DataReader(stream))); Assert.AreEqual(reflectionUpdater, ctx.Deserialize(new DataReader(stream))); stream.Close(); }