public void RestartProcesses() { 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.RestartProcesses(sessionId, 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.RestartProcesses(); } rmMock.Verify(); }
public void RegisterResources() { 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.RegisterResources(sessionId, It.IsAny <IEnumerable <string> >(), It.IsAny <IEnumerable <RM_UNIQUE_PROCESS> >(), It.IsAny <IEnumerable <string> >())).Returns(NativeMethods.ERROR_SUCCESS); var files = new HashSet <string>(StringComparer.OrdinalIgnoreCase) { @"C:\ShouldNotExist", }; using (var sut = new RestartManagerSession(services)) { sut.RegisterResources(files: files); } rmMock.Verify(x => x.RegisterResources(1, It.Is <IEnumerable <string> >(y => files.SetEquals(y)), null, null), Times.Once); }
public void New_Starts_Session() { 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); using (var sut = new RestartManagerSession(services)) { Assert.Equal(1, sut.SessionId); Assert.Equal("1234abcd", sut.SessionKey); } }
public void RestartProcesses_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.RestartProcesses(sessionId, It.IsAny <RM_WRITE_STATUS_CALLBACK>())).Returns(NativeMethods.ERROR_OUTOFMEMORY); using (var sut = new RestartManagerSession(services)) { Assert.Throws <OutOfMemoryException>(() => sut.RestartProcesses()); } }
public void RegisterResources_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.RegisterResources(sessionId, It.IsAny <IEnumerable <string> >(), It.IsAny <IEnumerable <RM_UNIQUE_PROCESS> >(), It.IsAny <IEnumerable <string> >())).Returns(NativeMethods.ERROR_OUTOFMEMORY); using (var sut = new RestartManagerSession(services)) { Assert.Throws <OutOfMemoryException>(() => sut.RegisterResources(files: new[] { @"C:\ShouldNotExist" })); } }
public void RegisterResources_No_Resources() { 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); using (var sut = new RestartManagerSession(services)) { sut.RegisterResources(); } rmMock.Verify(x => x.RegisterResources(It.IsAny <int>(), It.IsAny <IEnumerable <string> >(), It.IsAny <IEnumerable <RM_UNIQUE_PROCESS> >(), It.IsAny <IEnumerable <string> >()), Times.Never); }
public void RegisterResources_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.RegisterResources(files: new[] { @"C:\ShouldNotExist" })); }
public void Dispose_Ends_Session() { 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); using (var sut = new RestartManagerSession(services)) { // Make sure we do not attempt to end again. sut.Dispose(); Assert.True(sut.IsDisposed); } rmMock.Verify(x => x.EndSession(1), Times.Once); }