public HomeControllerTests()
        {
            // Database setup
            var services = new ServiceCollection();
            services.AddEntityFramework()
                    .AddSqlServer()
                    .AddInMemoryDatabase()
                    .AddDbContext<DataDbContext>(options =>
                        options.UseInMemoryDatabase()
                    );

            // Dependencies initializations
            _pageConfiguration = new FakePageConfiguration();

            var optionsBuilder = new DbContextOptionsBuilder<DataDbContext>();
            optionsBuilder.UseInMemoryDatabase();
            _dataDbContext = new DataDbContext(optionsBuilder.Options);

            _contentRepository = new ContentRepository(_dataDbContext);
            _humanReadableContentService = new HumanReadableContentService(_pageConfiguration, _contentRepository);

            _languageManipulationService = new LanguageManipulationService();

            // Controller initialization
            _homeController = new PersonalWebsite.Controllers.HomeController(
                _pageConfiguration,
                _humanReadableContentService,
                _languageManipulationService
            );
        }
Example #2
0
        /// <summary>
        /// Create <see cref="HomeControllerTests"/>.
        /// </summary>
        public HomeControllerTests()
        {
            // Database setup
            var services = new ServiceCollection();

            services.AddEntityFrameworkInMemoryDatabase()
            .AddDbContext <DataDbContext>(options =>
                                          options.UseInMemoryDatabase()
                                          );

            // Dependencies initializations
            _pageConfiguration = new FakePageConfiguration();

            var optionsBuilder = new DbContextOptionsBuilder <DataDbContext>();

            optionsBuilder.UseInMemoryDatabase();
            _dataDbContext = new DataDbContext(optionsBuilder.Options);

            _contentRepository           = new ContentRepository(_dataDbContext);
            _humanReadableContentService = new HumanReadableContentRetrievalService(_pageConfiguration, _contentRepository);

            _languageManipulationService = new LanguageManipulationService();

            // Controller initialization
            _homeController = new HomeController(
                _pageConfiguration,
                _humanReadableContentService,
                _languageManipulationService
                );
        }
Example #3
0
 public UrlLanguagePrefixer(
     IPageConfiguration pageConfiguration,
     ILanguageManipulationService languageManipulationService)
 {
     _pageConfiguration           = pageConfiguration ?? throw new ArgumentNullException(nameof(pageConfiguration));
     _languageManipulationService = languageManipulationService ?? throw new ArgumentNullException(nameof(languageManipulationService));
 }
Example #4
0
        public void Configure(
            IApplicationBuilder app,
            IHostEnvironment env,
            IPageConfiguration pageConfiguration,
            ILanguageManipulationService languageManipulationService,
            IEndpointsBuilder endpointsBuilder)
        {
            app.UseStatusCodePagesWithReExecute("/errors/{0}");

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseStaticFiles();

            var defaultCulture = languageManipulationService
                                 .LanguageDefinitionToCultureInfo(
                pageConfiguration.DefaultLanguage
                );

            app.UseRequestLocalization(new RequestLocalizationOptions
            {
                SupportedCultures       = languageManipulationService.SupportedCultures,
                SupportedUICultures     = languageManipulationService.SupportedCultures,
                RequestCultureProviders = new IRequestCultureProvider[] { new CustomUrlStringCultureProvider(languageManipulationService) },
                DefaultRequestCulture   = new RequestCulture(defaultCulture, defaultCulture)
            }
                                       );

            app.UseRouting();
            app.UseAuthentication();
            app.UseAuthorization();
            app.UseEndpoints(endpointsBuilder.Build);
        }
