Exemple #1
0
        public HelloService()
        {
            Get["/helloworld"] = _ => {
                Console.WriteLine("General greeting requested");
                return("Hello, World!");
            };

            Get["/hellome"] = _ => {
                var name = Request.Query["Name"];
                Console.WriteLine("Personalized greeting requested for {0}", name);
                return(HelloLogic.Greet_person(name));
            };

            Post["/hellome"] = _ => {
                var name = Request.Query["Name"];
                Console.WriteLine("Advanced personalized greeting requested for {0}", name);
                return(HelloLogic.Greet_visitor(name));
            };

            Get["/provokeexception"] = _ => {
                throw new ApplicationException("Bye, bye from the hello service...");
            };

            Get["/provokeexit"] = _ => {
                Console.WriteLine("Exiting service upon request, but with a non-zero exit code...");
                Environment.Exit(-99);
                return(""); // will never be reached
            };

            Get["/version"] = _ =>
            {
                Console.WriteLine("Version inquired");

                var assembly = System.Reflection.Assembly.GetExecutingAssembly();
                var fvi      = FileVersionInfo.GetVersionInfo(assembly.Location);
                return($"Version: {fvi.FileVersion}");
            };
        }
Exemple #2
0
        public void Greet_visitor()
        {
            File.Delete("visitors.txt");

            var result = HelloLogic.Greet_visitor("Peter");

            Assert.AreEqual("Hello, Peter!", result);

            result = HelloLogic.Greet_visitor("Peter");
            Assert.AreEqual("Welcome back, Peter!", result);

            result = HelloLogic.Greet_visitor("Peter");
            Assert.AreEqual("Hello, my good friend Peter!", result);

            result = HelloLogic.Greet_visitor("Mary");
            Assert.AreEqual("Hello, Mary!", result);

            result = HelloLogic.Greet_visitor("Peter");
            Assert.AreEqual("Hello, my good friend Peter!", result);

            result = HelloLogic.Greet_visitor("Mary");
            Assert.AreEqual("Welcome back, Mary!", result);
        }
Exemple #3
0
        public void Greet_person()
        {
            var result = HelloLogic.Greet_person("Bruce");

            Assert.AreEqual("Hello, Bruce!", result);
        }