public void ShutdownProcesses() { var services = new ServiceContainer(); var rmMock = new Mock <IRestartManagerService>(); services.AddService(rmMock.Object); var sessionId = 1; var sessionKey = "1234abcd"; rmMock.Setup(x => x.StartSession(out sessionId, out sessionKey)).Returns(NativeMethods.ERROR_SUCCESS); rmMock.Setup(x => x.ShutdownProcesses(sessionId, 0, It.IsAny <RM_WRITE_STATUS_CALLBACK>())).Returns(NativeMethods.ERROR_SUCCESS).Verifiable(); var files = new HashSet <string>(StringComparer.OrdinalIgnoreCase) { @"C:\ShouldNotExist", }; using (var sut = new RestartManagerSession(services)) { sut.ShutdownProcesses(); } rmMock.Verify(); }
public void ShutdownProcesses_Throws() { var services = new ServiceContainer(); var rmMock = new Mock <IRestartManagerService>(); services.AddService(rmMock.Object); var sessionId = 1; var sessionKey = "1234abcd"; rmMock.Setup(x => x.StartSession(out sessionId, out sessionKey)).Returns(NativeMethods.ERROR_SUCCESS); rmMock.Setup(x => x.ShutdownProcesses(sessionId, RM_SHUTDOWN_TYPE.RmForceShutdown, It.IsAny <RM_WRITE_STATUS_CALLBACK>())).Returns(NativeMethods.ERROR_OUTOFMEMORY); using (var sut = new RestartManagerSession(services)) { Assert.Throws <OutOfMemoryException>(() => sut.ShutdownProcesses(force: true)); } }
public void ShutdownProcesses_Disposed_Throws() { var services = new ServiceContainer(); var rmMock = new Mock <IRestartManagerService>(); services.AddService(rmMock.Object); var sessionId = 1; var sessionKey = "1234abcd"; rmMock.Setup(x => x.StartSession(out sessionId, out sessionKey)).Returns(NativeMethods.ERROR_SUCCESS); RestartManagerSession sut; using (sut = new RestartManagerSession(services)) { } Assert.Throws <ObjectDisposedException>(() => sut.ShutdownProcesses()); }