public void TestMethodDefaultMethod3() { List <string> methodsCalled = new List <string>(); BeethovenFactory factory = new BeethovenFactory(); ITestMethods test = factory.Generate <ITestMethods>( new DefaultMethod((methodInfo, _) => methodsCalled.Add(methodInfo.Name))); test.Simple(); test.ReturnValue(); test.WithParameters("as", "wefewf"); test.WithParameters("", null, 5); string b = ""; test.OutAndRef(out string a, ref b, 5); int value = 0; test.Ref(ref value); test.GetMain("klkl", "kklklklkk"); test.NoReturnValue("", ""); CollectionAssert.AreEquivalent(new[] { "Simple", "ReturnValue", "WithParameters", "WithParameters", "OutAndRef", "Ref", "GetMain", "NoReturnValue" }, methodsCalled); }
public void MethodReturnValueInvalid() { BeethovenFactory factory = new BeethovenFactory(); ITestMethods test = factory.Generate <ITestMethods>(new InvalidSignature()); test.ReturnValue(); Assert.Fail(); }
public void MethodSimpleMissing() { BeethovenFactory factory = new BeethovenFactory(); ITestMethods test = factory.Generate <ITestMethods>(new object()); test.Simple(); Assert.Fail(); }
public void MethodWithParametersInvalid2() { BeethovenFactory factory = new BeethovenFactory(); ITestMethods test = factory.Generate <ITestMethods>(new InvalidSignature()); test.WithParameters("123", "abc", 5); Assert.Fail(); }
public void MethodWithParameters2() { ITestMethods fake = A.Fake <ITestMethods>(); BeethovenFactory factory = new BeethovenFactory(); ITestMethods test = factory.Generate <ITestMethods>(fake); A.CallTo(() => fake.WithParameters("123", "abc", 5)).Returns(42); Assert.AreEqual(42, test.WithParameters("123", "abc", 5)); }
public void ConstructorInitializedFieldMethodSimple() { ITestMethods fake = A.Fake <ITestMethods>(); BeethovenFactory factory = new BeethovenFactory(); ITestMethods test = factory.Generate <ITestMethods>(fake); test.Simple(); A.CallTo(() => fake.Simple()).MustHaveHappenedOnceExactly(); }
public void MethodRefInvalid() { BeethovenFactory factory = new BeethovenFactory(); ITestMethods test = factory.Generate <ITestMethods>(new InvalidSignature()); int value = 5; test.Ref(ref value); Assert.Fail(); }
public void MethodOutAndRefInvalid() { BeethovenFactory factory = new BeethovenFactory(); ITestMethods test = factory.Generate <ITestMethods>(new InvalidSignature()); string text1 = "abc"; test.OutAndRef(out string _, ref text1, 5); Assert.Fail(); }
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 MethodReturnValue() { ITestMethods fake = A.Fake <ITestMethods>(); BeethovenFactory factory = new BeethovenFactory(); ITestMethods test = factory.Generate <ITestMethods>(fake); A.CallTo(() => fake.ReturnValue()).Returns(42); Assert.AreEqual(42, test.ReturnValue()); A.CallTo(() => fake.ReturnValue()).MustHaveHappenedOnceExactly(); }
public void MethodRefTest() { OutAndRefImplementation obj = new OutAndRefImplementation(); BeethovenFactory factory = new BeethovenFactory(); ITestMethods test = factory.Generate <ITestMethods>(obj); int value = 4; test.Ref(ref value); Assert.AreEqual(5, value); }
public void LinkedMethodsReturnValueTest2() { PartialMethods partialMethods = new PartialMethods(); BeethovenFactory beethovenFactory = new BeethovenFactory(); ITestMethods instance = beethovenFactory.Generate <ITestMethods>( new LinkedMethodsReturnValue(nameof(ITestMethods.WithParameters)) .PartialMatchMethod(partialMethods, nameof(partialMethods.WithParametersReturnValue))); Assert.AreEqual(5, instance.WithParameters("w", "sd", 3)); }
public void TestMethodDefaultMethod2() { List <string> methodsCalled = new List <string>(); BeethovenFactory factory = new BeethovenFactory(); ITestMethods test = factory.Generate <ITestMethods>( new DefaultMethod((methodInfo, _) => methodsCalled.Add(methodInfo.Name))); Assert.AreEqual(0, test.ReturnValue()); CollectionAssert.AreEquivalent(new[] { "ReturnValue" }, methodsCalled); }
public void MethodOutAndRef() { OutAndRefImplementation obj = new OutAndRefImplementation(); BeethovenFactory factory = new BeethovenFactory(); ITestMethods test = factory.Generate <ITestMethods>(obj); string text1 = "abc"; Assert.AreEqual(19, test.OutAndRef(out string text2, ref text1, 5)); Assert.AreEqual("cba", text1); Assert.AreEqual("abc abc abc abc abc", text2); }
public void LinkedMethodsReturnValueTest3() { PartialMethods partialMethods = new PartialMethods(); BeethovenFactory beethovenFactory = new BeethovenFactory(); ITestMethods instance = beethovenFactory.Generate <ITestMethods>( new LinkedMethodsReturnValue(nameof(ITestMethods.GetMain)) .PartialMatchMethod <ITestMethods>(partialMethods, "testMethods")); object actual = instance.GetMain("w", "sd"); Assert.AreEqual(instance, actual); }
public void MethodMultiObjects() { SimpleImplementation obj1 = new SimpleImplementation(); OutAndRefImplementation obj2 = new OutAndRefImplementation(); BeethovenFactory factory = new BeethovenFactory(); ITestMethods test = factory.Generate <ITestMethods>(obj1, obj2); string text1 = "abc"; Assert.AreEqual(19, test.OutAndRef(out string _, ref text1, 5)); test.Simple(); }
public object GetMain(ITestMethods testMethods, string text1, string text2) { if (string.IsNullOrEmpty(text1)) { throw new Exception(); } if (string.IsNullOrEmpty(text2)) { throw new Exception(); } return(testMethods); }
public void LinkedMethodsTest11() { BeethovenFactory beethovenFactory = new BeethovenFactory(); WithParametersImplementation implentation = new WithParametersImplementation(); ITestMethods instance = beethovenFactory.Generate <ITestMethods>( LinkedMethodsReturnValue.Create <ITestMethods>(nameof(ITestMethods.WithParameters), 1) .AutoMappedMethod(implentation) .Func(() => 5)); int result = instance.WithParameters("fdgdf", "afasf", 3); Assert.AreEqual(5, result); }
public void LinkedMethodsTest2() { SimpleImplementation implementation = new SimpleImplementation(); BeethovenFactory beethovenFactory = new BeethovenFactory(); ITestMethods instance = beethovenFactory.Generate <ITestMethods>( new LinkedMethods(nameof(ITestMethods.Simple)) .AutoMappedMethod(implementation) .Action((int value) => { })); instance.Simple(); Assert.Fail(); }
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 LinkedMethodsTest4() { BeethovenFactory beethovenFactory = new BeethovenFactory(); bool skip = true; ITestMethods instance = beethovenFactory.Generate <ITestMethods>( LinkedMethodsReturnValue.Create <ITestMethods>(nameof(ITestMethods.ReturnValue)) .SkipIf(() => skip) .Func(() => 477)); Assert.AreEqual(0, instance.ReturnValue()); skip = false; Assert.AreEqual(477, instance.ReturnValue()); }
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 LinkedMethodsTest3() { BeethovenFactory beethovenFactory = new BeethovenFactory(); ITestMethods instance = beethovenFactory.Generate <ITestMethods>( LinkedMethodsReturnValue.Create <ITestMethods>(nameof(ITestMethods.WithParameters)) .SkipIf <string, string>((text1, text2) => string.IsNullOrEmpty(text1)) .SkipIf <string, string>((text1, text2) => string.IsNullOrEmpty(text2)) .Func((string text1, string text2) => text1.Length + text2.Length)); //Assert.AreEqual(0, instance.WithParameters(null, null)); //Assert.AreEqual(0, instance.WithParameters("", "dsfgdsfhsd")); //Assert.AreEqual(0, instance.WithParameters("gjgkffg", "")); Assert.AreEqual(15, instance.WithParameters("fdsfd", "dsfgdsfhsd")); }
public void LinkedMethodsTest1() { List <string> log = new List <string>(); SimpleImplementation implementation = new SimpleImplementation(); BeethovenFactory beethovenFactory = new BeethovenFactory(); ITestMethods instance = beethovenFactory.Generate <ITestMethods>( new LinkedMethods(nameof(ITestMethods.Simple)) .Action(() => log.Add("Before")) .AutoMappedMethod(implementation) .Action(() => log.Add("After"))); instance.Simple(); CollectionAssert.AreEquivalent(new[] { "Before", "After" }, log); }
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 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); }
public void MethodWithParameters1() { ITestMethods fake = A.Fake <ITestMethods>(); BeethovenFactory factory = new BeethovenFactory(); ITestMethods test = factory.Generate <ITestMethods>(fake); A.CallTo(() => fake.WithParameters("123", "abc")).Returns(42); A.CallTo(() => fake.WithParameters("", "")).Returns(41); A.CallTo(() => fake.WithParameters("123", "abc", 0)).Returns(0); Assert.AreEqual(42, test.WithParameters("123", "abc")); A.CallTo(() => fake.WithParameters("123", "abc")).MustHaveHappenedOnceExactly(); A.CallTo(() => fake.WithParameters("123", "abc", 0)).MustNotHaveHappened(); A.CallTo(() => fake.WithParameters("", "")).MustNotHaveHappened(); }
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); }