Example #5
0
 /// <summary>
 /// Create <see cref="HomeController"/>.
 /// </summary>
 /// <param name="pageConfiguration">Page configuration.</param>
 /// <param name="humanReadableContentService">Human-readable content retrieval service.</param>
 /// <param name="languageManipulationService">Language manipulation service.</param>
 public HomeController(
     IPageConfiguration pageConfiguration,
     IHumanReadableContentRetrievalService humanReadableContentService,
     ILanguageManipulationService languageManipulationService)
 {
     _pageConfiguration           = pageConfiguration ?? throw new ArgumentNullException(nameof(pageConfiguration));
     _humanReadableContentService = humanReadableContentService ?? throw new ArgumentNullException(nameof(humanReadableContentService));
     _languageManipulationService = languageManipulationService ?? throw new ArgumentNullException(nameof(languageManipulationService));
 }
        public CustomUrlStringCultureProvider(ILanguageManipulationService languageManipulationService)
        {
            if(languageManipulationService == null)
            {
                throw new ArgumentNullException(nameof(languageManipulationService));
            }

            _languageManipulationService = languageManipulationService;
        }
        public CustomUrlStringCultureProvider(ILanguageManipulationService languageManipulationService)
        {
            if (languageManipulationService == null)
            {
                throw new ArgumentNullException(nameof(languageManipulationService));
            }

            _languageManipulationService = languageManipulationService;
        }
Example #8
0
        public RoutesBuilder(ILanguageManipulationService languageManipulationService)
        {
            if (languageManipulationService == null)
            {
                throw new ArgumentNullException(nameof(languageManipulationService));
            }

            _languageManipulationService = languageManipulationService;
        }
Example #9
0
        // Configure is called after ConfigureServices is called.
        public void Configure(
            IApplicationBuilder app,
            IHostingEnvironment env,
            ILoggerFactory loggerFactory,
            IPageConfiguration pageConfiguration,
            ILanguageManipulationService languageManipulationService,
            IRoutesBuilder routesBuilder)
        {
            loggerFactory.AddConsole();

            // Configure the HTTP request pipeline.

            // Add the following to the request pipeline only in development environment.
            if (env.IsDevelopment())
            {
                app.UseBrowserLink();
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();

                loggerFactory.AddDebug(LogLevel.Debug);
            }
            else
            {
                loggerFactory.AddDebug(LogLevel.Critical);
            }

            // Add static files to the request pipeline.
            app.UseStaticFiles();

            // Add cookie-based authentication to the request pipeline.
            app.UseIdentity();


            var defaultCulture = languageManipulationService
                                 .LanguageDefinitionToCultureInfo(
                pageConfiguration.DefaultLanguage
                );

            app.UseRequestLocalization(new RequestLocalizationOptions
            {
                SupportedCultures       = languageManipulationService.SupportedCultures,
                SupportedUICultures     = languageManipulationService.SupportedCultures,
                RequestCultureProviders = new[] { new CustomUrlStringCultureProvider(languageManipulationService) },
                DefaultRequestCulture   = new RequestCulture(defaultCulture, defaultCulture)
            }
                                       );

            app.UseMvc(routesBuilder.Build);

            using (var dataInitializer = new DataInitializer(app.ApplicationServices))
            {
                dataInitializer.EnsureRequiredContentsAvailable();
                dataInitializer.EnsureInitialUserAvaialble();
            }
        }
        public UrlLanguagePrefixer(
            IPageConfiguration pageConfiguration,
            ILanguageManipulationService languageManipulationService)
        {
            if(pageConfiguration == null)
            {
                throw new ArgumentNullException(nameof(pageConfiguration));
            }

            if(languageManipulationService == null)
            {
                throw new ArgumentNullException(nameof(languageManipulationService));
            }

            _pageConfiguration = pageConfiguration;
            _languageManipulationService = languageManipulationService;
        }
