예제 #1
0
        public async Task TurningRichTextIntoHtmlShouldYieldCorrectResult()
        {
            //Arrange
            _handler.Response           = GetResponseFromFile(@"EntriesCollectionWithRichTextField.json");
            _client.ContentTypeResolver = new RichTextResolver();

            var htmlrenderer = new HtmlRenderer();

            htmlrenderer.AddRenderer(new RichTextContentRenderer()
            {
                Order = 10
            });
            htmlrenderer.AddRenderer(new RichTextContentRendererLinks()
            {
                Order = 10
            });
            //Act
            var res = await _client.GetEntries <RichTextModel>();

            var html = await htmlrenderer.ToHtml(res.Skip(1).First().RichText);

            //Assert
            Assert.Contains("<h1>Heading 1</h1>", html);
            Assert.Contains("<h2>Heading 2</h2>", html);
            Assert.Contains("<a href=\"Entry Hyperlink\">Embedded 1</a>", html);
            Assert.Contains("<div><h2>Embedded 2</h2></div>", html);
            Assert.Contains("<ul><li><p>Unordered List</p></li>", html);
            Assert.Contains("<ol><li><p>With Nested Ordered</p></li>", html);
            Assert.Contains("<blockquote><p>A quote</p></blockquote>", html);
            Assert.Contains("<a href=\"//images.ctfassets.net/jd7yc4wnatx3/4j1JCmvF6MqQymaMqi6OSu/d0013ff28dd2db0371315ea7e63a6e0b/cat.jpg\">Asset Hyp<em>erlink</em></a>", html);
            Assert.Contains("<hr>", html);
            Assert.Contains("<img src=\"//images.ctfassets.net/jd7yc4wnatx3/4j1JCmvF6MqQymaMqi6OSu/d0013ff28dd2db0371315ea7e63a6e0b/cat.jpg\" alt=\"cat\" />", html);
            Assert.Contains("<p><strong>Bold Text</strong></p><p><em>Italic Text</em></p><p><u>Underline Text</u></p>", html);
        }
예제 #2
0
 public CtfDeliveryService(IConfiguration configuration, CacheService cacheService)
 {
     _cacheService = cacheService;
     CtfClient     = new ContentfulClient(new HttpClient(), new ContentfulOptions {
         DeliveryApiKey = configuration["DeliveryApiKey"], SpaceId = configuration["DeliverySpaceId"]
     })
     {
         ResolveEntriesSelectively = true
     };
     _htmlRenderer = new HtmlRenderer();
     _htmlRenderer.AddRenderer(new LinkContentRenderer {
         Order = 10
     });
 }
예제 #3
0
        public void ConfigureServices(IServiceCollection services)
        {
            ConfigMan configMan = new ConfigMan(_configuration);

            services.Configure <ServerConfig>(_configuration);
            services.AddDbContext <DataContext>(
                options =>
            {
                options.UseNpgsql(_configuration.GetConnectionString(ConnectionStringName.DataContext));
            }
                );

            // Set up data protection for session cookie/ anti-forgery key
            var redis = ConnectionMultiplexer.Connect(_configuration.GetConnectionString(ConnectionStringName.Redis));

            services.AddDataProtection()
            .PersistKeysToStackExchangeRedis(redis, RedisDataProtectionKey);

            services.AddDistributedMemoryCache();
            services.AddSession(options =>
            {
                options.IdleTimeout        = TimeSpan.FromMinutes(20);
                options.Cookie.HttpOnly    = true;
                options.Cookie.IsEssential = true;
            });

            if (_currentEnvironment.IsDevelopment())
            {
                services.AddControllersWithViews().AddRazorRuntimeCompilation().AddSessionStateTempDataProvider();
            }
            else
            {
                services.AddControllersWithViews().AddSessionStateTempDataProvider();
            }

            services.AddSingleton <IEmailSender, IdentityEmailSender>();

            services.AddContentful(_configuration);
            services.AddTransient((c) =>
            {
                var renderer = new HtmlRenderer();
                renderer.AddRenderer(new SimpleHyperlinkRenderer()
                {
                    Order = 10
                });
                return(renderer);
            });

            services.AddRazorPages()
            .AddRazorPagesOptions(options =>                                            //locks down following folder and page for only users that are logged in (regardless of Role)
            {
                options.Conventions.AuthorizeAreaFolder("Identity", "/Account/Manage"); //folder for managing own identity
                options.Conventions.AuthorizeAreaPage("Identity", "/Account/Logout");   //page that makes no sense unless logged in
            });

            services.AddAuthorization(options => //setup policy we can use on MVC controllers, actions and razor pages
            {
                options.AddPolicy(Settings.Authorization.EditRights, policy => policy.RequireRole(Settings.Authorization.EditRightsRoles));
            });

            services.AddTransient <UsersFacade>();
            services.AddScoped <IContentfulService, ContentfulService>();
            services.AddHttpClient <PosttagService>();
        }