예제 #1
0
 public void TestServerConstruction()
 {
     using (var testServer = new Server()) {
         Assert.IsNotNull(testServer.Container);
         Assert.AreEqual(8888,testServer.Port);
     }
 }
예제 #2
0
        public void TryLogin()
        {
            using(var tempDb = new TempFile())
            {
                //GlobalProxySelection.Select = new WebProxy("127.0.0.1", 8888); // proxy via Fiddler2.

                using (var server = new Server()  { Port = 8000, SqliteFile = tempDb.Path })
                {
                    server.Start();

                    // log in
                    var restClient = new JsonServiceClient(FakeServer.BaseUri);
                    var response = restClient.Post<AuthResponseEx>(
                        "/api/auth/credentials?format=json",
                        new Auth()
                        {
                            UserName = "******",
                            Password = "******",
                            RememberMe = true
                        });

                    response.SessionId.ShouldMatch(@"[a-zA-Z0-9=+/]{20,100}");
                    response.UserName.ShouldBe("tech");
                    response.UserId.ShouldMatch(@"^[a-zA-Z0-9_-]{8}$");

                    // log out
                    var logoutResponse = restClient.Delete<AuthResponse>("/api/auth/credentials?format=json&UserName=tech");
                    logoutResponse.SessionId.ShouldBe(null);

                    // can't come up with a good way to verify that we logged out.
                }
            }
        }
예제 #3
0
        public static void Main(string[] args)
        {
            int port = DefaultPort;
            bool help = false;
            var opts = new OptionSet () {
                { "port=",      (int v) => port = v },
                { "h|?|help",   v => help = v != null },
            };

            try {
                opts.Parse (args);
            }
            catch (OptionException e) {
                Console.WriteLine (e.Message);
                Console.WriteLine ("Try `Server --help' for more information.");
                return;
            }

            if (help) {
                ShowHelp(opts);
                return;
            }

            using (var server = new Server(){Port = port }) {
                server.Start();
                logger.Info("Sioux Technology Radar Server Created at {0}, listening on {1}", DateTime.Now, port);
                Console.ReadKey();
            }
        }
예제 #4
0
        public void TestReusingContainerFromServer()
        {
            var fakeThings = new FakeThingsRepository();

            var mike = fakeThings.SetupFakeThing();

            using (var server = new Server())
            {
                var container = server.Container;
                container.Register<IThingsRepository>(fakeThings);

                var things = container.Resolve<IThingsRepository>().GetByName(new string[] { "C#" });
                Assert.That(things.First(), Is.EqualTo(mike));

            }
        }
예제 #5
0
        public static void Main(string[] args)
        {
            int port = DefaultPort;
            bool help = false;
            string sqliteFile = "db\\tech_radar.sqlite";
            int backupMinutes = 15;

            var opts = new OptionSet() {
                { "port=",         "HTTP port to listen on",  (int v) => port = v },
                { "h|?|help",      "Display this help",        v => help = v != null },
                { "sqlitefile=",   "Database filename",        v => sqliteFile = v },
                { "backupperiod=", "Backup period in minutes", (int v) => backupMinutes = v },
            };

            try
            {
                opts.Parse(args);
            }
            catch (OptionException e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine("Try `Server --help' for more information.");
                return;
            }

            if (help)
            {
                ShowHelp(opts);
                return;
            }

            Console.WriteLine("Server running..");

            using (var server = new Server(true)
            {
                Port = port,
                SqliteFile = sqliteFile,
                BackupPeriodMinutes = backupMinutes,
            })
            {
                server.Start();
                logger.Info("Sioux Technology Radar Server Created at {0}, listening on {1}", DateTime.Now, port);

                try
                {
                    while (Console.ReadKey().Key != ConsoleKey.Enter) { }
                }
                catch (InvalidOperationException)
                {
                    // there's no console when running as a service; just loop indefinitely. I'm not actually sure
                    // why we still need this thread at all, but I don't want to dive into that. This is fine.
                    while (true)
                    {
                        Thread.Sleep(1000);
                    }
                }
            }
        }