Beispiel #1
0
        public void TestMethodPropertyPropertyMapped6()
        {
            MappedTestClass  obj     = new MappedTestClass();
            BeethovenFactory factory = new BeethovenFactory();
            ITestProperties  test    = factory.Generate <ITestProperties>(
                new PropertyDefinition <string>(nameof(ITestProperties.Property2))
                .MappedFrom(obj));

            Assert.AreEqual(null, test.Property2);
            obj.Property2 = "42";
            Assert.AreEqual("42", test.Property2);
        }
Beispiel #2
0
        public void TestMethodPropertyPropertyMapped5()
        {
            MappedTestClass  obj     = new MappedTestClass();
            BeethovenFactory factory = new BeethovenFactory();
            ITestProperties  test    = factory.Generate <ITestProperties>(
                new PropertyDefinition <int>(nameof(ITestProperties.Property1))
                .MappedFrom(obj));

            Assert.AreEqual(0, test.Property1);
            obj.Property1 = 42;
            Assert.AreEqual(42, test.Property1);
        }
Beispiel #3
0
        public void TestMethodProperty2()
        {
            int              setCount = 0;
            Action <int>     action   = value => setCount++;
            BeethovenFactory factory  = new BeethovenFactory();
            ITestProperties  test     = factory.Generate <ITestProperties>(
                new PropertyDefinition <int>(nameof(ITestProperties.Property1))
                .DelegatedSetter(action));

            test.Property1 = 5;
            Assert.AreEqual(1, setCount);
        }
Beispiel #4
0
        public void TestMethodPropertyValidityCheck1()
        {
            BeethovenFactory factory = new BeethovenFactory();
            ITestProperties  test    = factory.Generate <ITestProperties>(
                new PropertyDefinition <int>(nameof(ITestProperties.Property1))
                .ValidityCheck(value => value % 2 == 0)
                .SetterGetter());

            Assert.AreEqual(0, test.Property1);
            test.Property1 = 10;
            Assert.AreEqual(10, test.Property1);
        }
