Exemplo n.º 1
0
        public void CreateAndDispose_intermediateFilterRegistredAndLeft_exceptionThrown()
        {
            Exception      gotException       = null;
            IMessageFilter intermediateFilter = null;
            var            thread             = new Thread(() =>
            {
                intermediateFilter = new TestMessageFilter();
                try
                {
                    using (new StaComCrossThreadInvoker())
                    {
                        IMessageFilter commonFilter = null;
                        NativeMethods.CoRegisterMessageFilter(intermediateFilter, out commonFilter);
                    }
                }
                catch (Exception ex)
                {
                    gotException = ex;
                }
            });

            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
            thread.Join();

            Assert.IsInstanceOf <InvalidOperationException>(gotException);
        }
        public void CreateAndDispose_intermediateFilterRegistredAndLeft_exceptionThrown()
        {
            Exception gotException = null;
            IMessageFilter intermediateFilter = null;
            var thread = new Thread(() =>
            {
                intermediateFilter = new TestMessageFilter();
                try
                {
                    using (new StaComCrossThreadInvoker())
                    {
                        IMessageFilter commonFilter = null;
                        NativeMethods.CoRegisterMessageFilter(intermediateFilter, out commonFilter);
                    }
                }
                catch (Exception ex)
                {
                    gotException = ex;
                }
            });
            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
            thread.Join();

            Assert.IsInstanceOf<InvalidOperationException>(gotException);
        }
Exemplo n.º 3
0
        public void CreateAndDispose_previousFilterRegistered_previousFilterReturned()
        {
            IMessageFilter noFilterByDefault  = null;
            IMessageFilter testFilter         = null;
            IMessageFilter testFilterReturned = null;
            var            thread             = new Thread(() =>
            {
                testFilter = new TestMessageFilter();
                NativeMethods.CoRegisterMessageFilter(testFilter, out noFilterByDefault);
                using (new StaComCrossThreadInvoker())
                {
                }
                NativeMethods.CoRegisterMessageFilter(null, out testFilterReturned);
            });

            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
            thread.Join();

            Assert.IsNull(noFilterByDefault);
            Assert.AreEqual(testFilter, testFilterReturned);
        }
        public void CreateAndDispose_previousFilterRegistered_previousFilterReturned()
        {
            IMessageFilter noFilterByDefault = null;
            IMessageFilter testFilter = null;
            IMessageFilter testFilterReturned = null;
            var thread = new Thread(() =>
                                        {
                                            testFilter = new TestMessageFilter();
                                            NativeMethods.CoRegisterMessageFilter(testFilter, out noFilterByDefault);
                                            using (new StaComCrossThreadInvoker())
                                            {

                                            }
                                            NativeMethods.CoRegisterMessageFilter(null, out testFilterReturned);
                                        });
            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
            thread.Join();

            Assert.IsNull(noFilterByDefault);
            Assert.AreEqual(testFilter,testFilterReturned);
        }