public void No_Session_Throws() { var services = new MockContainer(MockBehavior.Strict) .Push <IVariableService, MockVariableService>() .GetValue <RestartManagerSession>(SessionManager.VariableName, () => null) .Pop(); using (fixture.UseServices(services)) { var sut = fixture.Create() .AddCommand(CommandName); var ex = Assert.Throws <CmdletInvocationException>(() => sut.Invoke()); Assert.IsType <NoSessionException>(ex.InnerException); } services.Verify(); }
public void Session_Disposed() { var services = new MockContainer(MockBehavior.Strict) .Push <IRestartManagerService>() .Pop(); var session = new RestartManagerSession(services); session.Dispose(); services.Verify <IRestartManagerService>(x => x.EndSession(0), Times.Once); fixture.Create() .AddCommand(CommandName) .AddParameter("Session", session) .Invoke(); services.Verify <IRestartManagerService>(x => x.EndSession(0), Times.Once); }
public void Creates_Session_Throws() { var services = new MockContainer(MockBehavior.Strict) .Push <IRestartManagerService>(error: NativeMethods.ERROR_OUTOFMEMORY) .Pop() .Push <IVariableService, MockVariableService>() .GetValue <RestartManagerSession>(SessionManager.VariableName, () => null) .Pop(); using (fixture.UseServices(services)) { var sut = fixture.Create() .AddCommand(CommandName) .AddParameter("PassThru"); var ex = Assert.Throws <CmdletInvocationException>(() => sut.Invoke()); Assert.IsType <OutOfMemoryException>(ex.InnerException); } services.Verify(); }
public void ProcessRecord_Throws() { var services = new MockContainer(MockBehavior.Strict) .Push <IRestartManagerService>() .RegisterResources() .GetProcesses(error: NativeMethods.ERROR_OUTOFMEMORY) .Pop(); using (var session = new RestartManagerSession(services)) { session.RegisterResources(files: new[] { @"C:\ShouldNotExist.txt" }); var sut = fixture.Create() .AddCommand(CommandName) .AddParameter("Session", session); var ex = Assert.Throws <CmdletInvocationException>(() => sut.Invoke()); Assert.IsType <OutOfMemoryException>(ex.InnerException); } services.Verify(); }