Esempio n. 1
0
        public void ExecuteFunctionProperly()
        {
            var obj     = new TestFunctionClass();
            var wrapper = new ImplBaseTester(obj);

            Assert.AreEqual(42, wrapper.ExecuteFunction(nameof(obj.Function), new[] { typeof(int) }, 42));
        }
Esempio n. 2
0
        public void ExecuteMethodProperlyWithGivenParameterTypes()
        {
            var obj     = new TestMethodClass();
            var wrapper = new ImplBaseTester(obj);

            wrapper.ExecuteMethod2(nameof(obj.Method), new[] { typeof(int) }, 42);
            Assert.IsTrue(obj.CorrectMethodExecuted);
        }
Esempio n. 3
0
        public void ExecuteMethodProperly()
        {
            var obj     = new TestMethodClass();
            var wrapper = new ImplBaseTester(obj);

            wrapper.ExecuteMethod(nameof(obj.Method), 42);
            Assert.IsTrue(obj.CorrectMethodExecuted);
        }
Esempio n. 4
0
        public void AttachEventCorrectly()
        {
            var obj     = new TestEventClass();
            var wrapper = new ImplBaseTester(obj);

            wrapper.AddEvent <EventArgs>(nameof(TestEventClass.Event), nameof(ImplBaseTester.HandleEvent));
            obj.FireEvent();
            Assert.IsTrue(wrapper.EventCalled);
        }
Esempio n. 5
0
        public void ReturnCorrectPropertyValue()
        {
            var obj = new TestPropertyClass {
                Property = 42
            };
            var wrapper = new ImplBaseTester(obj);

            Assert.AreEqual(42, wrapper.GetProperty <int>(nameof(obj.Property)));
        }
Esempio n. 6
0
        public void ThrowExceptionIfParametersIsNull()
        {
            var obj     = new TestMethodClass();
            var wrapper = new ImplBaseTester(obj);

            var ex = Assert.Throws <ArgumentNullException>(() => wrapper.ExecuteMethod(nameof(obj.Method), null));

            Assert.IsNotNull(ex);
            ex.ParamName.Should().Be("parameters");
        }
Esempio n. 7
0
        public void ThrowExceptionIfMethodNameIsInvalid()
        {
            var obj     = new TestMethodClass();
            var wrapper = new ImplBaseTester(obj);

            var ex = Assert.Throws <ArgumentOutOfRangeException>(() => wrapper.ExecuteMethod("invalid", 42));

            Assert.IsNotNull(ex);
            ex.Message.Should().Be($"Class method with given name does not exist!{Environment.NewLine}Parameter name: methodName");
        }
Esempio n. 8
0
        public void DetachEventCorrectly()
        {
            var obj     = new TestEventClass();
            var wrapper = new ImplBaseTester(obj);

            obj.Event += wrapper.HandleEvent;
            wrapper.RemoveEvent <EventArgs>(nameof(TestEventClass.Event), nameof(ImplBaseTester.HandleEvent));
            obj.FireEvent();
            Assert.IsFalse(wrapper.EventCalled);
        }
Esempio n. 9
0
        public void ThrowExceptionIfHandlerNameIsNull()
        {
            var obj     = new TestEventClass();
            var wrapper = new ImplBaseTester(obj);

            var ex = Assert.Throws <ArgumentNullException>(() => wrapper.AddEvent <EventArgs>(nameof(TestEventClass.Event), null));

            Assert.IsNotNull(ex);
            ex.ParamName.Should().Be("handlerName");
        }
Esempio n. 10
0
        public void SetPropertyCorrectly()
        {
            var obj = new TestPropertyClass {
                Property = 13
            };
            var wrapper = new ImplBaseTester(obj);

            wrapper.SetProperty(nameof(TestPropertyClass.Property), 42);
            Assert.AreEqual(42, obj.Property);
        }
Esempio n. 11
0
        public void ThrowExceptionIfPropertyAccessMethodDoesNotExist()
        {
            var obj     = new TestPropertyClass();
            var wrapper = new ImplBaseTester(obj);

            var ex = Assert.Throws <ArgumentOutOfRangeException>(() => wrapper.GetProperty <int>(nameof(obj.WriteOnlyProperty)));

            Assert.IsNotNull(ex);
            ex.Message.Should().Be($"Specified argument was out of the range of valid values.{Environment.NewLine}Parameter name: Property get does not exist for WriteOnlyProperty!");
        }
Esempio n. 12
0
        public void ThrowExceptionIfPropertyDoesNotExist()
        {
            var obj     = new TestPropertyClass();
            var wrapper = new ImplBaseTester(obj);

            var ex = Assert.Throws <ArgumentOutOfRangeException>(() => wrapper.GetProperty <int>("invalid"));

            Assert.IsNotNull(ex);
            ex.Message.Should().Be($"Property does not exist!{Environment.NewLine}Parameter name: propertyName");
        }
Esempio n. 13
0
        public void ThrowExceptionIfPropertyNameIsNull()
        {
            var obj     = new TestPropertyClass();
            var wrapper = new ImplBaseTester(obj);

            var ex = Assert.Throws <ArgumentNullException>(() => wrapper.GetProperty <int>(null));

            Assert.IsNotNull(ex);
            ex.ParamName.Should().Be("propertyName");
        }
Esempio n. 14
0
        public void ThrowExceptionIfEventNameIsInvalid()
        {
            var obj     = new TestEventClass();
            var wrapper = new ImplBaseTester(obj);

            var ex = Assert.Throws <ArgumentOutOfRangeException>(
                () => wrapper.AddEvent <EventArgs>("InvalidEvent", nameof(ImplBaseTester.HandleEvent)));

            Assert.IsNotNull(ex);
            ex.Message.Should().Be($"Invalid event name supplied!{Environment.NewLine}Parameter name: eventName");
        }
Esempio n. 15
0
        public void ThrowExceptionIfHandlerHasIncorrectSignature()
        {
            var obj     = new TestEventClass();
            var wrapper = new ImplBaseTester(obj);

            var ex = Assert.Throws <ArgumentOutOfRangeException>(
                () => wrapper.AddEvent <EventArgs>(nameof(TestEventClass.Event),
                                                   nameof(ImplBaseTester.HandleEvent2)));

            Assert.IsNotNull(ex);
            ex.Message.Should().Be($"Invalid handler name supplied!{Environment.NewLine}Parameter name: handlerName");
        }