示例#1
0
        public void DisposeTest()
        {
            var serviceProvider    = new MockServiceProvider();
            var mockSolutionEvents = new Mock <IVsSolutionEvents>();

            uint cookie = 0;

            ((IVsSolution)serviceProvider.GetService(typeof(SVsSolution))).AdviseSolutionEvents(mockSolutionEvents.Instance as IVsSolutionEvents, out cookie);
            Debug.Assert(cookie == 1);

            SolutionListener target = new SolutionListener(serviceProvider);

            PrivateObject solutionListner = new PrivateObject(target, new PrivateType(typeof(SolutionListener)));

            solutionListner.SetFieldOrProperty("eventsCookie", cookie);
            target.Dispose();

            uint expected = 0;

            Assert.AreEqual(expected, solutionListner.GetFieldOrProperty("eventsCookie"), "Dispose does not remove the event sink");
        }
示例#2
0
        public void DisposeTest()
        {
            var serviceProvider    = new MockServiceProvider();
            var mockSolutionEvents = new Mock <IVsSolutionEvents>(MockBehavior.Strict);

            uint cookie = 0;

            ((IVsSolution)serviceProvider.GetService(typeof(SVsSolution))).AdviseSolutionEvents(mockSolutionEvents.Object, out cookie);
            Debug.Assert(cookie == 1);

            SolutionListener target = new SolutionListener(serviceProvider);

            typeof(SolutionListener).GetField("eventsCookie", BindingFlags.Instance | BindingFlags.NonPublic)
            .SetValue(target, cookie);
            target.Dispose();

            uint expected = 0;

            Assert.AreEqual(expected,
                            typeof(SolutionListener).GetField("eventsCookie", BindingFlags.Instance | BindingFlags.NonPublic)
                            .GetValue(target), "Dispose does not remove the event sink");
        }