Beispiel #5
0
        public void TestMethodPropertyRangeCheck1()
        {
            BeethovenFactory factory = new BeethovenFactory();
            ITestProperties  test    = factory.Generate <ITestProperties>(
                new PropertyDefinition <int>(nameof(ITestProperties.Property1))
                .RangeCheck(0, 42)
                .SetterGetter());

            Assert.AreEqual(0, test.Property1);
            test.Property1 = 42;
            Assert.AreEqual(42, test.Property1);
        }
        public void LinkedMethodsReturnValueTest4()
        {
            CustomImplentation implementation   = new CustomImplentation();
            BeethovenFactory   beethovenFactory = new BeethovenFactory();
            ITestMethods       instance         = beethovenFactory.Generate <ITestMethods>(
                new LinkedMethodsReturnValue(nameof(ITestMethods.OutAndRef))
                .MappedMethod(implementation, nameof(CustomImplentation.OutAndRef))
                .InvertResult()
                .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 EventSimpleRemoved1()
        {
            BeethovenFactory factory           = new BeethovenFactory();
            ITestEvents      test              = factory.Generate <ITestEvents>();
            Action           trigger           = new EventTrigger(test, nameof(ITestEvents.Simple)).ToAction();
            bool             simpleEventCalled = false;
            Action           delegate1         = delegate { simpleEventCalled = true; };

            test.Simple += delegate1;
            test.Simple -= delegate1;
            trigger();
            Assert.IsFalse(simpleEventCalled);
        }
        public void GenericSimpleTest3()
        {
            BeethovenFactory beethovenFactory = new BeethovenFactory();
            IGenericMethods  instance         = beethovenFactory.Generate <IGenericMethods>(
                new SimpleFuncMethod <string>("Simple", () => "abcd"),
                new SimpleFuncMethod <int>("Simple", () => 5),
                new SimpleFuncMethod <short>("Simple", () => 0)
                );

            Assert.AreEqual(5, instance.Simple <int>());
            Assert.AreEqual(0, instance.Simple <short>());
            Assert.AreEqual("abcd", instance.Simple <string>());
        }
        public void TestMethodPropertySkipIfEqual3()
        {
            BeethovenFactory factory = new BeethovenFactory();
            int             setCount = 0;
            ITestProperties test     = factory.Generate <ITestProperties>(
                new PropertyDefinition <int>(nameof(ITestProperties.Property1))
                .SkipIfEqual()
                .DelegatedSetter(value => setCount++));

            test.Property1 = 5;
            test.Property1 = 6;
            Assert.AreEqual(2, setCount);
        }
        public void EventWithReturnValue3()
        {
            BeethovenFactory    factory = new BeethovenFactory();
            ITestEvents         test    = factory.Generate <ITestEvents>();
            Func <string, bool> trigger =
                new EventTrigger(test, nameof(ITestEvents.WithReturnValue)).ToFunc <string, bool>();

            test.WithReturnValue += value => false;
            test.WithReturnValue += value => true;
            bool returnValue = trigger("123");

            Assert.AreEqual(true, returnValue);
        }
        public void GenericSimpleTest1()
        {
            GenericMethods   genericMethods   = new GenericMethods();
            BeethovenFactory beethovenFactory = new BeethovenFactory();
            IGenericMethods  instance         = beethovenFactory.Generate <IGenericMethods>(genericMethods);
            List <string>    calledMethods    = new List <string>();

            genericMethods.MethodCalled += s => calledMethods.Add(s);
            Assert.AreEqual(5, instance.Simple <int>());
            Assert.AreEqual(0, instance.Simple <short>());
            Assert.AreEqual("abcd", instance.Simple <string>());
            CollectionAssert.AreEquivalent(new[] { "Simple", "Simple", "Simple" }, calledMethods);
        }
        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();
        }
Beispiel #14
0
        public void TestMethodDefaultPropertySetterGetter1()
        {
            BeethovenFactory factory = new BeethovenFactory();
            ITestProperties  test    = factory.Generate <ITestProperties>(
                new DefaultProperty()
                .SetterGetter());

            Assert.AreEqual(0, test.Property1);
            test.Property2 = "Some value";
            Assert.AreEqual("Some value", test.Property2);
            test.Property1 = 55;
            Assert.AreEqual(55, test.Property1);
        }
        public void TestMethodProperty3()
        {
            BeethovenFactory factory = new BeethovenFactory();
            ITestProperties  test    = factory.Generate <ITestProperties>(
                new PropertyDefinition <string>(nameof(ITestProperties.Property2))
                .SetterGetter());
            ITestProperties test2 = factory.Generate <ITestProperties>(
                new PropertyDefinition <string>(nameof(ITestProperties.Property2))
                .SetterGetter());

            test.Property2 = "abc";
            Assert.AreEqual(null, test2.Property2);
        }
Beispiel #16
0
        public void TestMethodDefaultPropertyDelegated3()
        {
            DefaultImplementation2 implementation = new DefaultImplementation2();
            BeethovenFactory       factory        = new BeethovenFactory();
            ITestProperties        test           = factory.Generate <ITestProperties>(
                new DefaultProperty()
                .DelegatedSetter(implementation, nameof(implementation.DelegatedSetter)));

            Assert.AreEqual(0, test.Property1);
            test.Property2 = "Nothing";
            test.Property2 = "Some value";
            test.Property1 = 55;
            CollectionAssert.AreEquivalent(new object[] { 55, "Some value" }, implementation.GetObjects());
        }
Beispiel #17
0
        public void TestMethodPropertyDelegatedGetter1()
        {
            int value = 0;
            // ReSharper disable once AccessToModifiedClosure
            Func <int>       action  = () => value;
            BeethovenFactory factory = new BeethovenFactory();
            ITestProperties  test    = factory.Generate <ITestProperties>(
                new PropertyDefinition <int>(nameof(ITestProperties.Property1))
                .DelegatedGetter(action));

            Assert.AreEqual(0, test.Property1);
            value = 5;
            Assert.AreEqual(5, test.Property1);
        }
Beispiel #18
0
        public void EventWithParameters2()
        {
            BeethovenFactory factory   = new BeethovenFactory();
            ITestEvents      test      = factory.Generate <ITestEvents>();
            IEventTrigger    trigger   = factory.CreateEventTrigger(test, nameof(ITestEvents.WithParameters));
            double           gotValue1 = 0;
            string           gotValue2 = null;

            test.WithParameters += (value1, value2) => gotValue1 = value1;
            test.WithParameters += (value1, value2) => gotValue2 = value2;
            trigger.Notify(54.0, "abe");
            Assert.AreEqual(54.0, gotValue1);
            Assert.AreEqual("abe", gotValue2);
        }
        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);
        }
