public void TestDynamicWrapper() { Person original = new Person( "Bruce Lee", 25 ); dynamic wrapper = new DynamicWrapper( original ); Assert.AreEqual( original.Name, wrapper.Name ); Assert.AreEqual( original.Age, wrapper.Age ); double distance; original.Walk( 10d, out distance ); Assert.AreEqual( 10d, distance ); wrapper.Walk( 10d, out distance ); //Assert.AreEqual( 20d, distance ); Assert.AreEqual( 20d, original.TryGetFieldValue( "metersTravelled" ) ); }
public void TestToXml() { string xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>{0}" + "<Person>{0}{1}</Person>{0}"; string name = string.Format( "{1}<Name>Bruce Lee</Name>{0}", Environment.NewLine, "\t" ); string age = string.Format( "{1}<Age>25</Age>{0}", Environment.NewLine, "\t" ); string mt = string.Format( "{1}<MetersTravelled>0</MetersTravelled>{0}", Environment.NewLine, "\t" ); var expected = new List<string>(); expected.Add( string.Format( xml, Environment.NewLine, name + age + mt ) ); expected.Add( string.Format( xml, Environment.NewLine, name + mt + age ) ); expected.Add( string.Format( xml, Environment.NewLine, age + name + mt ) ); expected.Add( string.Format( xml, Environment.NewLine, age + mt + name ) ); expected.Add( string.Format( xml, Environment.NewLine, mt + age + name ) ); expected.Add( string.Format( xml, Environment.NewLine, mt + name + age ) ); Person person = new Person( "Bruce Lee", 25 ); Assert.IsTrue( expected.Contains( person.ToXml() ) ); }
public Person AddFriend( Person friend ) { return friend; }
internal Person( Person other ) : this( other.Name, other.Age ) { }
public void TestGetPropertyUsingMemberExpression() { var person = new Person( "Arthur", 32 ); Assert.AreEqual( "Arthur", person.GetPropertyValue( () => person.Name ) ); person.SetPropertyValue( () => person.Name, "Ford" ); Assert.AreEqual( "Ford", person.Name ); }