Example #11
0
        /// <summary>
        /// Create <see cref="ContentsController"/>.
        /// </summary>
        /// <param name="pageConfiguration">Page configuration.</param>
        /// <param name="humanReadableContentService">Human-readable content retrieval service.</param>
        /// <param name="languageManipulationService">Language manipulation service.</param>
        public ContentsController(
            IPageConfiguration pageConfiguration,
            IHumanReadableContentRetrievalService humanReadableContentService,
            ILanguageManipulationService languageManipulationService)
        {
            if (pageConfiguration == null)
            {
                throw new ArgumentNullException(nameof(pageConfiguration));
            }

            if (humanReadableContentService == null)
            {
                throw new ArgumentNullException(nameof(humanReadableContentService));
            }

            if (languageManipulationService == null)
            {
                throw new ArgumentNullException(nameof(languageManipulationService));
            }

            _humanReadableContentService = humanReadableContentService;
            _languageManipulationService = languageManipulationService;
            _pageConfiguration           = pageConfiguration;
        }
        public HomeController(
            IPageConfiguration pageConfiguration,
            IHumanReadableContentService humanReadableContentService,
            ILanguageManipulationService languageManipulationService)
        {
            if(pageConfiguration == null)
            {
                throw new ArgumentNullException(nameof(pageConfiguration));
            }

            if(humanReadableContentService == null)
            {
                throw new ArgumentNullException(nameof(humanReadableContentService));
            }

            if(languageManipulationService == null)
            {
                throw new ArgumentNullException(nameof(languageManipulationService));
            }

            _pageConfiguration = pageConfiguration;
            _humanReadableContentService = humanReadableContentService;
            _languageManipulationService = languageManipulationService;
        }
Example #13
0
        // Configure is called after ConfigureServices is called.
        public void Configure(
            IApplicationBuilder app,
            IHostingEnvironment env,
            ILoggerFactory loggerFactory,
            IPageConfiguration pageConfiguration,
            ILanguageManipulationService languageManipulationService)
        {
            if (pageConfiguration == null)
            {
                throw new ArgumentNullException(nameof(pageConfiguration));
            }

            if (languageManipulationService == null)
            {
                throw new ArgumentNullException(nameof(languageManipulationService));
            }

            loggerFactory.MinimumLevel = LogLevel.Warning;
            loggerFactory.AddConsole();

            // Configure the HTTP request pipeline.

            // Add the following to the request pipeline only in development environment.
            if (env.IsDevelopment())
            {
                app.UseBrowserLink();
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage(x => x.EnableAll());

                loggerFactory.AddDebug(LogLevel.Debug);
            }
            else
            {
                // Add Error handling middleware which catches all application specific errors and
                // sends the request to the following path or controller action.
                app.UseExceptionHandler("/Home/Error");

                loggerFactory.AddDebug(LogLevel.Critical);
            }

            // Add the platform handler to the request pipeline.
            app.UseIISPlatformHandler();

            // Add static files to the request pipeline.
            app.UseStaticFiles();

            // Add cookie-based authentication to the request pipeline.
            app.UseIdentity();

            var defaultCulture = languageManipulationService
                                 .LanguageDefinitionToCultureInfo(
                pageConfiguration.DefaultLanguage
                );

            app.UseRequestLocalization(new RequestLocalizationOptions
            {
                SupportedCultures       = languageManipulationService.SupportedCultures,
                SupportedUICultures     = languageManipulationService.SupportedCultures,
                RequestCultureProviders = new[] { new CustomUrlStringCultureProvider(languageManipulationService) }
            },
                                       new RequestCulture(defaultCulture, defaultCulture)
                                       );

            // Add MVC to the request pipeline.
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: nameof(PersonalWebsite.Areas.Private),
                    template: "{area}/{controller}/{action}/{id?}",
                    defaults: new { },
                    constraints: new { area = "private" });
                routes.MapRoute(
                    name: "defaultWithLanguage",
                    template: "{language}/{controller=Home}/{action=Index}",
                    defaults: new { },
                    constraints: new { language = languageManipulationService.LanguageValidationRegexp() }
                    );
                routes.MapRoute(
                    name: "defaultWithoutLanguage",
                    template: "{controller=Home}/{action=Index}",
                    defaults: new { language = String.Empty }
                    );

                routes.MapRoute(
                    name: "contentsWithLanguage",
                    template: "{language}/{urlName}/{controller=Contents}/{action=Show}",
                    defaults: new { },
                    constraints: new { language = languageManipulationService.LanguageValidationRegexp() }
                    );
                routes.MapRoute(
                    name: "contentsWithoutLanguage",
                    template: "{urlName}/{controller=Contents}/{action=Show}"
                    );
            });

            using (var dataInitializer = new DataInitializer(app.ApplicationServices))
            {
                if (env.IsDevelopment())
                {
                    dataInitializer.ClearRequiredContents();
                    dataInitializer.ClearInitialUser();
                }

                dataInitializer.EnsureRequiredContentsAvailable();
                dataInitializer.EnsureInitialUserAvaialble();
            }
        }
 public EndpointsBuilder(ILanguageManipulationService languageManipulationService)
 {
     _languageManipulationService = languageManipulationService ?? throw new ArgumentNullException(nameof(languageManipulationService));
 }
