public void Execute_StopCommand_SericeIsStopped() { //Ensure the service is stopped var service = new ServiceController(SERVICE_NAME); var timeout = TimeSpan.FromMilliseconds(5000); if (service.Status != ServiceControllerStatus.Running) { service.Start(); } service.WaitForStatus(ServiceControllerStatus.Running, timeout); //Mock the commandXml var info = Mock.Of <IWindowsServiceStopCommand>( start => start.ServiceName == SERVICE_NAME && start.TimeOut == 5000 ); //Apply the test var cmd = WindowsServiceCommand.Stop(info); cmd.Execute(); //Assert service.Refresh(); Assert.That(service.Status, Is.EqualTo(ServiceControllerStatus.Stopped)); }
static void Main(string[] args) { var configurations = AppSettings.RabbitMqConfigurations; var bus = BusCreator.Create(configurations); var sendToUri = new Uri($"{configurations.Uri}{configurations.WindowsServiceQueue}"); var text = string.Empty; while (text != "quit") { Console.Write("Enter a message: "); text = Console.ReadLine(); var message = new WindowsServiceCommand { Id = Guid.NewGuid(), Message = text, DateTime = DateTime.Now }; Task.Run(() => CommandExtension.SendCommand(bus, sendToUri, message)); } }