Exemple #1
0
        public void Methods_NoSuchEvent_ThrowsNullReferenceException()
        {
            var attribute = new ComAwareEventInfo(typeof(NonComObject), string.Empty);

            Assert.Throws <NullReferenceException>(() => attribute.AddEventHandler(new object(), new EventHandler(EventHandler)));
            Assert.Throws <NullReferenceException>(() => attribute.RemoveEventHandler(new object(), new EventHandler(EventHandler)));
            Assert.Throws <NullReferenceException>(() => attribute.GetAddMethod(false));
            Assert.Throws <NullReferenceException>(() => attribute.GetRaiseMethod(false));
            Assert.Throws <NullReferenceException>(() => attribute.GetRemoveMethod(false));
            Assert.Throws <NullReferenceException>(() => attribute.GetCustomAttributes(typeof(ComVisibleAttribute), false));
            Assert.Throws <NullReferenceException>(() => attribute.GetCustomAttributes(false));
            Assert.Throws <NullReferenceException>(() => attribute.IsDefined(typeof(ComVisibleAttribute), false));
        }
Exemple #2
0
        public void Ctor_Type_EventName()
        {
            EventInfo expectedEvent = typeof(NonComObject).GetEvent(nameof(NonComObject.Event));
            var       attribute     = new ComAwareEventInfo(typeof(NonComObject), nameof(NonComObject.Event));

            Assert.Equal(expectedEvent.Attributes, attribute.Attributes);
            Assert.Equal(expectedEvent.DeclaringType, attribute.DeclaringType);
            Assert.Equal(expectedEvent.Name, attribute.Name);
            Assert.Equal(expectedEvent.ReflectedType, attribute.ReflectedType);

            Assert.Equal(expectedEvent.GetAddMethod(), attribute.GetAddMethod());
            Assert.Equal(expectedEvent.GetRaiseMethod(), attribute.GetRaiseMethod());
            Assert.Equal(expectedEvent.GetRemoveMethod(), attribute.GetRemoveMethod());

            Assert.Equal(expectedEvent.GetCustomAttributes(typeof(ExcludeFromCodeCoverageAttribute), true), attribute.GetCustomAttributes(typeof(ExcludeFromCodeCoverageAttribute), true));
            Assert.Equal(expectedEvent.GetCustomAttributes(true), attribute.GetCustomAttributes(true));
            Assert.Equal(expectedEvent.IsDefined(typeof(ExcludeFromCodeCoverageAttribute)), attribute.IsDefined(typeof(ExcludeFromCodeCoverageAttribute)));
        }