Beispiel #21
0
        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 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 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 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 TestMethodLazyCreatorProperty3()
        {
            int count = 0;
            BeethovenFactory factory = new BeethovenFactory();
            ITestProperties  test    = factory.Generate <ITestProperties>(
                new PropertyDefinition <int>(nameof(ITestProperties.Property1))
                .LazyCreator(() => ++ count)
                .SetterGetter());

            Assert.AreEqual(1, test.Property1);
            Assert.AreEqual(1, test.Property1);
            Assert.AreEqual(1, test.Property1);
            Assert.AreEqual(1, count);
        }
        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);
        }
Beispiel #27
0
        public void LinkedMethodsReturnValueTest4()
        {
            BeethovenFactory beethovenFactory = new BeethovenFactory();
            string           gotValue1        = "";
            string           gotValue2        = "";
            ITestMethods     instance         = beethovenFactory.Generate <ITestMethods>(
                new LinkedMethodsReturnValue(nameof(ITestMethods.WithParameters))
                .Action((string text1) => gotValue1 = text1)
                .Action((string text2) => gotValue2 = text2)
                );

            instance.WithParameters("w", "sd", 3);
            Assert.AreEqual(gotValue1, "w");
            Assert.AreEqual(gotValue2, "sd");
        }
Beispiel #28
0
        public void TestMethodDefaultPropertyFallback1()
        {
            BeethovenFactory factory = new BeethovenFactory();
            ITestProperties  test    = factory.Generate <ITestProperties>(
                new PropertyDefinition <int>(nameof(ITestProperties.Property1))
                .MappedGetter(() => 6),
                new DefaultProperty()
                .SetterGetter());

            Assert.AreEqual(6, test.Property1);
            test.Property2 = "Some value";
            Assert.AreEqual("Some value", test.Property2);
            test.Property1 = 55;
            Assert.AreEqual(6, test.Property1);
        }
        public void TestMethodLazyCreatorProperty2()
        {
            BeethovenFactory factory = new BeethovenFactory();
            ITestProperties  test    = factory.Generate <ITestProperties>(
                new PropertyDefinition <int>(nameof(ITestProperties.Property1))
                .LazyCreator(() =>
            {
                Assert.Fail();
                return(0);
            })
                .SetterGetter());

            test.Property1 = 7;
            Assert.AreEqual(7, test.Property1);
        }
Beispiel #30
0
        public void TestMethodDefaultPropertyNotifyChanged1()
        {
            BeethovenFactory factory = new BeethovenFactory();
            ITestProperties  test    = factory.Generate <ITestProperties>(
                new DefaultProperty()
                .NotifyChanged());
            List <string> changes = new List <string>();

            test.PropertyChanged += (sender, args) => changes.Add(args.PropertyName);
            test.Property1        = 5;
            test.Property2        = "5";
            CollectionAssert.AreEquivalent(
                new[] { "Property1", "Property2" },
                changes);
        }