Exemplo n.º 1
0
        /// <summary>
        /// Disposes the contents of the class.
        /// </summary>
        /// <param name="disposing">Indicates whether to dispose unmanaged resources.</param>
        protected override void Dispose(bool disposing)
        {
            Param.Ignore(disposing);

            base.Dispose(disposing);

            if (disposing)
            {
                if (this.taskProvider != null)
                {
                    this.taskProvider.Dispose();
                    this.taskProvider = null;
                }

                if (this.solutionListener != null)
                {
                    this.solutionListener.Dispose();
                    this.solutionListener = null;
                }

                if (this.updateListener != null)
                {
                    this.updateListener.Dispose();
                    this.updateListener = null;
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Register for the environment events.
        /// </summary>
        protected override void RegisterEnvironmentEvents()
        {
            this.updateListener             = new UpdateSolutionListener(this.ServiceProvider);
            this.updateListener.BeginBuild += this.BuildEventsOnBuildBegin;
            this.updateListener.Initialize();

            this.solutionListener = new SolutionListener(this.ServiceProvider);
            this.solutionListener.AfterSolutionOpened   += this.SolutionOpenedEventHandler;
            this.solutionListener.BeforeClosingSolution += this.SolutionClosingEventHandler;
            this.solutionListener.Initialize();
        }
        public void EventsCookieTest()
        {
            var serviceProvider = new MockServiceProvider();
            SolutionListener target = new SolutionListener(serviceProvider);
            uint expected = 0;

            uint actual = (uint)typeof(SolutionListener)
                .GetField("eventsCookie", BindingFlags.Instance | BindingFlags.NonPublic)
                .GetValue(target);
            Assert.AreEqual(expected, actual, "initial value should be zero");

            target.Initialize();

            actual = (uint)typeof(SolutionListener)
                .GetField("eventsCookie", BindingFlags.Instance | BindingFlags.NonPublic)
                .GetValue(target);
            Assert.IsTrue(expected < actual, "Value after initialize should not be zero.");
        }
        public void EventsCookieTest()
        {
            var serviceProvider = new MockServiceProvider();
            SolutionListener target = new SolutionListener(serviceProvider);
            uint expected = 0;


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


            uint actual = (uint)solutionListner.GetFieldOrProperty("eventsCookie");
            Assert.AreEqual(expected, actual, "initial value should be zero");

            target.Initialize();

            actual = (uint)solutionListner.GetFieldOrProperty("eventsCookie");
            Assert.IsTrue(expected < actual, "Value after initialize should not be zero.");
        }
        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");
        }
        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);
            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");
        }
        public void OnAfterOpenSolutionTest()
        {
            IServiceProvider serviceProvider = this.PrepareServiceProvider();
            SolutionListener target = new SolutionListener(serviceProvider);

            bool eventFired = false;
            target.AfterSolutionOpened += (sender, args) => { eventFired = true; };
            int expected = VSConstants.S_OK;
            int actual = target.OnAfterOpenSolution(null, 0);
            Assert.AreEqual(expected, actual);
            Assert.IsTrue(eventFired, "Event was not fired");
        }
        public void SolutionTest()
        {
            IServiceProvider serviceProvider = this.PrepareServiceProvider();
            SolutionListener target = new SolutionListener(serviceProvider);

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

            IVsSolution actual = (IVsSolution)solutionListner.GetFieldOrProperty("solution");
            Assert.IsNotNull(actual, "Cnstructor did not get the solution class.");
        }
 public void SolutionListenerConstructorTest()
 {
     IServiceProvider serviceProvider = this.PrepareServiceProvider();
     SolutionListener target = new SolutionListener(serviceProvider);
     Assert.IsNotNull(target);
 }
Exemplo n.º 10
0
 public void OnQueryUnloadProjectTest()
 {
     IServiceProvider serviceProvider = this.PrepareServiceProvider();
     SolutionListener target = new SolutionListener(serviceProvider);
     IVsHierarchy pRealHierarchy = null; // TODO: Initialize to an appropriate value
     int pfCancel = 0; // TODO: Initialize to an appropriate value
     int pfCancelExpected = 0; // TODO: Initialize to an appropriate value
     int expected = VSConstants.E_NOTIMPL;
     int actual;
     actual = target.OnQueryUnloadProject(pRealHierarchy, ref pfCancel);
     Assert.AreEqual(pfCancelExpected, pfCancel);
     Assert.AreEqual(expected, actual);
 }
Exemplo n.º 11
0
 public void OnQueryCloseSolutionTest()
 {
     IServiceProvider serviceProvider = this.PrepareServiceProvider();
     SolutionListener target = new SolutionListener(serviceProvider);
     object pUnkReserved = null; // TODO: Initialize to an appropriate value
     int pfCancel = 0; // TODO: Initialize to an appropriate value
     int pfCancelExpected = 0; // TODO: Initialize to an appropriate value
     int expected = VSConstants.E_NOTIMPL;
     int actual;
     actual = target.OnQueryCloseSolution(pUnkReserved, ref pfCancel);
     Assert.AreEqual(pfCancelExpected, pfCancel);
     Assert.AreEqual(expected, actual);
 }
