コード例 #1
0
        public void NotWaitingItShouldBePossibleToWaitForATaskToCompleteWithTimeoutError()
        {
            _notWaitingCompleted = false;
            _notWaitingStarted   = false;
            _taskRun             = false;
            _taskStarted         = false;
            _completedTaks       = false;
            _exception           = null;
            var coroutine = new Mock <ICoroutineThread>();

            coroutine.Setup(a => a.Execute())
            .Returns(NotWaitingHavingTimeout());

            var target = new CoroutinesManager();

            target.TestInitialize();
            var rtt = new RunnerForTest(target);

            target.StartCoroutine(coroutine.Object);

            rtt.RunCycle();             //Coroutine initialized
            Assert.IsTrue(_notWaitingStarted);
            rtt.RunCycle(2);            //Coroutine started
            Assert.IsTrue(_notWaitingCompleted);


            Assert.IsTrue(_taskStarted);
            Assert.IsNull(_exception);
            Assert.IsFalse(_completedTaks);

            rtt.RunCycleFor(150);
            Assert.IsTrue(_taskStarted);
            Assert.IsNotNull(_exception);
            Assert.IsFalse(_completedTaks);
        }
コード例 #2
0
        public void ItShouldBePossibleToWaitForATaskToCompleteWithinTimeout()
        {
            _taskStarted = false;
            _taskRun     = false;
            _completed   = false;
            var coroutine = new Mock <ICoroutineThread>();

            coroutine.Setup(a => a.Execute())
            .Returns(CoroutineWaitingHavingTimeoutNotExploding());

            var target = new CoroutinesManager();

            target.TestInitialize();
            var rft = new RunnerForTest(target);

            target.StartCoroutine(coroutine.Object);
            target.TestRun();
            rft.RunCycleFor(200);
            target.TestRun();

            Assert.IsTrue(_taskStarted);
            Assert.IsTrue(_taskRun);
            Assert.IsTrue(_completed);
            coroutine.Verify(a => a.OnError(It.IsAny <Exception>()), Times.Never);
        }
コード例 #3
0
		public void StaticRenderer_WhenExecutingArequest_ShouldApplyFilters()
		{
			var assemblyLocation = Assembly.GetExecutingAssembly().Location;
			var runner = new RunnerForTest();
			NodeMainInitializer.InitializeFakeMain(assemblyLocation, runner);
			var rootDir = InferWebRootDir(assemblyLocation);
			var pathProvider = new StaticContentPathProvider(rootDir);
			var filterHandler = new FilterHandler();

			var globalFilter = new Mock<IFilter>();
			globalFilter.Setup(a => a.OnPreExecute(It.IsAny<IHttpContext>())).Returns(true);
			filterHandler.AddFilter(globalFilter.Object);
			ServiceLocator.Locator.Register<IFilterHandler>(filterHandler);

			var http = new HttpModule();
			http.SetParameter(HttpParameters.HttpPort, 8881);
			http.SetParameter(HttpParameters.HttpVirtualDir, "nodecs");
			http.SetParameter(HttpParameters.HttpHost, "localhost");


			var routingService = new RoutingService();
			http.RegisterRouting(routingService);

			http.Initialize();

			http.RegisterPathProvider(pathProvider);

			const string uri = "http://localhost:8881/nodecs";

			var context = CreateRequest(uri);
			var outputStream = (MockStream)context.Response.OutputStream;
			outputStream.Initialize();


            globalFilter.Setup(a => a.OnPostExecute(It.IsAny<IHttpContext>()))
                .Callback(() =>
                {
                    Console.WriteLine("AAAA");
                });

			//request.
			http.ExecuteRequest(context);
			runner.RunCycleFor(200);
			var os = (MemoryStream)context.Response.OutputStream;
			os.Seek(0, SeekOrigin.Begin);
			var bytes = os.ToArray();
			var result = Encoding.UTF8.GetString(bytes);

			Assert.IsTrue(outputStream.WrittenBytes > 0);
			Assert.IsNotNull(result);

			globalFilter.Verify(a => a.OnPreExecute(It.IsAny<IHttpContext>()), Times.Once);
			globalFilter.Verify(a => a.OnPostExecute(It.IsAny<IHttpContext>()), Times.Once);
		}
