예제 #1
0
        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 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());
        }
예제 #3
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);
        }
예제 #4
0
        public void MethodReturnValueInvalid()
        {
            BeethovenFactory factory = new BeethovenFactory();
            ITestMethods     test    = factory.Generate <ITestMethods>(new InvalidSignature());

            test.ReturnValue();
            Assert.Fail();
        }
예제 #5
0
        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);
        }
예제 #6
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);
        }