Author: jbevain Date: 2008-02-19 08:47:58 -0500 (Tue, 19 Feb 2008) New Revision: 96144
Modified: trunk/mcs/class/System.Core/Test/System.Linq.Expressions/ExpressionTest_New.cs Log: add a few tests Modified: trunk/mcs/class/System.Core/Test/System.Linq.Expressions/ExpressionTest_New.cs =================================================================== --- trunk/mcs/class/System.Core/Test/System.Linq.Expressions/ExpressionTest_New.cs 2008-02-19 13:46:38 UTC (rev 96143) +++ trunk/mcs/class/System.Core/Test/System.Linq.Expressions/ExpressionTest_New.cs 2008-02-19 13:47:58 UTC (rev 96144) @@ -174,5 +174,85 @@ Assert.IsNotNull (bar); Assert.IsNull (bar.Value); } + + public class FakeAnonymousType { + + public string Foo { get; set; } + public string Bar { get; set; } + public string Baz { get; set; } + public int Gazonk { get; set; } + public string Tzap { set {} } + + public FakeAnonymousType (string foo) + { + Foo = foo; + } + + public FakeAnonymousType (string foo, string bar, string baz) + { + Foo = foo; + Bar = bar; + Baz = baz; + } + } + + [Test] + [Category ("NotWorking")] + public void NewFakeAnonymousType () + { + var n = Expression.New ( + typeof (FakeAnonymousType).GetConstructor (new [] { typeof (string), typeof (string), typeof (string) } ), + new [] { "Foo".ToConstant (), "Bar".ToConstant (), "Baz".ToConstant () }, + new [] { typeof (FakeAnonymousType).GetProperty ("Foo"), typeof (FakeAnonymousType).GetProperty ("Bar"), typeof (FakeAnonymousType).GetProperty ("Baz") }); + + Assert.IsNotNull (n.Constructor); + Assert.IsNotNull (n.Arguments); + Assert.IsNotNull (n.Members); + Assert.AreEqual ("new FakeAnonymousType(Foo = \"Foo\", Bar = \"Bar\", Baz = \"Baz\")", n.ToString ()); + } + + [Test] + [Category ("NotWorking")] + [ExpectedException (typeof (ArgumentNullException))] + public void NullMember () + { + var n = Expression.New ( + typeof (FakeAnonymousType).GetConstructor (new [] { typeof (string) }), + new [] { "Foo".ToConstant () }, + new MemberInfo [] { null }); + } + + [Test] + [Category ("NotWorking")] + [ExpectedException (typeof (ArgumentException))] + public void MemberArgumentMiscount () + { + var n = Expression.New ( + typeof (FakeAnonymousType).GetConstructor (new [] { typeof (string) }), + new [] { "Foo".ToConstant () }, + new [] { typeof (FakeAnonymousType).GetProperty ("Foo"), typeof (FakeAnonymousType).GetProperty ("Bar") }); + } + + [Test] + [Category ("NotWorking")] + [ExpectedException (typeof (ArgumentException))] + public void MemberArgumentMismatch () + { + var n = Expression.New ( + typeof (FakeAnonymousType).GetConstructor (new [] { typeof (string) }), + new [] { "Foo".ToConstant () }, + new [] { typeof (FakeAnonymousType).GetProperty ("Gazonk") }); + } + + [Test] + [Category ("NotWorking")] + [ExpectedException (typeof (ArgumentException))] + public void MemberHasNoGetter () + { + var n = Expression.New ( + typeof (FakeAnonymousType).GetConstructor (new [] { typeof (string) }), + new [] { "Foo".ToConstant () }, + new [] { typeof (FakeAnonymousType).GetProperty ("Tzap") }); + } } } _______________________________________________ Mono-patches maillist - Mono-patches@lists.ximian.com http://lists.ximian.com/mailman/listinfo/mono-patches