Ejemplo n.º 1
0
        public void Run_2LongRequestsSentSimultaneously_ProcessedSimultaneously()
        {
            _configurationHelperMock.Setup(x => x.GetPort()).Returns(12351);

            var longTaskOnServerTime    = 4000;
            var numberOfRequests        = 2;
            var toleratedCompletionTime = longTaskOnServerTime * 1.4;

            var pageLoaderMock = new Mock <IPageLoader>();

            pageLoaderMock.Setup(x => x.LoadContentFromLocalFile(It.IsAny <string>())).Callback(() =>
            {
                Thread.Sleep(longTaskOnServerTime);
                _requestCount++;
            });

            var socketWebServer = new SocketWebServer(pageLoaderMock.Object,
                                                      new ProxyTcpListener(_configurationHelperMock.Object));

            socketWebServer.Run();

            var processingStarted = DateTime.Now;

            // Send asynchronously requests
            for (var i = 0; i < numberOfRequests; i++)
            {
                SendRequestWithoutResponse();
            }

            // Wait for all of them to be processed by the server
            while (_requestCount != numberOfRequests)
            {
                Thread.Sleep(500);
            }

            var processingFinished = DateTime.Now;

            var approximateExecutionTime = (processingFinished - processingStarted).TotalSeconds;

            Assert.AreEqual(numberOfRequests, _requestCount);
            Assert.IsTrue(approximateExecutionTime < toleratedCompletionTime / 1000);
        }
Ejemplo n.º 2
0
        public void Run_Stop_Once()
        {
            _configurationHelperMock.Setup(x => x.GetPort()).Returns(12345);

            try
            {
                _server.Run();

                _server.Stop();
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }
Ejemplo n.º 3
0
        public void Run_100RequestsSent_100RequestsReceivedOnServer()
        {
            _configurationHelperMock.Setup(x => x.GetPort()).Returns(12350);

            var pageLoaderMock = new Mock <IPageLoader>();

            pageLoaderMock.Setup(x => x.LoadContentFromLocalFile(It.IsAny <string>()))
            .Callback(() => { _requestCount++; });

            var socketWebServer = new SocketWebServer(pageLoaderMock.Object,
                                                      new ProxyTcpListener(_configurationHelperMock.Object));

            socketWebServer.Run();

            for (var i = 0; i < 100; i++)
            {
                SendRequestWithResponse();
            }

            Assert.AreEqual(100, _requestCount);
        }