public void DynamicNullableTest() { var d = new PrivateMock().AsDynamic(); (d.NullableMethod((IEnumerable <int>)null) as string).Is("enumerable"); (d.NullableMethod((List <int>)null) as string).Is("list"); (d.NullableMethod(Enumerable.Range(1, 10)) as string).Is("enumerable"); (d.NullableMethod(new List <int>().AsEnumerable()) as string).Is("enumerable"); (d.NullableMethod(new List <int>()) as string).Is("list"); }
public void DynamicTest() { var d = new PrivateMock().AsDynamic(); (d.privateField as string).Is("homu"); (d.PrivateProperty as string).Is("homuhomu"); (d.PrivateMethod(3) as string).Is("homuhomuhomu"); d.privateField = "mogu"; (d.privateField as string).Is("mogu"); d.PrivateProperty = "mami"; (d.privateField as string).Is("mami"); ((char)d[2]).Is('m'); d[3] = 'A'; (d.privateField as string).Is("AAA"); ((string)d[100.101]).Is("100.101"); d[72] = "Chihaya"; (d.privateField as string).Is("Chihaya72"); ((bool)d.NonParameterMethod()).Is(true); var list = new List <int>(); d.VoidMethod(list); list[0].Is(-100); list.Count.Is(1); var e1 = Assert.Throws <ArgumentException>(() => { var x = d["hoge"]; }); e1.Message.Is(s => s.Contains("indexer not found")); var e2 = Assert.Throws <ArgumentException>(() => { d["hoge"] = "a"; }); e2.Message.Is(s => s.Contains("indexer not found")); }