public void MethodMapperSimpleTest1() { CustomImplementation customImplementation = new CustomImplementation(); BeethovenFactory beethovenFactory = new BeethovenFactory(); ITestMethods instance = beethovenFactory.Generate <ITestMethods>( new MappedMethod(nameof(ITestMethods.WithParameters), customImplementation, nameof(customImplementation.GetLength))); Assert.AreEqual(10, instance.WithParameters("w", "sd", 7)); }
public void LinkedMethodsReturnValueTest4() { CustomImplementation implementation = new CustomImplementation(); BeethovenFactory beethovenFactory = new BeethovenFactory(); ITestMethods instance = beethovenFactory.Generate <ITestMethods>( LinkedMethodsReturnValue.Create <ITestMethods>(nameof(ITestMethods.OutAndRef)) .MappedMethod(implementation, nameof(CustomImplementation.OutAndRef)) .Action(Assert.Fail)); string text2 = "wetwt"; instance.OutAndRef(out string _, ref text2, 5); }
public void LinkedMethodsReturnValueTest3() { Logger logger = new Logger(); CustomImplementation implementation = new CustomImplementation(); BeethovenFactory beethovenFactory = new BeethovenFactory(); ITestMethods unused = beethovenFactory.Generate <ITestMethods>( LinkedMethodsReturnValue.Create <ITestMethods>(nameof(ITestMethods.WithParameters)) .MappedMethod(logger, nameof(logger.LogBefore)) .AutoMappedMethod(implementation) .MappedMethod(logger, nameof(logger.LogAfter))); Assert.Fail(); }
public void LinkedMethodsReturnValueTest5() { CustomImplementation implementation = new CustomImplementation(); BeethovenFactory beethovenFactory = new BeethovenFactory(); bool called = false; ITestMethods instance = beethovenFactory.Generate <ITestMethods>( LinkedMethodsReturnValue.Create <ITestMethods>(nameof(ITestMethods.OutAndRef)) .MappedMethod(implementation, nameof(CustomImplementation.OutAndRef1)) .Action(() => called = true)); string text2 = "wetwt"; instance.OutAndRef(out string _, ref text2, 5); Assert.IsTrue(called); }
public void LinkedMethodsReturnValueTest2() { CustomImplementation implementation = new CustomImplementation(); BeethovenFactory beethovenFactory = new BeethovenFactory(); ITestMethods instance = beethovenFactory.Generate <ITestMethods>( LinkedMethodsReturnValue.Create <ITestMethods>(nameof(ITestMethods.OutAndRef)) .MappedMethod(implementation, nameof(implementation.OutAndRef1)) .AutoMappedMethod(implementation)); string text1 = "abc"; Assert.AreEqual(20, instance.OutAndRef(out string text2, ref text1, 5)); Assert.AreEqual("cba", text1); Assert.AreEqual("abc abc abc abc abc", text2); }
public void LinkedMethodsReturnValueTest1() { Logger logger = new Logger(); CustomImplementation implementation = new CustomImplementation(); BeethovenFactory beethovenFactory = new BeethovenFactory(); ITestMethods instance = beethovenFactory.Generate <ITestMethods>( LinkedMethodsReturnValue.Create <ITestMethods>(nameof(ITestMethods.WithParameters), 1) .MappedMethod(logger, nameof(logger.LogBefore)) .MappedMethod(implementation, nameof(CustomImplementation.GetLength)) .MappedMethod(logger, nameof(logger.LogAfter))); Assert.AreEqual(10, instance.WithParameters("w", "sd", 7)); Assert.AreEqual(2, logger.Log.Count); }
//[TestMethod] public void LinkedMethodsReturnValueTest7() { CustomImplementation implementation = new CustomImplementation(); TypeDefinition <ITestMethods> typeDefinition = TypeDefinition <ITestMethods> .Create(FieldDefinition .CreateFromConstructorParameter <BoolContainer>() .ImportInMain(), LinkedMethodsReturnValue.Create <ITestMethods>(nameof(ITestMethods.OutAndRef)) .MappedMethod(implementation, nameof(CustomImplementation.OutAndRef))); BoolContainer boolContainer = new BoolContainer(); ITestMethods instance = typeDefinition.CreateNew(boolContainer); BoolContainer boolContainer2 = new BoolContainer(); typeDefinition.CreateNew(boolContainer2); string text2 = "wetwt"; instance.OutAndRef(out string _, ref text2, 5); Assert.IsTrue(boolContainer.Value); Assert.IsFalse(boolContainer2.Value); }