Example #15
0
        // Configure is called after ConfigureServices is called.
        public void Configure(
            IApplicationBuilder app,
            IHostingEnvironment env,
            ILoggerFactory loggerFactory,
            IPageConfiguration pageConfiguration,
            ILanguageManipulationService languageManipulationService)
        {
            if(pageConfiguration == null)
            {
                throw new ArgumentNullException(nameof(pageConfiguration));
            }

            if(languageManipulationService == null)
            {
                throw new ArgumentNullException(nameof(languageManipulationService));
            }

            loggerFactory.MinimumLevel = LogLevel.Warning;
            loggerFactory.AddConsole();

            // Configure the HTTP request pipeline.

            // Add the following to the request pipeline only in development environment.
            if (env.IsDevelopment())
            {
                app.UseBrowserLink();
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage(x => x.EnableAll());

                loggerFactory.AddDebug(LogLevel.Debug);
            }
            else
            {
                // Add Error handling middleware which catches all application specific errors and
                // sends the request to the following path or controller action.
                app.UseExceptionHandler("/Home/Error");

                loggerFactory.AddDebug(LogLevel.Critical);
            }

            // Add the platform handler to the request pipeline.
            app.UseIISPlatformHandler();

            // Add static files to the request pipeline.
            app.UseStaticFiles();

            // Add cookie-based authentication to the request pipeline.
            app.UseIdentity();

            var defaultCulture = languageManipulationService
                                   .LanguageDefinitionToCultureInfo(
                                      pageConfiguration.DefaultLanguage
                                   );
            app.UseRequestLocalization(new RequestLocalizationOptions
                {
                    SupportedCultures = languageManipulationService.SupportedCultures,
                    SupportedUICultures = languageManipulationService.SupportedCultures,
                    RequestCultureProviders = new[] { new CustomUrlStringCultureProvider(languageManipulationService) }
                }, 
                new RequestCulture(defaultCulture, defaultCulture)
            );

            // Add MVC to the request pipeline.
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: nameof(PersonalWebsite.Areas.Private),
                    template: "{area}/{controller}/{action}/{id?}",
                    defaults: new { },
                    constraints: new { area = "private" });
                routes.MapRoute(
                    name: "defaultWithLanguage",
                    template: "{language}/{controller=Home}/{action=Index}",
                    defaults: new { },
                    constraints: new { language = languageManipulationService.LanguageValidationRegexp() }
                );
                routes.MapRoute(
                    name: "defaultWithoutLanguage",
                    template: "{controller=Home}/{action=Index}",
                    defaults: new { language=String.Empty }
                );

                routes.MapRoute(
                    name: "contentsWithLanguage",
                    template: "{language}/{urlName}/{controller=Contents}/{action=Show}",
                    defaults: new { },
                    constraints: new { language = languageManipulationService.LanguageValidationRegexp() }
                );
                routes.MapRoute(
                    name: "contentsWithoutLanguage",
                    template: "{urlName}/{controller=Contents}/{action=Show}"
                );
            });

            using (var dataInitializer = new DataInitializer(app.ApplicationServices))
            {
                if (env.IsDevelopment())
                {
                    dataInitializer.ClearRequiredContents();
                    dataInitializer.ClearInitialUser();
                }

                dataInitializer.EnsureRequiredContentsAvailable();
                dataInitializer.EnsureInitialUserAvaialble();
            }
        }