public void Start_ServiceAppProcessCanStartSucessfully() { ILog log = Substitute.For <ILog>(); bool monitorMethodCalled = false; IProcessWrapperFactory procFactory = Substitute.For <IProcessWrapperFactory>(); procFactory.CreateProcess().Returns(new FakeStandardProcess()); var serviceApp = new ServiceApp { Name = "Test", AppVersion = new Version() }; ServiceAppProcess appProcToTest = new ServiceAppProcess(serviceApp, log, procFactory); appProcToTest.MonitorProcessCallback = () => { monitorMethodCalled = true; }; Task t = appProcToTest.Start(); bool success = t.Wait(500); if (!success) { Assert.Fail("Start() took too long to finish"); } log.DidNotReceive().Error(Arg.Any <object>(), Arg.Any <Exception>()); log.DidNotReceive().Warn(Arg.Any <object>(), Arg.Any <Exception>()); Assert.IsTrue(monitorMethodCalled, "MonitorProcessCallback() not called."); }
public void ProcessError_LoggingWorksWithUnrecognizedExceptionObject() { ILog log = Substitute.For <ILog>(); IProcessWrapperFactory procFactory = Substitute.For <IProcessWrapperFactory>(); procFactory.CreateProcess().Returns(new FakeStandardProcess()); var serviceApp = new ServiceApp { Name = "Test", AppVersion = new Version() }; ServiceAppProcess appProcToTest = new ServiceAppProcess(serviceApp, log, procFactory); Exception testException = new InvalidOperationException("test"); string exceptionMessage = string.Format(@"{{ error: {{ details: {{ type: ""{0}"", message: ""{1}"", source: ""{2}"", stackTrace: ""{3}"" }}, exception: ""xxxxx"" }} }}", testException.GetType().ToString(), testException.Message, testException.Source, testException.StackTrace); bool shouldExit = appProcToTest.ProcessMessage(exceptionMessage); log.Received().Warn(Arg.Any <string>()); Assert.IsFalse(shouldExit, "Process message was not meant to return true"); }
/// <summary> /// Instantiate a new ArpScanner object with the provided ProcessWrapperFactory. /// </summary> /// <param name="processWrapperFactory">ProcessWrapperFactory - used to generate the process /// to run the ARP scan.</param> public ArpScanner(IProcessWrapperFactory processWrapperFactory) { if (processWrapperFactory == null) { throw new NullReferenceException("ArpScanner: ProcessWrapper cannot be null."); } processWrapperFactory_m = processWrapperFactory; }
public void Constructor_ServiceAppProcessConstructorHasNoSurprises() { IProcessWrapperFactory procFactory = Substitute.For <IProcessWrapperFactory>(); procFactory.CreateProcess().Returns(new FakeStandardProcess()); ServiceAppProcess appProcToTest = new ServiceAppProcess( new ServiceApp { Name = "Test" }, Substitute.For <ILog>(), procFactory); }
public void ProcessMessage_DebugIsLogged() { ILog log = Substitute.For <ILog>(); IProcessWrapperFactory procFactory = Substitute.For <IProcessWrapperFactory>(); procFactory.CreateProcess().Returns(new FakeStandardProcess()); var serviceApp = new ServiceApp { Name = "Test", AppVersion = new Version() }; ServiceAppProcess appProcToTest = new ServiceAppProcess(serviceApp, log, procFactory); bool shouldExit = appProcToTest.ProcessMessage("{debug:\"test\"}"); log.Received().Debug("From Test: test"); Assert.IsFalse(shouldExit, "Process message was not meant to return true"); }
/// <summary> /// Initializes a new instance of the <see cref="ServiceAppProcess"/> class. /// </summary> /// <param name="app">The application.</param> /// <param name="log">The log.</param> /// <param name="processFactory">The factory that creates <see cref="ProcessWrapper"/> instances.</param> /// <exception cref="System.ArgumentNullException">app;Cannot create ServiceAppProcess with null ServiceApp</exception> /// <exception cref="System.ArgumentException">Cannot create ServiceAppProcess with null or empty ServiceApp name</exception> internal ServiceAppProcess(ServiceApp app, ILog log, IProcessWrapperFactory processFactory) { if (app == null) { throw new ArgumentNullException("app", "Cannot create ServiceAppProcess with null ServiceApp"); } if (string.IsNullOrWhiteSpace(app.Name)) { throw new ArgumentException("Cannot create ServiceAppProcess with null or empty ServiceApp name"); } ServiceApp = app; _log = log; _processFactory = processFactory; _Messages = new List <Tuple <string, ServiceAppState> >(); CreateProcess(); }
/// <summary> /// Instantiates a new instance of the <see cref="ServiceAppProcessWrapperFactory"/> class. /// </summary> /// <param name="processWrapperFactory">The <see cref="ProcessWrapper"/> factory to rely on.</param> public ServiceAppProcessWrapperFactory(IProcessWrapperFactory processWrapperFactory) { _processWrapperFactory = processWrapperFactory; }
public void SetUp() { _processWrapperFactory = MockRepository.GenerateMock <IProcessWrapperFactory>(); }