public void ConfigureServices(IServiceCollection services) { // [SystemConfigs] SystemConfigs.Service(services); // [Cros] Policy Cros.Service(services); // [Document API] Swagger Swagger.Service(services); // [Background Job] Hangfire Hangfire.Service(services); // [Caching] Redis Cache services.AddRedisCache(); // [Mini Response] WebMarkup WebMarkupMin.Service(services); // [Mapper] Auto Mapper services.AddAutoMapper(); // [MVC] Mvc.Service(services); // [Injection] Keep In Last DependencyInjection.Service(services); // [Database] Use Entity Framework Database.Service(services); }
public void Default_Post() { dynamic page = new MockGet(new string[] { "/" }); Mvc.Run(page, new PageController()); Assert_ShowDefaultPage(page); }
public void Edit_Wrong_Id_Shoud_Goto_Create() { dynamic page = new MockGet(new string[] { "Pages", "Edit", "id" }); Mvc.Run(page, new PageController()); Assert.AreEqual("~/Pages/Create", page.Page.Redirect); }
/// <summary> /// Filter for injecting the ViewResult of a controller into a Sitecore placeholder. /// /// Use this configuration snippet to enable: /// <mvc.resultExecuting> /// <processor type="Sitecore.Mvc.Contrib.Pipelines.MvcEvents.InjectViewInPlaceholderFilter, Sitecore.Mvc.Contrib"/> /// </mvc.resultExecuting> /// /// Will react to all controllers with the scItemPath and scPlaceholder set in the route data. E.g.: /// routes.MapRoute( /// "HelloWorld", // Route name /// "hello/{action}/{id}", // URL with parameters /// new { controller = "HelloWorld", scItemPath = "/sitecore/content/Mvc Sample", scPlaceholder = "main", id = UrlParameter.Optional } /// ); /// </summary> /// <param name="args">Pipeline arguments with filter context</param> public override void Process(Mvc.Pipelines.MvcEvents.ResultExecuting.ResultExecutingArgs args) { _logger.Info("Process called on InjectViewInPlaceholderFilter", this); var filterContext = args.Context; if (filterContext == null) return; var viewResult = filterContext.Result as ViewResult; if (viewResult == null) return; if (filterContext.HttpContext.Request.IsAjaxRequest()) return; if (filterContext.HttpContext.Items["injectorHasRun"] != null) return; var placeholder = filterContext.RouteData.Values["scPlaceholder"] as string; if (IsMissingPresentationValues(placeholder)) return; var viewPath = GetViewPath(viewResult, filterContext); var viewEngineResult = GetView(viewResult, filterContext, viewPath); viewResult.View = InjectViewInPlace(placeholder, filterContext.Controller.ControllerContext, viewEngineResult.View, viewResult.ViewData, viewResult.TempData); }
public void Edit_Post_Update() { dynamic data = new ExpandoObject(); data.Id = "id"; dynamic model = new Mock(); model.Setup("Update", new object[] { It.Is <dynamic>(item => item.Id == "id") }, model); model.SetupGet("Value", data); model.SetupGet("HasError", false); //this bypasses validation var form = new NameValueCollection(); form["OldId"] = "id"; dynamic page = new MockPost(new string[] { "Pages", "Edit" }, form); page.Response.Setup("Redirect", new object[] { "~/Pages/List", false }); var controller = new PageController(); controller.Model = model; Mvc.Run(page, controller); Assert.AreEqual("~/Pages/id", page.Page.Redirect); // redirect model.Verify(); }
public void Create_Post() { dynamic data = new ExpandoObject(); data.Id = "new-page"; dynamic model = new Mock(); model.Setup("Create", new object[] { It.Is <dynamic>(item => item.Title == "new page") }, model); model.SetupGet("Value", data); model.SetupGet("HasError", false); var form = new NameValueCollection(); form["title"] = "new page"; dynamic page = new MockPost(new string[] { "Pages", "Create" }, form); var controller = new PageController(); controller.Model = model; Mvc.Run(page, controller); Assert.AreEqual("~/Pages/new-page", page.Page.Redirect); model.Verify(); }
public void Create_Post_Should_Handle_Error() { dynamic data = new ExpandoObject(); data.Id = "id"; dynamic model = new Mock(); model.Setup("Create", new object[] { It.Is <dynamic>(item => item.Title == "new page") }, model); model.SetupGet("Value", data); model.SetupGet("HasError", true); // this raises validation error model.SetupGet("Errors", "x"); var form = new NameValueCollection(); form["title"] = "new page"; dynamic page = new MockPost(new string[] { "Pages", "Create" }, form); var controller = new PageController(); controller.Model = model; Mvc.Run(page, controller); Assert.AreEqual("~/Views/Pages/_Page_Create.cshtml", page.Page.View); // stayed on create page Assert.AreEqual("x", page.Page.Model.Errors); // pushed error messages model.Verify(); }
protected void Application_Start() { AutoFac.Setup(); Ef4.Setup(); Mvc.Setup(); Solr.Setup(); }
public void Edit_Post_Should_Handle_Error() { dynamic data = new ExpandoObject(); data.Id = "id"; dynamic model = new Mock(); model.Setup("Update", new object[] { It.Is <dynamic>(item => item.Id == "id") }, model); model.SetupGet("Value", data); model.SetupGet("HasError", true); // this raises validation error model.SetupGet("Errors", "x"); var form = new NameValueCollection(); form["OldId"] = "id"; dynamic page = new MockPost(new string[] { "Pages", "Edit", "id" }, form); var controller = new PageController(); controller.Model = model; Mvc.Run(page, controller); var view = SiteEngine.RunHook("GET_Pages_Page_Edit_View", page.Page.View) as string; Assert.AreEqual(view, page.Page.View); //stayed on edit page Assert.AreEqual("x", page.Page.Model.Errors); // pushed error message model.Verify(); }
public void Edit_Post_SaveAs() { dynamic data = new ExpandoObject(); data.Id = "new-id"; dynamic model = new Mock(); model.Setup("SaveAs", new object[] { It.Is <dynamic>(item => item.Id == "old-id"), "new-id" }, model); model.SetupGet("Value", data); model.SetupGet("HasError", false); //this bypasses validation model.Setup("Load", new object[] { It.Is <dynamic>(item => item.Id == "new-id") }, model); model.SetupGet("Value", data); var form = new NameValueCollection(); form["OldId"] = "old-id"; form["Id"] = "new-id"; dynamic page = new MockPost(new string[] { "Pages", "Edit", "id" }, form); var controller = new PageController(); controller.Model = model; Mvc.Run(page, controller); Assert.AreEqual("~/Pages/new-id", page.Page.Redirect); }
public static Config.Config InitApp(HttpConfiguration httpConfig, Service.Config.Config config = null) { XmlConfigurator.Configure(); GlobalContext.Properties["Version"] = typeof(MainController).Assembly.GetName().Version; config = config ?? ReadConfig(); if (config.Environment == "Development") { new Development().Run(config); } else { new Production().Run(config); } //в тестах мы можем запустить две копии приложения if (SessionFactory == null) { var nhibernate = new Config.Initializers.NHibernate(); nhibernate.Init(); SessionFactory = nhibernate.Factory; } ReadDbConfig(config); var mvc = new Mvc(); mvc.Run(httpConfig, SessionFactory, config); new Config.Initializers.SmartOrderFactory().Init(SessionFactory); return(config); }
[ExpectedException(typeof(Exception))] //delete through GET should not be allowed public void Get_Delete() { dynamic webPage = new MockGet(new string[] { "Mock", "Delete", "y", "z" }); dynamic controller = new MockController(); Mvc.Run(webPage, controller); controller.Verify(); }
public void Routing_Post() { dynamic webPage = new MockPost(new string[] { "Mock", "a", "b", "c" }, null); dynamic controller = new MockController(); Mvc.Run(webPage, controller); Assert.IsTrue(controller.Post_Called); controller.Verify(); }
public void Get_Edit_Pass_String() { dynamic webPage = new MockGet(new string[] { "Mock", "Edit", "y", "z" }); dynamic controller = new MockController(); Mvc.Run(webPage, controller); Assert.AreEqual("y/z", controller.Id); controller.Verify(); }
public void Routing_Get() { dynamic webPage = new MockGet(new string[] { "Mock", "a", "1", "2" }); dynamic controller = new MockController(); Mvc.Run(webPage, controller); Assert.IsTrue(controller.Get_Called); controller.Verify(); }
public void Post_Delete() { dynamic webPage = new MockPost(new string[] { "Mock", "Delete", "y", "z" }, null); dynamic controller = new MockController(); Mvc.Run(webPage, controller); Assert.AreEqual("y/z", controller.Id); controller.Verify(); }
public void Create_Get() { dynamic page = new MockGet(new string[] { "Pages", "Create", "id" }); Mvc.Run(page, new PageController()); Assert.AreEqual("~/Views/Pages/_Page_Create.cshtml", page.Page.View); Assert.IsTrue(page.Page.Model.Id == null); Assert.AreEqual("[New Page]", page.Page.Model.Title); }
public static void ConfigureServices(IConfiguration configuration, IServiceCollection services) { Mvc.ConfigureService(configuration, services); Swagger.ConfigureService(configuration, services); ApiVersioning.ConfigureService(services); services.AddAutoMapper(); AplicacaoConfiguracao.ConfigureService(configuration, services); Repositories.ConfigureService(services); ApiServices.ConfigureService(services); }
private static TagBuilder InlineEditForFieldTagBuilder(Mvc.ViewEngines.Razor.WebViewPage<dynamic> webViewPage, InlineViewModel viewModel, string partTypeName, string fieldTypeName) { var tagBuilder = new TagBuilder("form"); tagBuilder.MergeAttribute("action", webViewPage.Url.EditShape(viewModel.Content.Id, (string)viewModel.DisplayShape.Metadata.Type, "Field", partTypeName, fieldTypeName)); tagBuilder.MergeAttribute("method", "post", true); tagBuilder.MergeAttribute("enctype", "multipart/form-data", true); return tagBuilder; }
protected override Mvc.Presentation.Renderer GetRenderer(Mvc.Presentation.Rendering rendering, GetRendererArgs args) { Tuple<string, string> controllerAndAction = this.GetControllerAndAction(rendering, args); if (!IsChildActionRendering(args.RenderingTemplate) || controllerAndAction == null) { return null; } string controller = controllerAndAction.Item1; string action = controllerAndAction.Item2; return new ChildActionRenderer { ControllerName = controller, ActionName = action }; }
public void Routing_All() { dynamic webPage = new MockGet(new string[] { "Mock", "x", "y", "z" }); dynamic controller = new MockController(); Mvc.Run(webPage, controller); Assert.IsTrue(controller.All_Called); Assert.AreEqual("y", controller.UrlData[1]); Assert.AreEqual("z", controller.UrlData[2]); controller.Verify(); }
public void RenderView_Should_Get_Calling_Function_Name_As_View() { var webPage = new MockGet(new string[] { "Test", "List" }); var controller = new TestController(); Mvc.Run(webPage, controller); Assert.AreEqual("~/Views//__List.cshtml", webPage.Page.View); webPage.Verify(); }
public void Delete_Post() { dynamic model = new Mock(); model.Setup("Delete", new object[] { It.Is <dynamic>(item => item.Id == "id") }, null); dynamic page = new MockPost(new string[] { "Pages", "Delete", "id" }, null); //get id from url var controller = new PageController(); controller.Model = model; Mvc.Run(page, controller); model.Verify(); Assert.AreEqual("~/Pages/List", page.Page.Redirect); }
public static void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseHsts(); app.UseHttpsRedirection(); } Swagger.Configure(app); Mvc.Configure(app); }
public void Post_Edit_Pass_Form() { dynamic webPage = new MockPost(new string[] { "Mock", "Edit", "y", "z" }, null); webPage.Request.TestValue = -20.3m; dynamic controller = new MockController(); Mvc.Run(webPage, controller); Assert.AreEqual("y/z", controller.Id); Assert.AreEqual(-20.3m, controller.TestValue); controller.Verify(); }
public void List_Should_Use_PageSize() { dynamic model = new Mock(); model.Setup("List", new object[] { 5, 30 }, model); model.SetupGet("Value", new ExpandoObject()); dynamic page = new MockGet(new string[] { "Pages", "List", "5", "30" }); var controller = new PageController(); controller.Model = model; Mvc.Run(page, controller); Assert.AreEqual("~/Views/Pages/_Page_List.cshtml", page.Page.View); model.Verify(); }
/// <summary> /// Setup DevMvcComponent /// </summary> private static void SetupDevMvcComponent() { // initialize DevMvcComponent // Configure this with add a sender email. var mailer = new CustomMailServer( AppVar.Name, Setting.SenderEmail, Setting.SenderEmailPassword, Setting.SmtpHost, Setting.SmtpMailPort, Setting.IsSmtpssl); Mvc.Setup(AppVar.Name, Setting.DeveloperEmail, Assembly.GetExecutingAssembly(), mailer); //Mvc.Mailer.QuickSend("*****@*****.**", "Hello", "Hello"); Cookies = Mvc.Cookies; Caches = Mvc.Caches; }
static void Main(string[] args) { Mvc.Setup(System.Reflection.Assembly.GetExecutingAssembly()); string passPhraseFileName = "passPhrase.txt"; string encryptedFileName = "encrypted.txt"; while (true) { var prevPassPhrase = File.Exists(passPhraseFileName) ? File.ReadAllText(passPhraseFileName) : ""; var prevEncryptedtext = File.Exists(encryptedFileName) ? File.ReadAllText(encryptedFileName) : ""; if (!string.IsNullOrEmpty(prevPassPhrase)) { Console.WriteLine("Previous Encrypted String:"); Console.WriteLine(prevPassPhrase); Console.WriteLine("Previous Encrypted String as Decrypted:"); string tempDecryptedstring = Pbkdf2Encryption.Decrypt(prevEncryptedtext, prevPassPhrase); Console.WriteLine(tempDecryptedstring); } Console.WriteLine("Please enter a pass phrase to use:"); string passphrase = Console.ReadLine(); Console.WriteLine("Please enter a string to encrypt:"); string encryptingString = Console.ReadLine(); Console.WriteLine(""); Console.WriteLine("Your encrypted string is:"); string encryptedstring = Pbkdf2Encryption.Encrypt(encryptingString, passphrase); File.WriteAllText(encryptedFileName, encryptedstring); File.WriteAllText(passPhraseFileName, passphrase); Console.WriteLine("Saved respective strings into encrypted.txt and passPhrase.txt inside the executing folder."); Console.WriteLine(encryptedstring); Console.WriteLine(""); Console.WriteLine("Your decrypted string is:"); string decryptedstring = Pbkdf2Encryption.Decrypt(encryptedstring, passphrase); Console.WriteLine(decryptedstring); Console.WriteLine(""); Console.WriteLine("Press any key to exit..."); Console.ReadLine(); } }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); var assembly = System.Reflection.Assembly.GetExecutingAssembly(); var password = "******"; var mailServer = new GmailServer("testing email", "*****@*****.**", password); Mvc.Setup("DevMvcComponent Test", "*****@*****.**", assembly, mailServer); Mvc.Mailer.QuickSend("*****@*****.**", "subject", "<b>body</b>", isHtml: true); //try { // throw new Exception("Hello World"); //} catch (Exception ex) { // Mvc.Error.ByEmail(ex, "[email protected],[email protected]", "Method Name", "Custom Subject", Mvc.Mailer); //} //Console.WriteLine("Done sending email"); }
public void Edit_Get() { dynamic data = new ExpandoObject(); data.Id = "id"; dynamic model = new Mock(); model.Setup("Load", new object[] { It.Is <dynamic>(item => item.Id == "id") }, model); model.SetupGet("Value", data); dynamic page = new MockGet(new string[] { "Pages", "Edit", "id" }); var controller = new PageController(); controller.Model = model; Mvc.Run(page, controller); var view = SiteEngine.RunHook("GET_Pages_Page_Edit_View", page.Page.View) as string; Assert.AreEqual(view, page.Page.View); Assert.AreEqual("id", page.Page.Model.Id); model.Verify(); }
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory) { // [Important] The order of middleware very important for request and response handle! // Don't mad it !!! // [SystemConfigs] SystemConfigs.Middleware(app, loggerFactory); // Migrate Database app.DatabaseMigrate(); // [Response] Information ProcessingTimeMiddleware.Middleware(app); SystemInfoMiddleware.Middleware(app); // [Cros] Policy Cros.Middleware(app); // [Log] Serilog Log.Middleware(app, loggerFactory); // [Exception] Exception.Middleware(app); // [Security] Identity Server IdentityServer.Middleware(app); // [Document API] Swagger Swagger.Middleware(app); // [Background Job] Hangfire Hangfire.Middleware(app); // [Mini Response] WebMarkup WebMarkupMin.Middleware(app); // [MVC] Keep In Last Mvc.Middleware(app); }
[ExpectedException(typeof(Exception))] // Get is not allowed public void Delete_Get() { dynamic page = new MockGet(new string[] { "Pages", "Delete", "id" }); Mvc.Run(page, new PageController()); }
public override void Initialize(Mvc.Presentation.Rendering rendering) { base.Initialize(rendering); PlayerStream = GetRenderingItemLinkFieldAbsoluteUrl("Twitter Card Player Stream"); }