コード例 #4
0
		public void ItShouldBePossibleToExecuteArequest()
		{
			var assemblyLocation = Assembly.GetExecutingAssembly().Location;
			var runner = new RunnerForTest();
			NodeMainInitializer.InitializeFakeMain(assemblyLocation, runner);
			var rootDir = InferWebRootDir(assemblyLocation);
			var pathProvider = new StaticContentPathProvider(rootDir);
			var http = new HttpModule();
			http.SetParameter(HttpParameters.HttpPort, 8881);
			http.SetParameter(HttpParameters.HttpVirtualDir, "nodecs");
			http.SetParameter(HttpParameters.HttpHost, "localhost");


			var routingService = new RoutingService();
			http.RegisterRouting(routingService);

			http.Initialize();

			http.RegisterPathProvider(pathProvider);

			const string uri = "http://localhost:8881/nodecs";

			var context = CreateRequest(uri);
			var outputStream = (MockStream)context.Response.OutputStream;
			outputStream.Initialize();

			//request.
			http.ExecuteRequest(context);
			runner.RunCycleFor(200);
			var os = (MemoryStream)context.Response.OutputStream;
			os.Seek(0, SeekOrigin.Begin);
			var bytes = os.ToArray();
			var result = Encoding.UTF8.GetString(bytes);

			Assert.IsTrue(outputStream.WrittenBytes > 0);
			Assert.IsNotNull(result);
			Assert.IsTrue(result.Length > 0);
			Assert.IsTrue(result.IndexOf("Exception", StringComparison.Ordinal) < 0, result);
			Assert.AreEqual(1, outputStream.ClosesCall);
		}
コード例 #5
0
        public void WaitForTaskToComplete()
        {
            const int waitTime  = 100;
            var       coroutine = new Mock <ICoroutineThread>();

            coroutine.Setup(a => a.Execute())
            .Returns(CoroutineWaitingForTask(waitTime));

            var target = new CoroutinesManager();

            target.TestInitialize();
            var rft = new RunnerForTest(target);

            target.StartCoroutine(coroutine.Object);
            target.TestRun();                   //Initialize
            rft.RunCycleFor(waitTime * 2);
            target.TestRun();                   //CleanUp

            Assert.IsTrue(_taskStarted);
            Assert.IsTrue(_taskRun);
            Assert.IsTrue(_completed);
        }
コード例 #6
0
		public void ItShouldBePossibleToSimulateRequest()
		{
			var assemblyLocation = Assembly.GetExecutingAssembly().Location;
			var runner = new RunnerForTest();
			NodeMainInitializer.InitializeFakeMain(assemblyLocation, runner);
			var rootDir = InferWebRootDir(assemblyLocation);
			var pathProvider = new StaticContentPathProvider(rootDir);
			var http = new HttpModule();
			http.SetParameter(HttpParameters.HttpPort, 8881);
			http.SetParameter(HttpParameters.HttpVirtualDir, "nodecs");
			http.SetParameter(HttpParameters.HttpHost, "localhost");


			var routingService = new RoutingService();
			http.RegisterRouting(routingService);

			http.Initialize();

			http.RegisterPathProvider(pathProvider);

			const string uri = "http://*****:*****@src");
			var contexts = new List<SimpleHttpContext>();
			if (nodes != null)
			{
				foreach (HtmlNode node in nodes)
				{
					var src = node.Attributes["src"].Value;
					if (!src.StartsWith("http")) src = uri + "/" + src.Trim('/');
					contexts.Add((SimpleHttpContext)PrepareRequest(src));
					http.ExecuteRequest(contexts.Last());
				}
			}
			runner.RunCycleFor(500);
			for (int index = 0; index < contexts.Count; index++)
			{
				var ctx = contexts[index];
				VerifyContext(ctx);
			}
		}
コード例 #7
0
		protected byte[] RunRequest(string uri, HttpModule http, RunnerForTest runner, int timeoutMs = 250)
		{
			var context = PrepareRequest(uri);
			http.ExecuteRequest(context);
			var outputStream = (MockStream)context.Response.OutputStream;

			var sw = new Stopwatch();
			sw.Start();
			while (outputStream.ClosesCall != 1 && sw.ElapsedMilliseconds < timeoutMs)
			{
				runner.RunCycleFor(timeoutMs);
			}
			Console.WriteLine(outputStream.WrittenBytes + " " + uri);
			Assert.AreEqual(1, outputStream.ClosesCall);
			Assert.IsTrue(outputStream.WrittenBytes > 0);
			var os = (MemoryStream)context.Response.OutputStream;
			os.Seek(0, SeekOrigin.Begin);
			var bytes = os.ToArray();
			var strings = Encoding.UTF8.GetString(bytes);
			Assert.IsTrue(strings.Length > 0);
			Assert.IsTrue(strings.IndexOf("Exception", StringComparison.Ordinal) < 0, strings);
			return bytes;
		}