Provides utilities and helpers for application testing.
示例#1
0
        public void ApplicationProcessStopForce()
        {
            string           path   = ApplicationUtils.CreateValidExampleApplication();
            ManualResetEvent handle = new ManualResetEvent(false);

            try
            {
                using (ApplicationProcess process = new ApplicationProcess(Logger, path, Path.GetFullPath("Collar.exe")))
                {
                    process.Exited += (object sender, EventArgs e) =>
                    {
                        Assert.Fail();
                        handle.Set();
                    };

                    process.KillTimeout += (object sender, EventArgs e) =>
                    {
                        Assert.Fail();
                        handle.Set();
                    };

                    Assert.IsTrue(process.Start());
                    process.Stop(true);
                    WaitHandle.WaitAll(new WaitHandle[] { handle }, 11000);
                }
            }
            finally
            {
                handle.Close();
            }
        }
示例#2
0
        public void ApplicationCoordinatorRefreshRemove()
        {
            ApplicationElement element1 = new ApplicationElement()
            {
                ApplicationPath = ApplicationUtils.CreateValidExampleApplication(), Framework = Framework
            };
            ApplicationElement element2 = new ApplicationElement()
            {
                ApplicationPath = ApplicationUtils.CreateValidExampleApplication(), Framework = Framework
            };
            ApplicationElement element3 = new ApplicationElement()
            {
                ApplicationPath = ApplicationUtils.CreateValidExampleApplication(), Framework = Framework
            };

            using (ApplicationCoordinator coordinator = new ApplicationCoordinator(Logger, Path.GetFullPath("Collar.exe")))
            {
                coordinator.StartAndRefresh(new ApplicationElement[] { element1, element2, element3 });
                Assert.IsTrue(coordinator.IsRunning);

                var paths = coordinator.GetCoordinatedApplicationPaths();
                Assert.AreEqual(3, coordinator.Count);
                Assert.IsTrue(paths.Contains(element1.ApplicationPath));
                Assert.IsTrue(paths.Contains(element2.ApplicationPath));
                Assert.IsTrue(paths.Contains(element3.ApplicationPath));

                coordinator.StartAndRefresh(new ApplicationElement[] { element1, element3 });
                Assert.IsTrue(coordinator.IsRunning);

                paths = coordinator.GetCoordinatedApplicationPaths();
                Assert.AreEqual(2, coordinator.Count);
                Assert.IsTrue(paths.Contains(element1.ApplicationPath));
                Assert.IsTrue(paths.Contains(element3.ApplicationPath));
            }
        }
示例#3
0
        public void BootstrapsBasicApplicationFileChange()
        {
            string           path     = ApplicationUtils.CreateValidExampleApplication();
            string           filePath = Path.Combine(path, Path.GetFileNameWithoutExtension(Path.GetRandomFileName()) + ".dll");
            ManualResetEvent handle   = new ManualResetEvent(false);

            try
            {
                using (Bootstraps bootstraps = new Bootstraps(path, null, 500))
                {
                    bootstraps.ApplicationFilesChanged += (sender, e) =>
                    {
                        Assert.AreEqual(filePath, e.FullPath);
                        handle.Set();
                    };

                    Assert.AreEqual(BootstrapsPullupResultType.Success, bootstraps.PullUp().ResultType);

                    using (File.Create(filePath))
                    {
                    }

                    WaitHandle.WaitAll(new WaitHandle[] { handle });
                }
            }
            finally
            {
                handle.Close();
            }
        }
示例#4
0
        public void BootstrapsPullUpAndExecuteJob()
        {
            string path = ApplicationUtils.CreateValidExampleApplication();

            using (Bootstraps bootstraps = new Bootstraps(path, null, 500))
            {
                Assert.AreEqual(BootstrapsPullupResultType.Success, bootstraps.PullUp(true).ResultType);

                CreateFileJob job = new CreateFileJob()
                {
                    Path = Path.Combine(path, Path.GetRandomFileName())
                };

                Assert.IsFalse(File.Exists(job.Path));

                // The default configuration specifies a SQLite repository pointing
                // to BlueCollar.sqlite in the application's root directory.
                using (IRepository repository = new SQLiteRepository(string.Format(CultureInfo.InvariantCulture, "data source={0};journal mode=Off;synchronous=Off;version=3", Path.Combine(path, "BlueCollar.sqlite"))))
                {
                    job.Enqueue("Default", null, repository);
                }

                // Default worker heartbeat is 5 seconds.
                Thread.Sleep(6000);
                Assert.IsTrue(File.Exists(job.Path));
            }
        }
