Ejemplo n.º 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.
                }
            }
        }
        public TempSQLiteFactory()
        {
            SqlFile = new TempFile();
            SQLiteConnection.CreateFile(SqlFile.Path);

            ConnectionString = SqlFile.Path;
            OrmLiteConnectionFactory = new OrmLiteConnectionFactory (ConnectionString, true, SqliteDialect.Provider);
            var db=  OrmLiteConnectionFactory.OpenDbConnection ();
            db.CreateTableIfNotExists<Thing> ();
            db.CreateTableIfNotExists<User>();
            db.TableExists("Thing").ShouldBe(true);
            db.TableExists("User").ShouldBe(true);
        }