public void When_A_New_Socket_Can_Not_Connect_Should_Notify_An_Abort_Via_Dispatcher() { // use always IP addresses or a valid and resolvable DNS entry, otherwise the problem will be a DNS error instead a TCP one. //Keep in mind that if the hostname could not be resolved, the first error will be a DNS, not a TCP. string unavailableService = "127.0.0.1:59999"; string unavailableServiceUrl = "http://" + unavailableService; var cancel = new CancellationToken(); var events = new List <Message>(); var dispatcherMoq = WatcherTest.PrepareMock(events); var winsock = new WinsockWatcher(dispatcherMoq.Object); //act winsock.StartWatching(cancel); Thread.Sleep(2000); //now we force a tcp connection to nowhere CallService(unavailableServiceUrl); //give some room to ETW to raise the Tcp Event Thread.Sleep(4000); WatcherTest.AssertSendCalled(dispatcherMoq, Times.AtLeastOnce()); WatcherTest.AssertExpectedEventSent(events, WinsockWatcher.ABORT, string.Empty); }
public void When_App_Starts_Catching_Exception_Should_Notify_Via_Dispatcher() { // use always IP addresses or a valid and resolvable DNS entry, otherwise the problem will be a DNS error instead a TCP one. //Keep in mind that if the hostname could not be resolved, the first error will be a DNS, not a TCP. string unavailableService = "127.0.0.1:59999"; string unavailableServiceUrl = "http://" + unavailableService; var cancel = new CancellationToken(); var events = new List <Message>(); var dispatcherMoq = WatcherTest.PrepareMock(events); var clr = new ClrWatcher(dispatcherMoq.Object); //act clr.StartWatching(cancel); //give it some room to start receiveing ETW events Thread.Sleep(1000); //now we force an exception to be thrown ThrowAndCatch(); //give some room to ETW to raise the Tcp Event Thread.Sleep(1000); WatcherTest.AssertSendCalled(dispatcherMoq, Times.AtLeastOnce()); WatcherTest.AssertExpectedEventSent(events, ClrWatcher.EXCEPTION_CATCH_START, nameof(ThrowAndCatch)); }
public void When_A_Dns_Lookup_Times_Out_Should_Notify_Via_Dispatcher() { var cancel = new CancellationToken(); var events = new List <Message>(); var dispatcherMoq = WatcherTest.PrepareMock(events); // DnsWatcher.DNS_TIMED_OUT var dns = new DnsWatcher(dispatcherMoq.Object); //act dns.StartWatching(cancel); //now we force a DNS lookup to a non-existing DNS entry var falseDnsEntry = DateTime.Now.Ticks.ToString() + ".unit.test"; CallService("http://" + falseDnsEntry); //give some room to ETW to raise the DNS error Event Thread.Sleep(2000); WatcherTest.AssertSendCalled(dispatcherMoq, Times.AtLeastOnce()); WatcherTest.AssertExpectedEventSent(events, DnsWatcher.DNS_NAME_ERROR, falseDnsEntry); }
public void When_A_New_Socket_Connects_Should_Notify_An_Connect_Via_Dispatcher() { var cancel = new CancellationToken(); var events = new List <Message>(); var dispatcherMoq = WatcherTest.PrepareMock(events); var winsock = new WinsockWatcher(dispatcherMoq.Object); //act winsock.StartWatching(cancel); //give some room to ETW to raise the Tcp Event Thread.Sleep(4000); CreateSocketListener(cancel); Connect(); WatcherTest.AssertSendCalled(dispatcherMoq, Times.AtLeastOnce()); WatcherTest.AssertExpectedEventSent(events, WinsockWatcher.CONNECT, string.Empty); }
public void When_A_New_Proccess_Is_Created_By_SO_Should_Notify_Via_Dispatcher() { // use always IP addresses or a resolvable DNS entry. //Keep in mind that if the hostname could not be resolved, the first error will be a DNS, not a TCP. var cancel = new CancellationToken(); var events = new List <Message>(); var dispatcherMoq = WatcherTest.PrepareMock(events); //dispatcherMoq.Setup(x => x.Send(It.IsAny<int>(), It.IsAny<string>(), It.IsAny<string>())) // .Callback<int, string, string>((id, body, routingKey) => // { // remember that the OS is running while we run test, so we may capture lots of events // not related with this test. That's why we need to hold a list of all captured events // events.Add(new Message { ProcessId = id, Body = body, RoutingKey = routingKey }); // }); var processWatcher = new ProcessWatcher(dispatcherMoq.Object); //act processWatcher.StartWatching(cancel); Thread.Sleep(2000); var p = new System.Diagnostics.Process(); p.StartInfo = new System.Diagnostics.ProcessStartInfo("cmd.exe"); p.StartInfo.WorkingDirectory = @"C:\windows\temp"; p.StartInfo.CreateNoWindow = true; p.StartInfo.UseShellExecute = false; p.Start(); p.Kill(); //give some room to ETW to raise the Event Thread.Sleep(3000); WatcherTest.AssertSendCalled(dispatcherMoq, Times.AtLeastOnce()); WatcherTest.AssertExpectedEventSent(events, ProcessWatcher.PROCESS_CREATION, "cmd.exe"); }