public void SetUp() { TestHelper.SetupLog4NetForTests(); Umbraco.Core.Configuration.UmbracoSettings.UseLegacyXmlSchema = false; _httpContextFactory = new FakeHttpContextFactory("~/Home"); //ensure the StateHelper is using our custom context StateHelper.HttpContext = _httpContextFactory.HttpContext; _umbracoContext = new UmbracoContext(_httpContextFactory.HttpContext, new ApplicationContext(), new DefaultRoutesCache(false)); _umbracoContext.GetXmlDelegate = () => { var xDoc = new XmlDocument(); //create a custom xml structure to return xDoc.LoadXml(GetXml()); //return the custom x doc return(xDoc); }; _publishedContentStore = new DefaultPublishedContentStore(); }
public void SetUp() { TestHelper.SetupLog4NetForTests(); //create the app context ApplicationContext.Current = new ApplicationContext(false); _httpContextFactory = new FakeHttpContextFactory("~/Home"); //ensure the StateHelper is using our custom context StateHelper.HttpContext = _httpContextFactory.HttpContext; UmbracoSettings.UseLegacyXmlSchema = false; var cache = new PublishedContentCache { GetXmlDelegate = (context, preview) => { var doc = new XmlDocument(); doc.LoadXml(GetXml()); return(doc); } }; _umbracoContext = new UmbracoContext( _httpContextFactory.HttpContext, ApplicationContext.Current, new PublishedCaches(cache, new PublishedMediaCache())); _cache = _umbracoContext.ContentCache; }
public void BackOfficeRouting_Ensure_Default_Editor_Url_Structures() { //Arrange var context = new FakeHttpContextFactory("~/empty", new RouteData()); var contentEditor = new ContentEditorController(new FakeBackOfficeRequestContext()); var contentControllerName = RebelController.GetControllerName(contentEditor.GetType()); var contentControllerId = RebelController.GetControllerId <EditorAttribute>(contentEditor.GetType()); var dataTypeEditor = new DataTypeEditorController(new FakeBackOfficeRequestContext()); var dataTypeControllerName = RebelController.GetControllerName(dataTypeEditor.GetType()); var dataTypeControllerId = RebelController.GetControllerId <EditorAttribute>(dataTypeEditor.GetType()); var docTypeEditor = new DocumentTypeEditorController(new FakeBackOfficeRequestContext()); var docTypeControllerName = RebelController.GetControllerName(docTypeEditor.GetType()); var docTypeControllerId = RebelController.GetControllerId <EditorAttribute>(docTypeEditor.GetType()); const string customAction = "Index"; const string defaultAction = "Dashboard"; const int id = -1; const string area = "Rebel"; //Act //ensure the area is passed in because we're matchin a URL in an area, otherwise it will not work var contentEditorDefaultUrl = UrlHelper.GenerateUrl(null, defaultAction, contentControllerName, new RouteValueDictionary(new { area, id = UrlParameter.Optional, editorId = contentControllerId.ToString("N") }), RouteTable.Routes, context.RequestContext, true); var dataTypeEditorDefaultUrl = UrlHelper.GenerateUrl(null, defaultAction, dataTypeControllerName, new RouteValueDictionary(new { area, id = UrlParameter.Optional, editorId = dataTypeControllerId.ToString("N") }), RouteTable.Routes, context.RequestContext, true); var docTypeEditorDefaultUrl = UrlHelper.GenerateUrl(null, defaultAction, docTypeControllerName, new RouteValueDictionary(new { area, id = UrlParameter.Optional, editorId = docTypeControllerId.ToString("N") }), RouteTable.Routes, context.RequestContext, true); var contentEditorCustomUrl = UrlHelper.GenerateUrl(null, customAction, contentControllerName, new RouteValueDictionary(new { area, id, editorId = contentControllerId.ToString("N") }), RouteTable.Routes, context.RequestContext, true); var dataTypeEditorCustomUrl = UrlHelper.GenerateUrl(null, customAction, dataTypeControllerName, new RouteValueDictionary(new { area, id, editorId = dataTypeControllerId.ToString("N") }), RouteTable.Routes, context.RequestContext, true); var docTypeEditorCustomUrl = UrlHelper.GenerateUrl(null, customAction, docTypeControllerName, new RouteValueDictionary(new { area, id, editorId = docTypeControllerId.ToString("N") }), RouteTable.Routes, context.RequestContext, true); //Assert Assert.AreEqual(string.Format("/Rebel/Editors/{0}", contentControllerName), contentEditorDefaultUrl); Assert.AreEqual(string.Format("/Rebel/Editors/{0}", dataTypeControllerName), dataTypeEditorDefaultUrl); Assert.AreEqual(string.Format("/Rebel/Editors/{0}", docTypeControllerName), docTypeEditorDefaultUrl); Assert.AreEqual(string.Format("/Rebel/Editors/{0}/{1}/{2}", contentControllerName, customAction, id), contentEditorCustomUrl); Assert.AreEqual(string.Format("/Rebel/Editors/{0}/{1}/{2}", dataTypeControllerName, customAction, id), dataTypeEditorCustomUrl); Assert.AreEqual(string.Format("/Rebel/Editors/{0}/{1}/{2}", docTypeControllerName, customAction, id), docTypeEditorCustomUrl); }
public override void Initialize() { base.Initialize(); _httpContextFactory = new FakeHttpContextFactory("~/Home"); //ensure the StateHelper is using our custom context StateHelper.HttpContext = _httpContextFactory.HttpContext; var settings = SettingsForTests.GenerateMockSettings(); var contentMock = Mock.Get(settings.Content); contentMock.Setup(x => x.UseLegacyXmlSchema).Returns(false); SettingsForTests.ConfigureSettings(settings); _xml = new XmlDocument(); _xml.LoadXml(GetXml()); var cache = new PublishedContentCache { GetXmlDelegate = (context, preview) => _xml }; _umbracoContext = new UmbracoContext( _httpContextFactory.HttpContext, ApplicationContext, new PublishedCaches(cache, new PublishedMediaCache(ApplicationContext)), new WebSecurity(_httpContextFactory.HttpContext, ApplicationContext)); _cache = _umbracoContext.ContentCache; }
public void Setup() { // this is so the model factory looks into the test assembly _pluginManager = PluginManager.Current; PluginManager.Current = new PluginManager(false) { AssembliesToScan = _pluginManager.AssembliesToScan .Union(new[] { typeof(PublishedContentMoreTests).Assembly }) }; PropertyValueConvertersResolver.Current = new PropertyValueConvertersResolver(); PublishedContentModelFactoryResolver.Current = new PublishedContentModelFactoryResolver(new PublishedContentModelFactoryImpl()); Resolution.Freeze(); var caches = CreatePublishedContent(); ApplicationContext.Current = new ApplicationContext(false) { IsReady = true }; var factory = new FakeHttpContextFactory("http://umbraco.local/"); StateHelper.HttpContext = factory.HttpContext; var context = new UmbracoContext( factory.HttpContext, ApplicationContext.Current, caches); UmbracoContext.Current = context; }
public void ManyResolverHttpRequestLifetimeScope() { var httpContextFactory = new FakeHttpContextFactory("~/Home"); var httpContext = httpContextFactory.HttpContext; var resolver = new ManyResolver(httpContext); resolver.AddType <Resolved1>(); resolver.AddType <Resolved2>(); Resolution.Freeze(); var values = resolver.ResolvedObjects; Assert.AreEqual(2, values.Count()); Assert.IsInstanceOf <Resolved1>(values.ElementAt(0)); Assert.IsInstanceOf <Resolved2>(values.ElementAt(1)); var values2 = resolver.ResolvedObjects; Assert.AreEqual(2, values2.Count()); Assert.AreSame(values.ElementAt(0), values2.ElementAt(0)); Assert.AreSame(values.ElementAt(1), values2.ElementAt(1)); httpContextFactory.HttpContext.Items.Clear(); // new context var values3 = resolver.ResolvedObjects; Assert.AreEqual(2, values3.Count()); Assert.AreNotSame(values.ElementAt(0), values3.ElementAt(0)); Assert.AreNotSame(values.ElementAt(1), values3.ElementAt(1)); }
protected override void Initialize() { base.Initialize(); _httpContextFactory = new FakeHttpContextFactory("~/Home"); var umbracoSettings = Factory.GetInstance <IUmbracoSettingsSection>(); var globalSettings = Factory.GetInstance <IGlobalSettings>(); _xml = new XmlDocument(); _xml.LoadXml(GetXml()); var xmlStore = new XmlStore(() => _xml, null, null, null); var cacheProvider = new StaticCacheProvider(); var domainCache = new DomainCache(ServiceContext.DomainService, DefaultCultureAccessor); var publishedShapshot = new Umbraco.Web.PublishedCache.XmlPublishedCache.PublishedSnapshot( new PublishedContentCache(xmlStore, domainCache, cacheProvider, globalSettings, new SiteDomainHelper(), ContentTypesCache, null, null), new PublishedMediaCache(xmlStore, ServiceContext.MediaService, ServiceContext.UserService, cacheProvider, ContentTypesCache), new PublishedMemberCache(null, cacheProvider, Current.Services.MemberService, ContentTypesCache), domainCache); var publishedSnapshotService = new Mock <IPublishedSnapshotService>(); publishedSnapshotService.Setup(x => x.CreatePublishedSnapshot(It.IsAny <string>())).Returns(publishedShapshot); _umbracoContext = new UmbracoContext( _httpContextFactory.HttpContext, publishedSnapshotService.Object, new WebSecurity(_httpContextFactory.HttpContext, Current.Services.UserService, globalSettings), umbracoSettings, Enumerable.Empty <IUrlProvider>(), globalSettings, new TestVariationContextAccessor()); _cache = _umbracoContext.ContentCache; }
public void Is_Reserved_By_Route(string url, bool shouldMatch) { //reset the app config, we only want to test routes not the hard coded paths Umbraco.Core.Configuration.GlobalSettings.ReservedPaths = ""; Umbraco.Core.Configuration.GlobalSettings.ReservedUrls = ""; var routes = new RouteCollection(); routes.MapRoute( "Umbraco_default", "Umbraco/RenderMvc/{action}/{id}", new { controller = "RenderMvc", action = "Index", id = UrlParameter.Optional }); routes.MapRoute( "WebAPI", "api/{controller}/{id}", new { controller = "WebApiTestController", action = "Index", id = UrlParameter.Optional }); var context = new FakeHttpContextFactory(url); Assert.AreEqual( shouldMatch, Umbraco.Core.Configuration.GlobalSettings.IsReservedPathOrUrl(url, context.HttpContext, routes)); }
private UrlHelper CreateHelper() { var http = new FakeHttpContextFactory("~/test"); var url = new UrlHelper(http.RequestContext); return(url); }
public void Is_Reserved_By_Route(string url, bool shouldMatch) { //reset the app config, we only want to test routes not the hard coded paths var globalSettingsMock = Mock.Get(Factory.GetInstance <IGlobalSettings>()); //this will modify the IGlobalSettings instance stored in the container globalSettingsMock.Setup(x => x.ReservedPaths).Returns(""); globalSettingsMock.Setup(x => x.ReservedUrls).Returns(""); var routes = new RouteCollection(); routes.MapRoute( "Umbraco_default", "Umbraco/RenderMvc/{action}/{id}", new { controller = "RenderMvc", action = "Index", id = UrlParameter.Optional }); routes.MapRoute( "WebAPI", "api/{controller}/{id}", new { controller = "WebApiTestController", action = "Index", id = UrlParameter.Optional }); var context = new FakeHttpContextFactory(url); Assert.AreEqual( shouldMatch, globalSettingsMock.Object.IsReservedPathOrUrl(url, context.HttpContext, routes)); }
public override void Setup() { base.Setup(); var typeFinder = new TypeFinder(Mock.Of <ILogger>()); _ctx = new FakeHttpContextFactory("http://localhost/test"); _appCache = new HttpRequestAppCache(() => _ctx.HttpContext.Items, typeFinder); }
public void Ensure_Request_Routable(string url, bool assert) { var httpContextFactory = new FakeHttpContextFactory(url); var httpContext = httpContextFactory.HttpContext; var umbracoContext = GetUmbracoContext(url); var result = _module.EnsureUmbracoRoutablePage(umbracoContext, httpContext); Assert.AreEqual(assert, result.Success); }
/// <summary> /// Checks if the URL will be ignored in the RouteTable /// </summary> /// <param name="url"></param> /// <returns></returns> /// <remarks> /// MVCContrib has a similar one but is faulty: /// http://mvccontrib.codeplex.com/workitem/7173 /// </remarks> public static bool ShouldIgnoreRoute(this string url) { var http = new FakeHttpContextFactory(url); var r = RouteTable.Routes.GetRouteData(http.HttpContext); if (r == null) { return(false); } return(r.RouteHandler is StopRoutingHandler); }
public async Task ShouldCreateHttpContextUsingFactory() { // Given HttpContext context = null; var factory = new FakeHttpContextFactory(req => context = new HttpContext(req)); var pipeline = new RequestPipeline(factory); var request = new HttpRequest("HTTP/1.1", "GET", Url.Blank, new Dictionary<string, string[]>(), Stream.Null, null, string.Empty); // When var actual = await pipeline.HandleRequest(request, CancellationToken.None); Assert.Same(context, actual); }
public void BackOfficeRouting_Ensure_Plugin_Editor_Url_Structures() { //Arrange var context = new FakeHttpContextFactory("~/empty", new RouteData()); var contentEditor = new Stubs.Editors.ContentEditorController(new FakeBackOfficeRequestContext()); var contentControllerName = UmbracoController.GetControllerName(contentEditor.GetType()); var contentControllerId = UmbracoController.GetControllerId <EditorAttribute>(contentEditor.GetType()); var mediaEditorController = new Stubs.Editors.MediaEditorController(new FakeBackOfficeRequestContext()); var mediaControllerName = UmbracoController.GetControllerName(mediaEditorController.GetType()); var mediaControllerId = UmbracoController.GetControllerId <EditorAttribute>(mediaEditorController.GetType()); const string customAction = "Index"; const string defaultAction = "Dashboard"; const int id = -1; const string area = "TestPackage"; //Act //ensure the area is passed in because we're matchin a URL in an area, otherwise it will not work var contentEditorDefaultUrl = UrlHelper.GenerateUrl(null, defaultAction, contentControllerName, new RouteValueDictionary(new { area, id = UrlParameter.Optional, editorId = contentControllerId.ToString("N") }), RouteTable.Routes, context.RequestContext, true); var dataTypeEditorDefaulturl = UrlHelper.GenerateUrl(null, defaultAction, mediaControllerName, new RouteValueDictionary(new { area, id = UrlParameter.Optional, editorId = mediaControllerId.ToString("N") }), RouteTable.Routes, context.RequestContext, true); var contentEditorCustomUrl = UrlHelper.GenerateUrl(null, customAction, contentControllerName, new RouteValueDictionary(new { area, id, editorId = contentControllerId.ToString("N") }), RouteTable.Routes, context.RequestContext, true); var dataTypeEditorCustomurl = UrlHelper.GenerateUrl(null, customAction, mediaControllerName, new RouteValueDictionary(new { area, id, editorId = mediaControllerId.ToString("N") }), RouteTable.Routes, context.RequestContext, true); //Assert //Assert.AreEqual(string.Format("/Umbraco/TestPackage/Editors/{0}/{1}", contentControllerId.ToString("N"), contentControllerName), contentEditorDefaultUrl); //Assert.AreEqual(string.Format("/Umbraco/TestPackage/Editors/{0}/{1}", mediaControllerId.ToString("N"), mediaControllerName), dataTypeEditorDefaulturl); //Assert.AreEqual(string.Format("/Umbraco/TestPackage/Editors/{0}/{1}/{2}/{3}", contentControllerId.ToString("N"), contentControllerName, customAction, id), contentEditorCustomUrl); //Assert.AreEqual(string.Format("/Umbraco/TestPackage/Editors/{0}/{1}/{2}/{3}", mediaControllerId.ToString("N"), mediaControllerName, customAction, id), dataTypeEditorCustomurl); Assert.AreEqual(string.Format("/Umbraco/TestPackage/{0}", contentControllerName), contentEditorDefaultUrl); Assert.AreEqual(string.Format("/Umbraco/TestPackage/{0}", mediaControllerName), dataTypeEditorDefaulturl); Assert.AreEqual(string.Format("/Umbraco/TestPackage/{0}/{1}/{2}", contentControllerName, customAction, id), contentEditorCustomUrl); Assert.AreEqual(string.Format("/Umbraco/TestPackage/{0}/{1}/{2}", mediaControllerName, customAction, id), dataTypeEditorCustomurl); }
public void BackOfficeRouting_Ensure_Plugin_Tree_Url_Structures() { //Arrange var context = new FakeHttpContextFactory("~/empty", new RouteData()); var contentTree = new Stubs.Trees.ContentTreeController(new FakeBackOfficeRequestContext()); var contentControllerName = RebelController.GetControllerName(contentTree.GetType()); var contentControllerId = RebelController.GetControllerId <TreeAttribute>(contentTree.GetType()); var mediaTree = new Stubs.Trees.MediaTreeController(new FakeBackOfficeRequestContext()); var mediaTreeControllerName = RebelController.GetControllerName(mediaTree.GetType()); var mediaTreeControllerId = RebelController.GetControllerId <TreeAttribute>(mediaTree.GetType()); const string action = "Index"; var defaultId = HiveId.Empty; const int customId = 123; const string area = "TestPackage"; //Act //ensure the area is passed in because we're matchin a URL in an area, otherwise it will not work var contentTreeDefaultUrl = UrlHelper.GenerateUrl(null, action, contentControllerName, new RouteValueDictionary(new { area, id = defaultId, treeId = contentControllerId.ToString("N") }), RouteTable.Routes, context.RequestContext, true); var mediaTreeDefaultUrl = UrlHelper.GenerateUrl(null, action, mediaTreeControllerName, new RouteValueDictionary(new { area, id = defaultId, treeId = mediaTreeControllerId.ToString("N") }), RouteTable.Routes, context.RequestContext, true); var contentTreeCustomUrl = UrlHelper.GenerateUrl(null, action, contentControllerName, new RouteValueDictionary(new { area, id = customId, treeId = contentControllerId.ToString("N") }), RouteTable.Routes, context.RequestContext, true); var mediaTreeCustomUrl = UrlHelper.GenerateUrl(null, action, mediaTreeControllerName, new RouteValueDictionary(new { area, id = customId, treeId = mediaTreeControllerId.ToString("N") }), RouteTable.Routes, context.RequestContext, true); //Assert //Assert.AreEqual(string.Format("/Rebel/TestPackage/Trees/{0}/{1}", contentControllerId.ToString("N"), contentControllerName), contentTreeDefaultUrl); //Assert.AreEqual(string.Format("/Rebel/TestPackage/Trees/{0}/{1}", mediaTreeControllerId.ToString("N"), mediaTreeControllerName), mediaTreeDefaultUrl); //Assert.AreEqual(string.Format("/Rebel/TestPackage/Trees/{0}/{1}/{2}/{3}", contentControllerId.ToString("N"), contentControllerName, action, customId), contentTreeCustomUrl); //Assert.AreEqual(string.Format("/Rebel/TestPackage/Trees/{0}/{1}/{2}/{3}", mediaTreeControllerId.ToString("N"), mediaTreeControllerName, action, customId), mediaTreeCustomUrl); Assert.AreEqual(string.Format("/Rebel/TestPackage/{0}", contentControllerName), contentTreeDefaultUrl); Assert.AreEqual(string.Format("/Rebel/TestPackage/{0}", mediaTreeControllerName), mediaTreeDefaultUrl); Assert.AreEqual(string.Format("/Rebel/TestPackage/{0}/{1}/{2}", contentControllerName, action, customId), contentTreeCustomUrl); Assert.AreEqual(string.Format("/Rebel/TestPackage/{0}/{1}/{2}", mediaTreeControllerName, action, customId), mediaTreeCustomUrl); }
public void Ensure_All_Ancestor_ViewData_Is_Merged_Without_Data_Loss() { var http = new FakeHttpContextFactory("http://localhost"); //setup an heirarchy var rootViewCtx = new ViewContext { Controller = new MyController(), RequestContext = http.RequestContext, ViewData = new ViewDataDictionary() }; var parentViewCtx = new ViewContext { Controller = new MyController(), RequestContext = http.RequestContext, RouteData = new RouteData(), ViewData = new ViewDataDictionary() }; parentViewCtx.RouteData.DataTokens.Add("ParentActionViewContext", rootViewCtx); var controllerCtx = new ControllerContext(http.RequestContext, new MyController()) { RouteData = new RouteData() }; controllerCtx.RouteData.DataTokens.Add("ParentActionViewContext", parentViewCtx); //set up the view data with overlapping keys controllerCtx.Controller.ViewData["Test1"] = "Test1"; controllerCtx.Controller.ViewData["Test2"] = "Test2"; controllerCtx.Controller.ViewData["Test3"] = "Test3"; parentViewCtx.ViewData["Test2"] = "Test4"; parentViewCtx.ViewData["Test3"] = "Test5"; parentViewCtx.ViewData["Test4"] = "Test6"; rootViewCtx.ViewData["Test3"] = "Test7"; rootViewCtx.ViewData["Test4"] = "Test8"; rootViewCtx.ViewData["Test5"] = "Test9"; var filter = new ResultExecutingContext(controllerCtx, new ContentResult()) { RouteData = controllerCtx.RouteData }; var att = new MergeParentContextViewDataAttribute(); Assert.IsTrue(filter.IsChildAction); att.OnResultExecuting(filter); Assert.AreEqual(5, controllerCtx.Controller.ViewData.Count); Assert.AreEqual("Test1", controllerCtx.Controller.ViewData["Test1"]); Assert.AreEqual("Test2", controllerCtx.Controller.ViewData["Test2"]); Assert.AreEqual("Test3", controllerCtx.Controller.ViewData["Test3"]); Assert.AreEqual("Test6", controllerCtx.Controller.ViewData["Test4"]); Assert.AreEqual("Test9", controllerCtx.Controller.ViewData["Test5"]); }
public void NHibernateBootstrapper_Configure_Application() { //Arrange //create a new web.config file in /plugins for the providers to write to var http = new FakeHttpContextFactory("~/test"); var configFile = new FileInfo(Path.Combine(Environment.CurrentDirectory, "nhibernate.config")); var configMgr = new DeepConfigManager(http.HttpContext); var configXml = DeepConfigManager.CreateNewConfigFile(configFile, true); var installModel = new DatabaseInstallModel() { DatabaseType = DatabaseServerType.MSSQL, DatabaseName = "test", Server = "testserver", Username = "******", Password = "******" }; var boot = new ProviderBootstrapper(null, null, new FakeFrameworkContext()); //Act boot.ConfigureApplication("rw-test", "test", configXml, new BendyObject(installModel)); //Assert Assert.AreEqual(@"<configuration> <configSections> <sectionGroup name=""rebel""> <sectionGroup name=""persistenceProviderSettings""> <section name=""test"" type=""Rebel.Framework.Persistence.NHibernate.Config.ProviderConfigurationSection, Rebel.Framework.Persistence.NHibernate, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"" /> </sectionGroup> </sectionGroup> </configSections> <connectionStrings> <add name=""test.ConnString"" connectionString=""Data Source=testserver; Initial Catalog=test;User Id=testuser;Password=testpass"" providerName=""System.Data.SqlClient"" /> </connectionStrings> <appSettings /> <rebel> <persistenceProviderSettings> <test connectionStringKey=""test.ConnString"" sessionContext=""web"" driver=""MsSql2008"" /> </persistenceProviderSettings> </rebel> </configuration>", configXml.ToString()); }
public void BackOfficeRouting_Ensure_Default_Tree_Url_Structures() { //Arrange var context = new FakeHttpContextFactory("~/empty", new RouteData()); var contentTree = new ContentTreeController(new FakeBackOfficeRequestContext()); var contentControllerName = RebelController.GetControllerName(contentTree.GetType()); var contentControllerId = RebelController.GetControllerId <TreeAttribute>(contentTree.GetType()); var dataTypeTree = new DataTypeTreeController(new FakeBackOfficeRequestContext()); var dataTypeControllerName = RebelController.GetControllerName(dataTypeTree.GetType()); var dataTypeControllerId = RebelController.GetControllerId <TreeAttribute>(dataTypeTree.GetType()); const string action = "Index"; var customId = HiveId.ConvertIntToGuid(123); const string area = "Rebel"; //Act //ensure the area is passed in because we're matchin a URL in an area, otherwise it will not work var contentTreeDefaultUrl = UrlHelper.GenerateUrl(null, action, contentControllerName, new RouteValueDictionary(new { area, id = HiveId.Empty, treeId = contentControllerId.ToString("N") }), RouteTable.Routes, context.RequestContext, true); var dataTypeTreeDefaultUrl = UrlHelper.GenerateUrl(null, action, dataTypeControllerName, new RouteValueDictionary(new { area, id = HiveId.Empty, treeId = dataTypeControllerId.ToString("N") }), RouteTable.Routes, context.RequestContext, true); var contentTreeCustomUrl = UrlHelper.GenerateUrl(null, action, contentControllerName, new RouteValueDictionary(new { area, id = customId, treeId = contentControllerId.ToString("N") }), RouteTable.Routes, context.RequestContext, true); var dataTypeTreeCustomUrl = UrlHelper.GenerateUrl(null, action, dataTypeControllerName, new RouteValueDictionary(new { area, id = customId, treeId = dataTypeControllerId.ToString("N") }), RouteTable.Routes, context.RequestContext, true); //Assert Assert.AreEqual(string.Format("/Rebel/Trees/{0}", contentControllerName), contentTreeDefaultUrl); Assert.AreEqual(string.Format("/Rebel/Trees/{0}", dataTypeControllerName), dataTypeTreeDefaultUrl); Assert.AreEqual(string.Format("/Rebel/Trees/{0}/{1}/{2}", contentControllerName, action, HttpUtility.UrlEncode(customId.ToString())), contentTreeCustomUrl); Assert.AreEqual(string.Format("/Rebel/Trees/{0}/{1}/{2}", dataTypeControllerName, action, HttpUtility.UrlEncode(customId.ToString())), dataTypeTreeCustomUrl); }
public void FrontEndRouting_Umbraco_Route_User_Defined_Controller_Action() { var http = new FakeHttpContextFactory("~/home-page"); var content = new Content(new HiveId(Guid.NewGuid()), new List <TypedAttribute>()); content.CurrentTemplate = new Template(new HiveId(new Uri("storage://templates"), "", new HiveIdValue("home-page.cshtml"))); content.ContentType = new EntitySchema("customUmbraco"); RenderModelFactory.AddMatchingUrlForContent("/home-page", content); var data = RouteTable.Routes.GetDataForRoute(http.HttpContext); Assert.AreEqual(typeof(RenderRouteHandler), data.RouteHandler.GetType()); var handler = (RenderRouteHandler)data.RouteHandler; handler.GetHandlerForRoute(http.RequestContext, RenderModelFactory.Create(http.HttpContext, http.HttpContext.Request.RawUrl)); Assert.AreEqual("CustomUmbraco", data.Values["controller"].ToString()); Assert.AreEqual("HomePage", data.Values["action"].ToString()); }
private HiveEntityUri ExecuteBinding(IValueProvider form, RouteData routeData, out ModelBindingContext bindingContext, out ControllerContext controllerContext) { var modelBinder = new HiveEntityUriModelBinder(); var httpContextFactory = new FakeHttpContextFactory("~/Umbraco/Editors/ContentEditor/Edit/1", routeData); var fakeFrameworkContext = new FakeFrameworkContext(); var hive = FakeHiveCmsManager.New(fakeFrameworkContext); var resolverContext = new MockedMapResolverContext(hive, new MockedPropertyEditorFactory(), new MockedParameterEditorFactory()); var webmModelMapper = new CmsModelMapper(resolverContext); var cmsPersistenceModelMapper = new CmsPersistenceModelMapper(resolverContext); var cmsModelMapper = new CmsDomainMapper(resolverContext); fakeFrameworkContext.SetTypeMappers(new FakeTypeMapperCollection(new AbstractTypeMapper[] { webmModelMapper, cmsModelMapper, cmsPersistenceModelMapper })); var umbracoApplicationContext = new FakeUmbracoApplicationContext(hive); controllerContext = new ControllerContext( httpContextFactory.RequestContext, new ContentEditorController(new FakeBackOfficeRequestContext(umbracoApplicationContext))); //put both the form and route values in the value provider var routeDataValueProvider = new RouteDataValueProvider(controllerContext); var values = new ValueProviderCollection(new List <IValueProvider>() { form, routeDataValueProvider }); bindingContext = GetBindingContext(new HiveEntityUri(1), values); //do the binding! var model = modelBinder.BindModel(controllerContext, bindingContext); //assert! Assert.IsInstanceOfType(model, typeof(HiveEntityUri), "Model isn't a HiveEntityUri"); var boundModel = (HiveEntityUri)model; return(boundModel); }
private HiveId ExecuteBinding(IValueProvider form, RouteData routeData, out ModelBindingContext bindingContext, out ControllerContext controllerContext) { var modelBinder = new HiveIdModelBinder(); var httpContextFactory = new FakeHttpContextFactory("~/Rebel/Editors/ContentEditor/Edit/1", routeData); var fakeFrameworkContext = new FakeFrameworkContext(); var hive = FakeHiveCmsManager.New(fakeFrameworkContext); var appContext = new FakeRebelApplicationContext(hive); var resolverContext = new MockedMapResolverContext(fakeFrameworkContext, hive, new MockedPropertyEditorFactory(appContext), new MockedParameterEditorFactory()); var webmModelMapper = new CmsModelMapper(resolverContext); fakeFrameworkContext.SetTypeMappers(new FakeTypeMapperCollection(new AbstractMappingEngine[] { webmModelMapper, new FrameworkModelMapper(fakeFrameworkContext) })); var rebelApplicationContext = new FakeRebelApplicationContext(hive); controllerContext = new ControllerContext( httpContextFactory.RequestContext, new ContentEditorController(new FakeBackOfficeRequestContext(rebelApplicationContext))); //put both the form and route values in the value provider var routeDataValueProvider = new RouteDataValueProvider(controllerContext); var values = new ValueProviderCollection(new List <IValueProvider>() { form, routeDataValueProvider }); bindingContext = GetBindingContext(new HiveId(1), values); //do the binding! var model = modelBinder.BindModel(controllerContext, bindingContext); //assert! Assert.That(model, Is.InstanceOf <HiveId>(), "Model isn't a HiveId"); var boundModel = (HiveId)model; return(boundModel); }
public void Ensure_HttpRequest_Object_Creation() { var httpContextFactory = new FakeHttpContextFactory("~/Home"); var resolver = new HttpRequestObjectsResolver(httpContextFactory.HttpContext); resolver.AddType <TransientObject>(); Resolution.Freeze(); var instances1 = resolver.Objects; var instances2 = resolver.Objects; Assert.IsTrue(object.ReferenceEquals(instances1.Single(), instances2.Single())); //now clear the items, this is like mimicing a new request httpContextFactory.HttpContext.Items.Clear(); var instances3 = resolver.Objects; Assert.IsFalse(object.ReferenceEquals(instances1.Single(), instances3.Single())); }
protected override void Initialize() { base.Initialize(); _httpContextFactory = new FakeHttpContextFactory("~/Home"); var globalSettings = new GlobalSettings(); var umbracoContextAccessor = Factory.GetRequiredService <IUmbracoContextAccessor>(); _xml = new XmlDocument(); _xml.LoadXml(GetXml()); var xmlStore = new XmlStore(() => _xml, null, null, null, HostingEnvironment); var appCache = new DictionaryAppCache(); var domainCache = new DomainCache(Mock.Of <IDomainService>(), DefaultCultureAccessor); var publishedShapshot = new PublishedSnapshot( new PublishedContentCache(xmlStore, domainCache, appCache, globalSettings, ContentTypesCache, null, VariationContextAccessor, null), new PublishedMediaCache(xmlStore, Mock.Of <IMediaService>(), Mock.Of <IUserService>(), appCache, ContentTypesCache, Factory.GetRequiredService <IEntityXmlSerializer>(), umbracoContextAccessor, VariationContextAccessor), new PublishedMemberCache(ContentTypesCache, VariationContextAccessor), domainCache); var publishedSnapshotService = new Mock <IPublishedSnapshotService>(); publishedSnapshotService.Setup(x => x.CreatePublishedSnapshot(It.IsAny <string>())).Returns(publishedShapshot); var httpContext = _httpContextFactory.HttpContext; var httpContextAccessor = TestHelper.GetHttpContextAccessor(httpContext); _umbracoContext = new UmbracoContext( httpContextAccessor, publishedSnapshotService.Object, Mock.Of <IBackOfficeSecurity>(), globalSettings, HostingEnvironment, new TestVariationContextAccessor(), UriUtility, new AspNetCookieManager(httpContextAccessor)); _cache = _umbracoContext.Content; }
public override void Initialize() { base.Initialize(); _httpContextFactory = new FakeHttpContextFactory("~/Home"); //ensure the StateHelper is using our custom context StateHelper.HttpContext = _httpContextFactory.HttpContext; UmbracoSettings.UseLegacyXmlSchema = false; _xml = new XmlDocument(); _xml.LoadXml(GetXml()); var cache = new PublishedContentCache { GetXmlDelegate = (context, preview) => _xml }; _umbracoContext = new UmbracoContext( _httpContextFactory.HttpContext, ApplicationContext.Current, new PublishedCaches(cache, new PublishedMediaCache())); _cache = _umbracoContext.ContentCache; }
public override void SetUp() { var ctx = new FakeHttpContextFactory("/"); CacheProvider = new PerHttpRequestCacheProvider(ctx.HttpContext); }
/// <summary> /// Return the route data for the url based on a mocked context /// </summary> /// <param name="routes"></param> /// <param name="requestUrl"></param> /// <returns></returns> public static RouteData GetDataForRoute(this RouteCollection routes, string requestUrl) { var context = new FakeHttpContextFactory(requestUrl); return(routes.GetDataForRoute(context.HttpContext)); }
protected Umbraco.Cms.Web.Context.IBackOfficeRequestContext GetBackOfficeRequestContext(Uri uri) { var httpContext = new FakeHttpContextFactory(uri).HttpContext; return(new FakeBackOfficeRequestContext(UmbracoApplicationContext, new DefaultRoutingEngine(UmbracoApplicationContext, httpContext))); }
public override void Setup() { base.Setup(); _ctx = new FakeHttpContextFactory("http://localhost/test"); _provider = new HttpRequestCacheProvider(_ctx.HttpContext); }
public override void Setup() { base.Setup(); _ctx = new FakeHttpContextFactory("http://localhost/test"); _appCache = new HttpRequestAppCache(_ctx.HttpContext); }
public void NHibernateBootstrapper_Configure_Application() { //Arrange //create a new web.config file in /plugins for the providers to write to var http = new FakeHttpContextFactory("~/test"); var configFile = new FileInfo(Path.Combine(Environment.CurrentDirectory, "nhibernate.config")); var configMgr = new DeepConfigManager(http.HttpContext); var configXml = DeepConfigManager.CreateNewConfigFile(configFile, true); var installModel = new DatabaseInstallModel() { DatabaseType = DatabaseServerType.MSSQL, DatabaseName = "test", Server = "testserver", Username = "******", Password = "******" }; var boot = new ProviderBootstrapper(null, null, new FakeFrameworkContext()); //Act boot.ConfigureApplication("rw-test", "test", configXml, new BendyObject(installModel)); //Assert Assert.AreEqual(@"<configuration> <configSections> <sectionGroup name=""umbraco""> <sectionGroup name=""persistenceProviderSettings""> <section name=""test"" type=""Umbraco.Framework.Persistence.NHibernate.Config.ProviderConfigurationSection, Umbraco.Framework.Persistence.NHibernate, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"" /> </sectionGroup> </sectionGroup> </configSections> <connectionStrings> <add name=""test.ConnString"" connectionString=""Data Source=testserver; Initial Catalog=test;User Id=testuser;Password=testpass"" providerName=""System.Data.SqlClient"" /> </connectionStrings> <appSettings /> <umbraco> <persistenceProviderSettings> <test connectionStringKey=""test.ConnString"" sessionContext=""web"" driver=""MsSql2008"" /> </persistenceProviderSettings> </umbraco> </configuration>", configXml.ToString()); }
public static void InjectDependencies <T>( this T controller, IDictionary <string, string> querystringValues, IDictionary <string, string> formValues, IBackOfficeRequestContext backOfficeRequest, bool ensureModelStateError = true, bool noExecution = false, string userName = "******", string[] userRoles = null) where T : Controller { var routeData = new RouteData(); //we need to mock the dependency resolver for the IBackOfficeRequest context //because of how the RebelAuthorizationAttribute works var dependencyResolver = Substitute.For <IDependencyResolver>(); DependencyResolver.SetResolver(dependencyResolver); dependencyResolver.GetService(typeof(IBackOfficeRequestContext)).Returns(backOfficeRequest); var ctx = new FakeHttpContextFactory("~/MyController/MyAction/MyId"); controller.Url = new UrlHelper(ctx.RequestContext); controller.ValueProvider = formValues.ToValueProvider(); var context = new ControllerContext(ctx.RequestContext, controller) { RouteData = routeData }; controller.ControllerContext = context; //set the form values controller.HttpContext.Request.Stub(x => x.QueryString).Return(formValues.ToNameValueCollection()); controller.HttpContext.Request.Stub(x => x.Form).Return(formValues.ToNameValueCollection()); controller.HttpContext.Request.Stub(x => x.RequestType).Return(formValues.Count > 0 ? "POST" : "GET"); if (userRoles == null) { userRoles = new string[] { "administrator" } } ; //default to administrator var userData = new UserData() { Id = Guid.NewGuid().ToString("N"), AllowedApplications = new string[] {}, Username = userName, RealName = userName, Roles = userRoles, SessionTimeout = 0, StartContentNode = "-1", StartMediaNode = "-1" }; controller.HttpContext.Stub(x => x.User).Return(new FakePrincipal(new RebelBackOfficeIdentity(new FormsAuthenticationTicket(4, userName, DateTime.Now, DateTime.Now.AddDays(1), false, (new JavaScriptSerializer()).Serialize(userData))), userRoles)); if (!noExecution) { //if Initialize needs to run on the controller, this needs to occur, so we'll swallow the exception cuz there will always be one. try { (controller as IController).Execute(ctx.RequestContext); } catch (System.Exception) { } } if (ensureModelStateError) { //always ensure invalid model state so we can get the model returned controller.ModelState.AddModelError("DummyKey", "error"); } }