示例#5
0
        public void BootstrapsWebApplicationConfigFileChange()
        {
            string           path   = ApplicationUtils.CreateValidExampleWebApplication();
            ManualResetEvent handle = new ManualResetEvent(false);

            try
            {
                using (Bootstraps bootstraps = new Bootstraps(path, null, 500))
                {
                    bootstraps.ApplicationFilesChanged += (sender, e) =>
                    {
                        Assert.AreEqual(Path.Combine(path, "Web.config"), e.FullPath);
                        handle.Set();
                    };

                    Assert.AreEqual(BootstrapsPullupResultType.Success, bootstraps.PullUp().ResultType);

                    using (File.Create(Path.Combine(path, "Web.config")))
                    {
                    }

                    WaitHandle.WaitAll(new WaitHandle[] { handle });
                }
            }
            finally
            {
                handle.Close();
            }
        }
示例#6
0
        public void BootstrapsPullUpAndExcecuteJobWithHttpApplicationEntryPoint()
        {
            string path = ApplicationUtils.CreateValidExampleApplication();

            using (Bootstraps bootstraps = new Bootstraps(path, null, 500))
            {
                Assert.AreEqual(BootstrapsPullupResultType.Success, bootstraps.PullUp(true).ResultType);

                CreateFileJob job = new CreateFileJob()
                {
                    Path = Path.Combine(path, Path.GetRandomFileName())
                };

                Assert.IsFalse(File.Exists(job.Path));

                using (IRepository repository = new SQLiteRepository(string.Format(CultureInfo.InvariantCulture, "data source={0};journal mode=Off;synchronous=Off;version=3", Path.Combine(path, "BlueCollar.sqlite"))))
                {
                    job.Enqueue("Default", null, repository);
                }

                Thread.Sleep(6000);
                Assert.IsTrue(File.Exists("HttpApplicationStart"));

                bootstraps.Pushdown(true);
                Assert.IsTrue(File.Exists("HttpApplicationEnd"));
            }
        }
示例#7
0
        public void ApplicationProcessStart()
        {
            string path = ApplicationUtils.CreateValidExampleApplication();

            using (ApplicationProcess process = new ApplicationProcess(Logger, path, Path.GetFullPath("Collar.exe")))
            {
                Assert.IsTrue(process.Start());
            }
        }
示例#8
0
        public void BootstrapsPullUpBasicWebApplication()
        {
            string path = ApplicationUtils.CreateValidExampleWebApplication();

            using (Bootstraps bootstraps = new Bootstraps(path, null, 500))
            {
                Assert.AreEqual(BootstrapsPullupResultType.Success, bootstraps.PullUp().ResultType);
                Assert.IsTrue(bootstraps.IsLoaded);
            }
        }
