Exemple #1
0
        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 LinkedMethodsTest5()
        {
            BeethovenFactory beethovenFactory = new BeethovenFactory();
            bool             skip             = true;
            int          calledCount          = 0;
            ITestMethods instance             = beethovenFactory.Generate <ITestMethods>(
                new LinkedMethods(nameof(ITestMethods.Simple))
                .SkipIf(() => skip)
                .Action(() => calledCount++));

            instance.Simple();
            instance.Simple();
            Assert.AreEqual(0, calledCount);
            skip = false;
            instance.Simple();
            Assert.AreEqual(1, calledCount);
        }
        public void MethodSimpleMissing()
        {
            BeethovenFactory factory = new BeethovenFactory();
            ITestMethods     test    = factory.Generate <ITestMethods>(new object());

            test.Simple();
            Assert.Fail();
        }
        public void MethodSimpleInvalid()
        {
            BeethovenFactory factory = new BeethovenFactory();
            ITestMethods     test    = factory.Generate <ITestMethods>(new InvalidSignature());

            test.Simple();
            Assert.Fail();
        }
Exemple #5
0
        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();
        }
Exemple #6
0
        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 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 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);
        }
Exemple #10
0
        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);
        }
Exemple #11
0
        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);
        }