예제 #1
0
        public void TestMethodProperty5()
        {
            TypeDefinition <ITestProperties> definition =
                TypeDefinition <ITestProperties> .Create()
                .Add(new PropertyDefinition <int>(nameof(ITestProperties.Property1))
                     .SetterGetter());

            CompiledTypeDefinition <ITestProperties> compiledTypeDefinition = definition.Compile();
            ITestProperties test1 = compiledTypeDefinition.Create();
            ITestProperties test2 = compiledTypeDefinition.Create();

            test1.Property1 = 42;
            Assert.AreEqual(0, test2.Property1);
        }
예제 #2
0
        public void ConstructorInitializedFieldInitialValueTest3()
        {
            CompiledTypeDefinition <ITestProperties> compiledTypeDefinition =
                TypeDefinition <ITestProperties> .Create()
                .Add(new PropertyDefinition <int>(nameof(ITestProperties.Property1))
                     .ConstructorParameter()
                     .SetterGetter())
                .Compile();

            ITestProperties test1 = compiledTypeDefinition.Create(5);
            ITestProperties test2 = compiledTypeDefinition.Create(4);

            Assert.AreEqual(5, test1.Property1);
            Assert.AreEqual(4, test2.Property1);
        }
예제 #3
0
        public void ConstructorInitializedFieldInitialValueTest2()
        {
            CompiledTypeDefinition <ITestProperties> definition =
                TypeDefinition <ITestProperties> .Create()
                .Add(new PropertyDefinition <int>(nameof(ITestProperties.Property1))
                     .ConstructorParameter()
                     .SetterGetter())
                .Compile();

            ITestProperties test = definition.Create(17);

            test.Property1 = 50;
            Assert.AreEqual(50, test.Property1);
        }
예제 #4
0
        public void ConstructorInitializedFieldEventWithReturnValue1()
        {
            CompiledTypeDefinition <ITestEvents> compiledTypeDefinition =
                TypeDefinition <ITestEvents> .Create().Compile();

            ITestEvents     test    = compiledTypeDefinition.Create();
            Action <string> trigger =
                new EventTrigger(test, nameof(ITestEvents.WithReturnValue)).ToAction <string>();
            bool withReturnValueEventCalled = false;
            bool otherEventCalled           = false;

            test.Simple          += delegate { otherEventCalled = true; };
            test.WithParameters  += delegate { otherEventCalled = true; };
            test.WithReturnValue += delegate { return(withReturnValueEventCalled = true); };
            trigger("");
            Assert.IsTrue(withReturnValueEventCalled);
            Assert.IsFalse(otherEventCalled);
        }