Beispiel #1
0
        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);
        }
Beispiel #2
0
        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);
        }