public void MultiMethodsTest2() { TypeDefinition <IMultiMethods1> typeDefinition = new TypeDefinition <IMultiMethods1>( ActionMethod.Create("Foo", (int a) => { })); IMultiMethods1 instance = typeDefinition.Create(); instance.Foo(5); }
public void MultiMethodsTestInvalid2() { TypeDefinition <IMultiMethods1> typeDefinition = new TypeDefinition <IMultiMethods1>( ActionMethod.Create("Foo", (short value) => { })); IMultiMethods1 instance = typeDefinition.Create(); instance.Foo(5); }
public void MultiMethodsTestInvalid1() { TypeDefinition <IMultiMethods1> typeDefinition = TypeDefinition <IMultiMethods1> .Create(ActionMethod.Create("Foo", (string value) => { })); IMultiMethods1 instance = typeDefinition.CreateNew(); instance.Foo(5); }
public void MultiMethodsTest3() { int callCount = 0; TypeDefinition <IMultiMethods1> typeDefinition = new TypeDefinition <IMultiMethods1>( ActionMethod.Create("Foo", () => callCount++)); IMultiMethods1 instance = typeDefinition.Create(); instance.Foo(); instance.Foo(5); instance.Foo("5"); Assert.AreEqual(3, callCount); }
public void LinkedMethodsTest10() { List <string> log = new List <string>(); SimpleImplementation implementation = new SimpleImplementation(); BeethovenFactory beethovenFactory = new BeethovenFactory(); ITestMethods instance = beethovenFactory.Generate <ITestMethods>( new LinkedObjects( ActionMethod.Create("Simple", () => log.Add("Before")), implementation, ActionMethod.Create("Simple", () => log.Add("After")))); instance.Simple(); CollectionAssert.AreEquivalent(new[] { "Before", "After" }, log); }
public void TestMethodFallbackMethod1() { int callCount = 0; ITestMethods test = TypeDefinition <ITestMethods> .Create( ActionMethod.Create("Simple", () => callCount++).CreateFallback(), FuncMethod.Create("ReturnValue", () => 5) ) .CreateNew(); Assert.AreEqual(5, test.ReturnValue()); Assert.AreEqual(0, callCount); test.Simple(); Assert.AreEqual(1, callCount); }
public void MultiMethodsTest5() { int callCount = 0; TypeDefinition <IMultiMethods1> typeDefinition = TypeDefinition <IMultiMethods1> .Create(ActionMethod.Create("Foo", (int a) => { }), ActionMethod.Create("Foo", () => callCount++).CreateFallback()); IMultiMethods1 instance = typeDefinition.CreateNew(); instance.Foo(); instance.Foo(5); instance.Foo("5"); instance.Foo(out string _); Assert.AreEqual(3, callCount); }
public void LinkedMethodsTest13() { List <string> log = new List <string>(); List <int> implementation = new List <int> { 5, 2, 17 }; BeethovenFactory beethovenFactory = new BeethovenFactory(); IEnumerable <int> instance = beethovenFactory.Generate <IEnumerable <int> >( new LinkedObjects( ActionMethod.Create("GetEnumerator", () => log.Add("Before")), implementation, ActionMethod.Create("GetEnumerator", () => log.Add("After")))); CollectionAssert.AreEqual(new[] { 5, 2, 17 }, instance.ToArray()); CollectionAssert.AreEquivalent(new[] { "Before", "After" }, log); }
public void TestMethodDefaultMethod5() { List <string> methodsCalled = new List <string>(); object LogCall(MethodInfo methodInfo, object[] _) { methodsCalled.Add(methodInfo.Name); return(null); } BeethovenFactory factory = new BeethovenFactory(); ITestMethods test = factory.Generate <ITestMethods>( ActionMethod.Create(nameof(ITestMethods.Simple), () => { }), new DefaultMethod(LogCall)); test.Simple(); CollectionAssert.AreEquivalent(new string[0], methodsCalled); }