Пример #1
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.
                }
            }
        }
Пример #2
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();
            }
        }
Пример #3
0
        public void TestReusingContainerFromServer()
        {
            using (var fakeThings = new FakeThingsRepository()) {

                var mike = fakeThings.SetupMike();

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

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

                    server.Start();
                }
            }
        }
Пример #4
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);
                    }
                }
            }
        }