示例#9
0
        public void ExamplesTailLongLines()
        {
            string path = Path.GetFileNameWithoutExtension(Path.GetRandomFileName()) + ".txt";

            ApplicationUtils.CopyEmbeddedResourceToPath("TailTest-LongLines.txt", path);

            IList <string> tail = Tail.Read(path, 1, Encoding.UTF8).ToList();

            Assert.AreEqual(1, tail.Count);
            Assert.AreEqual("Cras ultrices, risus ut dictum suscipit, felis diam porta risus, non commodo eros neque vitae leo. Suspendisse condimentum suscipit urna, eget iaculis risus tempus vitae. Praesent luctus, magna ac feugiat euismod, enim dolor mattis sapien, eu mattis libero arcu vitae sem. Fusce eu erat ac metus gravida sodales a id tellus. Donec lacinia facilisis commodo. Vestibulum rhoncus aliquam arcu a varius. Pellentesque elementum egestas dictum. Ut orci nibh, imperdiet eget accumsan quis, pellentesque vel orci. Aliquam aliquam odio eu nulla bibendum mollis. Praesent enim turpis, volutpat at molestie vel, tincidunt id neque. In hac habitasse platea dictumst. Sed sit amet sapien eros. Sed consequat sem eu nunc vulputate sollicitudin. Sed ut suscipit augue. Phasellus rhoncus mauris et odio vulputate a placerat velit vestibulum. Vivamus eleifend augue sit amet libero bibendum lacinia. In faucibus, ante vel commodo bibendum, erat mi venenatis diam, sit amet laoreet libero quam ac nibh. Quisque porta volutpat lectus a luctus. Curabitur euismod pellentesque diam a placerat. Fusce dui velit, mollis in porttitor et, ullamcorper eu lacus. Aliquam vel diam in lorem dictum pellentesque in imperdiet nisi. Proin pretium ipsum in est eleifend quis ultrices orci ultrices. Morbi facilisis, libero non vulputate adipiscing, purus purus fermentum orci, non porttitor neque arcu eu arcu. Quisque eget tortor quam. Aenean risus nunc, ornare quis luctus ut, condimentum nec leo. Suspendisse quis magna non dui semper facilisis a eu nisi.", tail[0]);
        }
示例#10
0
        public void ExamplesTailAbc()
        {
            string path = Path.GetFileNameWithoutExtension(Path.GetRandomFileName()) + ".txt";

            ApplicationUtils.CopyEmbeddedResourceToPath("TailTest-Abc.txt", path);

            IList <string> tail = Tail.Read(path, 0, Encoding.UTF8).ToList();

            Assert.AreEqual(2, tail.Count);
            Assert.AreEqual("Fghi", tail[0]);
            Assert.AreEqual("Abcde", tail[1]);
        }
示例#11
0
        public void ExamplesTailSuperset()
        {
            string path = Path.GetFileNameWithoutExtension(Path.GetRandomFileName()) + ".txt";

            ApplicationUtils.CopyEmbeddedResourceToPath("TailTest-10.txt", path);

            IList <string> tail = Tail.Read(path, 100, Encoding.UTF8).ToList();

            Assert.AreEqual(10, tail.Count);
            Assert.AreEqual("Donec orci odio, vehicula ac convallis non, consectetur sed augue.", tail[0]);
            Assert.AreEqual("Lorem ipsum dolor sit amet, consectetur adipiscing elit.", tail[9]);
        }
示例#12
0
        public void ExamplesTailSubset()
        {
            string path = Path.GetFileNameWithoutExtension(Path.GetRandomFileName()) + ".txt";

            ApplicationUtils.CopyEmbeddedResourceToPath("TailTest-10.txt", path);

            IList <string> tail = Tail.Read(path, 3, Encoding.UTF8).ToList();

            Assert.AreEqual(3, tail.Count);
            Assert.AreEqual("Donec orci odio, vehicula ac convallis non, consectetur sed augue.", tail[0]);
            Assert.AreEqual("Mauris vitae nibh odio.", tail[1]);
            Assert.AreEqual("Mauris id diam ac nulla suscipit faucibus non non orci.", tail[2]);
        }
示例#13
0
        public void BootstrapsPullUpFail()
        {
            string path = ApplicationUtils.CreateValidExampleApplication();

            File.Delete(Path.Combine(path, "BlueCollar.dll"));

            using (Bootstraps bootstraps = new Bootstraps(path, null, 500))
            {
                BootstrapsPullupResult result = bootstraps.PullUp();
                Assert.AreEqual(BootstrapsPullupResultType.Exception, result.ResultType);
                Assert.IsNotNull(result.Exception);
            }
        }
示例#14
0
        public void BootstrapsBasicApplicationAssembliesNotLocked()
        {
            string path = ApplicationUtils.CreateValidExampleApplication();

            AssembliesNotLocked(path, Path.Combine(path, "BlueCollar.dll"));
        }