Exemplo n.º 12
0
 public void OnBeforeOpeningChildrenTest()
 {
     IServiceProvider serviceProvider = this.PrepareServiceProvider();
     SolutionListener target = new SolutionListener(serviceProvider);
     IVsHierarchy hierarchy = null; // TODO: Initialize to an appropriate value
     int expected = VSConstants.E_NOTIMPL;
     int actual;
     actual = target.OnBeforeOpeningChildren(hierarchy);
     Assert.AreEqual(expected, actual);
 }
 public void SolutionTest()
 {
     IServiceProvider serviceProvider = this.PrepareServiceProvider();
     SolutionListener target = new SolutionListener(serviceProvider);
     IVsSolution actual = (IVsSolution)typeof(SolutionListener)
         .GetField("solution", BindingFlags.Instance | BindingFlags.NonPublic)
         .GetValue(target);
     Assert.IsNotNull(actual, "Cnstructor did not get the solution class.");
 }
Exemplo n.º 14
0
 public void OnAfterOpenProjectTest()
 {
     IServiceProvider serviceProvider = this.PrepareServiceProvider();
     SolutionListener target = new SolutionListener(serviceProvider);
     IVsHierarchy hierarchy = null; // TODO: Initialize to an appropriate value
     int fAdded = 0; // TODO: Initialize to an appropriate value
     int expected = VSConstants.E_NOTIMPL;
     int actual;
     actual = target.OnAfterOpenProject(hierarchy, fAdded);
     Assert.AreEqual(expected, actual);
 }
Exemplo n.º 15
0
        public void InitializeTest()
        {
            var serviceProvider = new MockServiceProvider();
            SolutionListener target = new SolutionListener(serviceProvider);
            uint expected = 0;

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

            Assert.AreEqual(expected, solutionListner.GetFieldOrProperty("eventsCookie"));

            expected = 1;
            solutionListner.SetFieldOrProperty("eventsCookie", expected);
            target.Initialize();
            Assert.AreEqual(expected, solutionListner.GetFieldOrProperty("eventsCookie"));
        }
        /// <summary>
        /// Register for the environment events.
        /// </summary>
        protected override void RegisterEnvironmentEvents()
        {
            this.updateListener = new UpdateSolutionListener(this.ServiceProvider);
            this.updateListener.BeginBuild += this.BuildEventsOnBuildBegin;
            this.updateListener.Initialize();

            this.solutionListener = new SolutionListener(this.ServiceProvider);
            this.solutionListener.AfterSolutionOpened += this.SolutionOpenedEventHandler;
            this.solutionListener.BeforeClosingSolution += this.SolutionClosingEventHandler;
            this.solutionListener.Initialize();
        }
        /// <summary>
        /// Disposes the contents of the class.
        /// </summary>
        /// <param name="disposing">Indicates whether to dispose unmanaged resources.</param>
        protected override void Dispose(bool disposing)
        {
            Param.Ignore(disposing);

            base.Dispose(disposing);

            if (disposing)
            {
                if (this.taskProvider != null)
                {
                    this.taskProvider.Dispose();
                    this.taskProvider = null;
                }

                if (this.solutionListener != null)
                {
                    this.solutionListener.Dispose();
                    this.solutionListener = null;
                }

                if (this.updateListener != null)
                {
                    this.updateListener.Dispose();
                    this.updateListener = null;
                }
            }
        }
Exemplo n.º 18
0
        public void OnBeforeCloseSolutionTest()
        {
            var serviceProvider = new MockServiceProvider();

            SolutionListener target = new SolutionListener(serviceProvider);

            bool eventFired = false;
            target.BeforeClosingSolution += (sender, args) => { eventFired = true; };
            int expected = VSConstants.S_OK;
            int actual = target.OnBeforeCloseSolution(null);
            Assert.AreEqual(expected, actual);
            Assert.IsTrue(eventFired, "Event was not fired");
        }
        public void InitializeTest()
        {
            var serviceProvider = new MockServiceProvider();
            SolutionListener target = new SolutionListener(serviceProvider);
            uint expected = 0;
            Assert.AreEqual(expected, (uint)typeof(SolutionListener)
                .GetField("eventsCookie", BindingFlags.Instance | BindingFlags.NonPublic)
                .GetValue(target));

            expected = 1;
            typeof(SolutionListener).GetField("eventsCookie", BindingFlags.Instance | BindingFlags.NonPublic)
                .SetValue(target, expected);
            target.Initialize();
            Assert.AreEqual(expected, (uint)typeof(SolutionListener)
                .GetField("eventsCookie", BindingFlags.Instance | BindingFlags.NonPublic)
                .GetValue(target));
        }