public void Can_use_includeUrl()
        {
            string urlContents;
            var    context = appHost.GetPlugin <TemplatePagesFeature>();

            urlContents = new PageResult(context.OneTimePage(
                                             "{{ baseUrl | addPath('includeUrl-echo') | addQueryString({ id:1, name:'foo'}) | includeUrl | htmlencode }}")).Result;
            Assert.That(urlContents, Is.EqualTo("GET /includeUrl-echo?id=1&amp;name=foo"));

            urlContents = new PageResult(context.OneTimePage(
                                             "{{ baseUrl | addPath('includeUrl-model') | addQueryString({ id:1, name:'foo'}) | includeUrl({ accept: 'application/json' }) }}")).Result;
            Assert.That(urlContents, Is.EqualTo("{\"Id\":1,\"Name\":\"foo\"}"));

            urlContents = new PageResult(context.OneTimePage(
                                             "{{ baseUrl | addPath('includeUrl-model') | addQueryString({ id:1, name:'foo'}) | includeUrl({ dataType: 'json' }) }}")).Result;
            Assert.That(urlContents, Is.EqualTo("{\"Id\":1,\"Name\":\"foo\"}"));

            urlContents = new PageResult(context.OneTimePage(
                                             "{{ baseUrl | addPath('includeUrl-model') | includeUrl({ method:'POST', data: { id: 1, name: 'foo' }, accept: 'application/jsv' }) }}")).Result;
            Assert.That(urlContents, Is.EqualTo("{Id:1,Name:foo}"));

            urlContents = new PageResult(context.OneTimePage(
                                             "{{ baseUrl | addPath('includeUrl-model') | includeUrl({ method:'POST', data: { id: 1, name: 'foo' }, accept: 'application/json', contentType: 'application/json' }) }}")).Result;
            Assert.That(urlContents, Is.EqualTo("{\"Id\":1,\"Name\":\"foo\"}"));

            urlContents = new PageResult(context.OneTimePage(
                                             "{{ baseUrl | addPath('includeUrl-model') | includeUrl({ method:'POST', data: { id: 1, name: 'foo' }, dataType: 'json' }) }}")).Result;
            Assert.That(urlContents, Is.EqualTo("{\"Id\":1,\"Name\":\"foo\"}"));

            urlContents = new PageResult(context.OneTimePage(
                                             "{{ baseUrl | addPath('includeUrl-model') | includeUrl({ method:'POST', data: { id: 1, name: 'foo' }, dataType: 'jsv' }) }}")).Result;
            Assert.That(urlContents, Is.EqualTo("{Id:1,Name:foo}"));

            urlContents = new PageResult(context.OneTimePage(
                                             "{{ baseUrl | addPath('includeUrl-models') | includeUrl({ method:'POST', data: [{ id: 1, name: 'foo' }, { id: 2, name: 'bar' }], contentType:'application/json', accept: 'application/jsv' }) }}")).Result;
            Assert.That(urlContents, Is.EqualTo("[{Id:1,Name:foo},{Id:2,Name:bar}]"));

            urlContents = new PageResult(context.OneTimePage(
                                             "{{ baseUrl | addPath('includeUrl-models') | includeUrl({ method:'POST', data: [{ id: 1, name: 'foo' }, { id: 2, name: 'bar' }], contentType:'application/jsv', accept: 'text/csv' }) }}")).Result.NormalizeNewLines();
            Assert.That(urlContents, Is.EqualTo("Id,Name\n1,foo\n2,bar"));

            urlContents = new PageResult(context.OneTimePage(
                                             "{{ baseUrl | addPath('includeUrl-models') | includeUrl({ method:'POST', data: [{ id: 1, name: 'foo' }, { id: 2, name: 'bar' }], dataType:'csv' }) }}")).Result.NormalizeNewLines();
            Assert.That(urlContents, Is.EqualTo("Id,Name\n1,foo\n2,bar"));
        }
        public ServerEventsErrorHandlingTests()
        {
            appHost = new ServerEventsAppHost()
                      .Init()
                      .Start(Config.AbsoluteBaseUri);;

            appHost.GetPlugin <ServerEventsFeature>().OnInit = req =>
                                                               throw new Exception("Always throws");
        }
Ejemplo n.º 3
0
        public void TestFixtureSetUp()
        {
            var json = "~/AppData/ALFKI.json".MapProjectPath().ReadAllText();

            response = JsonSerializer.DeserializeFromString <CustomerDetailsResponse>(json);

            appHost = new BasicAppHost
            {
                WebHostPhysicalPath = "~".MapProjectPath(),
                Plugins             = { new MarkdownFormat() },
            }.Init();
            markdownFormat = appHost.GetPlugin <MarkdownFormat>();
        }
Ejemplo n.º 4
0
        public void TestFixtureSetUp()
        {
            var json = "~/AppData/ALFKI.json".MapProjectPath().ReadAllText();
            response = JsonSerializer.DeserializeFromString<CustomerDetailsResponse>(json);

            appHost = new BasicAppHost
            {
                ConfigFilter = config => {
                    //Files aren't copied, set RootDirectory to ProjectPath instead.
                    config.WebHostPhysicalPath = "~".MapProjectPath(); 
                }
            }.Init();
            markdownFormat = appHost.GetPlugin<MarkdownFormat>();
        }
Ejemplo n.º 5
0
        public void TestFixtureSetUp()
        {
            var json = "~/AppData/ALFKI.json".MapProjectPath().ReadAllText();

            response = JsonSerializer.DeserializeFromString <CustomerDetailsResponse>(json);

            appHost = new BasicAppHost
            {
                ConfigFilter = config => {
                    //Files aren't copied, set RootDirectory to ProjectPath instead.
                    config.WebHostPhysicalPath = "~".MapProjectPath();
                }
            }.Init();
            markdownFormat = appHost.GetPlugin <MarkdownFormat>();
        }
Ejemplo n.º 6
0
        public void Does_lockout_user_after_reaching_max_invalid_logins_limit()
        {
            RegisterUser(email: "*****@*****.**");

            var feature = appHost.GetPlugin <AuthFeature>();

            feature.MaxLoginAttempts = 3;

            feature.MaxLoginAttempts.Value.Times(i =>
            {
                appHost.ExecuteService(new Authenticate {
                    UserName = "******",
                    Password = "******"
                });

                using (var db = appHost.Resolve <IDbConnectionFactory>().Open())
                {
                    var user = db.Single <UserAuth>(q => q.Email == "*****@*****.**");
                    Assert.That(user.LastLoginAttempt, Is.Not.Null);
                    Assert.That(user.InvalidLoginAttempts, Is.EqualTo(i + 1)); //0 index
                }
            });

            using (var db = appHost.Resolve <IDbConnectionFactory>().Open())
            {
                var user = db.Single <UserAuth>(q => q.Email == "*****@*****.**");
                Assert.That(user.LockedDate, Is.Not.Null);
            }

            var response = appHost.ExecuteService(new Authenticate
            {
                UserName = "******",
                Password = "******"
            });

            var httpError = (HttpError)response;

            Assert.That(httpError.Message, Is.EqualTo("This account has been locked"));
            Assert.That(httpError.StatusCode, Is.EqualTo(HttpStatusCode.Unauthorized));
        }
Ejemplo n.º 7
0
 TemplatePage CreatePage(IVirtualFile file) =>
 new TemplatePage(appHost.GetPlugin <TemplatePagesFeature>(), file);
Ejemplo n.º 8
0
 SharpPage CreatePage(IVirtualFile file) =>
 new SharpPage(appHost.GetPlugin <SharpPagesFeature>(), file);