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_Accessor target = new SolutionListener_Accessor(serviceProvider); target.eventsCookie = cookie; target.Dispose(); uint expected = 0; Assert.AreEqual(expected, target.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); 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 DisposeTest() { try { var serviceProvider = new MockServiceProvider(); var mockUpdateSolutionEvents = new Mock<IVsUpdateSolutionEvents>(); UpdateSolutionListener target = new UpdateSolutionListener(serviceProvider); uint cookie = 0; ((IVsSolutionBuildManager)serviceProvider.GetService(typeof(SVsSolutionBuildManager))).AdviseUpdateSolutionEvents(mockUpdateSolutionEvents.Instance as IVsUpdateSolutionEvents, out cookie); Debug.Assert(cookie == 1); bool disposing = true; PrivateObject updateSolutionListner = new PrivateObject(target, new PrivateType(typeof(UpdateSolutionListener))); updateSolutionListner.SetFieldOrProperty("eventsCookie", cookie); updateSolutionListner.Invoke("Dispose", disposing); } catch (Exception ex) { // Use try catch to test a workaround on CI build (AppVeyor) Console.WriteLine(ex.Message); } }
public void DisposeTest() { var serviceProvider = new MockServiceProvider(); var mockUpdateSolutionEvents = new Mock<IVsUpdateSolutionEvents>(); UpdateSolutionListener target = new UpdateSolutionListener(serviceProvider); uint cookie = 0; ((IVsSolutionBuildManager)serviceProvider.GetService(typeof(SVsSolutionBuildManager))).AdviseUpdateSolutionEvents(mockUpdateSolutionEvents.Instance as IVsUpdateSolutionEvents, out cookie); Debug.Assert(cookie == 1); target.GetType() .GetField("eventsCookie", BindingFlags.Instance | BindingFlags.NonPublic) .SetValue(target, cookie); target.Dispose(); }
public void DisposeTest() { var serviceProvider = new MockServiceProvider(); var mockUpdateSolutionEvents = new Mock<IVsUpdateSolutionEvents>(); UpdateSolutionListener target = new UpdateSolutionListener(serviceProvider); uint cookie = 0; ((IVsSolutionBuildManager)serviceProvider.GetService(typeof(SVsSolutionBuildManager))).AdviseUpdateSolutionEvents(mockUpdateSolutionEvents.Instance as IVsUpdateSolutionEvents, out cookie); Debug.Assert(cookie == 1); bool disposing = true; PrivateObject updateSolutionListner = new PrivateObject(target, new PrivateType(typeof(UpdateSolutionListener))); updateSolutionListner.SetFieldOrProperty("eventsCookie", cookie); updateSolutionListner.Invoke("Dispose", disposing); }
public void DisposeTest() { var serviceProvider = new MockServiceProvider(); var mockUpdateSolutionEvents = new Mock<IVsUpdateSolutionEvents>(); UpdateSolutionListener_Accessor target = new UpdateSolutionListener_Accessor(serviceProvider); uint cookie = 0; ((IVsSolutionBuildManager)serviceProvider.GetService(typeof(SVsSolutionBuildManager))).AdviseUpdateSolutionEvents(mockUpdateSolutionEvents.Instance as IVsUpdateSolutionEvents, out cookie); Debug.Assert(cookie == 1); bool disposing = true; target.eventsCookie = cookie; target.Dispose(disposing); }