public void Can_Construct_And_Get_Result() { var globalSettings = TestObjects.GetGlobalSettings(); var umbracoContextFactory = new UmbracoContextFactory( Current.UmbracoContextAccessor, Mock.Of <IPublishedSnapshotService>(), new TestVariationContextAccessor(), new TestDefaultCultureAccessor(), TestObjects.GetUmbracoSettings(), globalSettings, new UrlProviderCollection(Enumerable.Empty <IUrlProvider>()), new MediaUrlProviderCollection(Enumerable.Empty <IMediaUrlProvider>()), Mock.Of <IUserService>()); var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext(Mock.Of <HttpContextBase>()); var umbracoContext = umbracoContextReference.UmbracoContext; var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext); var ctrl = new TestSurfaceController(umbracoContextAccessor); var result = ctrl.Index(); Assert.IsNotNull(result); }
public void Can_Lookup_Content() { var appCtx = new ApplicationContext( CacheHelper.CreateDisabledCacheHelper(), new ProfilingLogger(Mock.Of <ILogger>(), Mock.Of <IProfiler>())); var umbCtx = UmbracoContext.EnsureContext( new Mock <HttpContextBase>().Object, appCtx, new Mock <WebSecurity>(null, null).Object, Mock.Of <IUmbracoSettingsSection>(section => section.WebRouting == Mock.Of <IWebRoutingSection>(routingSection => routingSection.UrlProviderMode == "AutoLegacy")), Enumerable.Empty <IUrlProvider>(), true); var helper = new UmbracoHelper( umbCtx, Mock.Of <IPublishedContent>(), Mock.Of <ITypedPublishedContentQuery>(query => query.TypedContent(It.IsAny <int>()) == //return mock of IPublishedContent for any call to GetById Mock.Of <IPublishedContent>(content => content.Id == 2)), Mock.Of <IDynamicPublishedContentQuery>(), Mock.Of <ITagQuery>(), Mock.Of <IDataTypeService>(), new UrlProvider(umbCtx, Enumerable.Empty <IUrlProvider>()), Mock.Of <ICultureDictionary>(), Mock.Of <IUmbracoComponentRenderer>(), new MembershipHelper(umbCtx, Mock.Of <MembershipProvider>(), Mock.Of <RoleProvider>())); var ctrl = new TestSurfaceController(umbCtx, helper); var result = ctrl.GetContent(2) as PublishedContentResult; Assert.IsNotNull(result); Assert.AreEqual(2, result.Content.Id); }
public void Can_Lookup_Content() { var publishedSnapshot = new Mock <IPublishedSnapshot>(); publishedSnapshot.Setup(x => x.Members).Returns(Mock.Of <IPublishedMemberCache>()); var content = new Mock <IPublishedContent>(); content.Setup(x => x.Id).Returns(2); var backofficeSecurityAccessor = Mock.Of <IBackOfficeSecurityAccessor>(); Mock.Get(backofficeSecurityAccessor).Setup(x => x.BackOfficeSecurity).Returns(Mock.Of <IBackOfficeSecurity>()); var globalSettings = new GlobalSettings(); var umbracoContextFactory = TestUmbracoContextFactory.Create(globalSettings, _umbracoContextAccessor); var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext(); var umbracoContext = umbracoContextReference.UmbracoContext; var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext); var publishedContentQuery = Mock.Of <IPublishedContentQuery>(query => query.Content(2) == content.Object); var ctrl = new TestSurfaceController(umbracoContextAccessor, publishedContentQuery, Mock.Of <IPublishedUrlProvider>()); var result = ctrl.GetContent(2) as PublishedContentResult; Assert.IsNotNull(result); Assert.IsNotNull(result.Content); Assert.AreEqual(2, result.Content.Id); }
public void Mock_Current_Page() { var webRoutingSettings = Mock.Of <IWebRoutingSection>(section => section.UrlProviderMode == "Auto"); var globalSettings = TestObjects.GetGlobalSettings(); var umbracoContextFactory = new UmbracoContextFactory( Current.UmbracoContextAccessor, Mock.Of <IPublishedSnapshotService>(), new TestVariationContextAccessor(), new TestDefaultCultureAccessor(), Mock.Of <IUmbracoSettingsSection>(section => section.WebRouting == webRoutingSettings), globalSettings, new UrlProviderCollection(Enumerable.Empty <IUrlProvider>()), new MediaUrlProviderCollection(Enumerable.Empty <IMediaUrlProvider>()), Mock.Of <IUserService>()); var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext(Mock.Of <HttpContextBase>()); var umbracoContext = umbracoContextReference.UmbracoContext; var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext); var content = Mock.Of <IPublishedContent>(publishedContent => publishedContent.Id == 12345); var contextBase = umbracoContext.HttpContext; var publishedRouter = BaseWebTest.CreatePublishedRouter(TestObjects.GetUmbracoSettings().WebRouting); var frequest = publishedRouter.CreateRequest(umbracoContext, new Uri("http://localhost/test")); frequest.PublishedContent = content; var routeDefinition = new RouteDefinition { PublishedRequest = frequest }; var routeData = new RouteData(); routeData.DataTokens.Add(Core.Constants.Web.UmbracoRouteDefinitionDataToken, routeDefinition); var ctrl = new TestSurfaceController(umbracoContextAccessor, new UmbracoHelper()); ctrl.ControllerContext = new ControllerContext(contextBase, routeData, ctrl); var result = ctrl.GetContentFromCurrentPage() as PublishedContentResult; Assert.AreEqual(12345, result.Content.Id); }
public void Umbraco_Context_Not_Null() { var globalSettings = new GlobalSettings(); var backofficeSecurityAccessor = Mock.Of <IBackOfficeSecurityAccessor>(); Mock.Get(backofficeSecurityAccessor).Setup(x => x.BackOfficeSecurity).Returns(Mock.Of <IBackOfficeSecurity>()); var umbracoContextFactory = TestUmbracoContextFactory.Create(globalSettings, _umbracoContextAccessor); var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext(); var umbCtx = umbracoContextReference.UmbracoContext; var umbracoContextAccessor = new TestUmbracoContextAccessor(umbCtx); var ctrl = new TestSurfaceController(umbracoContextAccessor, Mock.Of <IPublishedContentQuery>(), Mock.Of <IPublishedUrlProvider>()); Assert.IsNotNull(ctrl.UmbracoContext); }
public void Can_Lookup_Content() { var publishedSnapshot = new Mock <IPublishedSnapshot>(); publishedSnapshot.Setup(x => x.Members).Returns(Mock.Of <IPublishedMemberCache>()); var contentCache = new Mock <IPublishedContentCache>(); var content = new Mock <IPublishedContent>(); content.Setup(x => x.Id).Returns(2); contentCache.Setup(x => x.GetById(It.IsAny <int>())).Returns(content.Object); var mediaCache = new Mock <IPublishedMediaCache>(); publishedSnapshot.Setup(x => x.Content).Returns(contentCache.Object); publishedSnapshot.Setup(x => x.Media).Returns(mediaCache.Object); var publishedSnapshotService = new Mock <IPublishedSnapshotService>(); publishedSnapshotService.Setup(x => x.CreatePublishedSnapshot(It.IsAny <string>())).Returns(publishedSnapshot.Object); var globalSettings = TestObjects.GetGlobalSettings(); var umbracoContext = UmbracoContext.EnsureContext( Current.UmbracoContextAccessor, new Mock <HttpContextBase>().Object, publishedSnapshotService.Object, new Mock <WebSecurity>(null, null, globalSettings).Object, Mock.Of <IUmbracoSettingsSection>(section => section.WebRouting == Mock.Of <IWebRoutingSection>(routingSection => routingSection.UrlProviderMode == "AutoLegacy")), Enumerable.Empty <IUrlProvider>(), globalSettings, new TestVariationContextAccessor(), true); var helper = new UmbracoHelper( umbracoContext, Mock.Of <IPublishedContent>(), Mock.Of <ITagQuery>(), Mock.Of <ICultureDictionary>(), Mock.Of <IUmbracoComponentRenderer>(), new MembershipHelper(new TestUmbracoContextAccessor(umbracoContext), Mock.Of <MembershipProvider>(), Mock.Of <RoleProvider>(), Mock.Of <IMemberService>(), Mock.Of <IMemberTypeService>(), Mock.Of <IUserService>(), Mock.Of <IPublicAccessService>(), null, Mock.Of <CacheHelper>(), Mock.Of <ILogger>()), ServiceContext.CreatePartial()); var ctrl = new TestSurfaceController(umbracoContext, helper); var result = ctrl.GetContent(2) as PublishedContentResult; Assert.IsNotNull(result); Assert.AreEqual(2, result.Content.Id); }
public void Umbraco_Context_Not_Null() { var globalSettings = TestObjects.GetGlobalSettings(); var umbCtx = UmbracoContext.EnsureContext( Current.UmbracoContextAccessor, new Mock <HttpContextBase>().Object, Mock.Of <IPublishedSnapshotService>(), new Mock <WebSecurity>(null, null, globalSettings).Object, TestObjects.GetUmbracoSettings(), Enumerable.Empty <IUrlProvider>(), globalSettings, new TestVariationContextAccessor(), true); var ctrl = new TestSurfaceController(umbCtx); Assert.IsNotNull(ctrl.UmbracoContext); }
public void Mock_Current_Page() { var appCtx = new ApplicationContext( CacheHelper.CreateDisabledCacheHelper(), new ProfilingLogger(Mock.Of <ILogger>(), Mock.Of <IProfiler>())); var webRoutingSettings = Mock.Of <IWebRoutingSection>(section => section.UrlProviderMode == "AutoLegacy"); var umbCtx = UmbracoContext.EnsureContext( new Mock <HttpContextBase>().Object, appCtx, new Mock <WebSecurity>(null, null).Object, Mock.Of <IUmbracoSettingsSection>(section => section.WebRouting == webRoutingSettings), Enumerable.Empty <IUrlProvider>(), true); var content = Mock.Of <IPublishedContent>(publishedContent => publishedContent.Id == 12345); var contextBase = umbCtx.HttpContext; var pcr = new PublishedContentRequest(new Uri("http://localhost/test"), umbCtx.RoutingContext, webRoutingSettings, s => Enumerable.Empty <string>()) { PublishedContent = content }; var routeDefinition = new RouteDefinition { PublishedContentRequest = pcr }; var routeData = new RouteData(); routeData.DataTokens.Add(Umbraco.Core.Constants.Web.UmbracoRouteDefinitionDataToken, routeDefinition); var ctrl = new TestSurfaceController(umbCtx, new UmbracoHelper()); ctrl.ControllerContext = new ControllerContext(contextBase, routeData, ctrl); var result = ctrl.GetContentFromCurrentPage() as PublishedContentResult; Assert.AreEqual(12345, result.Content.Id); }
public void Can_Lookup_Content() { var publishedSnapshot = new Mock <IPublishedSnapshot>(); publishedSnapshot.Setup(x => x.Members).Returns(Mock.Of <IPublishedMemberCache>()); var content = new Mock <IPublishedContent>(); content.Setup(x => x.Id).Returns(2); var publishedSnapshotService = new Mock <IPublishedSnapshotService>(); var globalSettings = TestObjects.GetGlobalSettings(); var umbracoContextFactory = new UmbracoContextFactory( Current.UmbracoContextAccessor, publishedSnapshotService.Object, new TestVariationContextAccessor(), new TestDefaultCultureAccessor(), Mock.Of <IUmbracoSettingsSection>(section => section.WebRouting == Mock.Of <IWebRoutingSection>(routingSection => routingSection.UrlProviderMode == "Auto")), globalSettings, new UrlProviderCollection(Enumerable.Empty <IUrlProvider>()), new MediaUrlProviderCollection(Enumerable.Empty <IMediaUrlProvider>()), Mock.Of <IUserService>()); var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext(Mock.Of <HttpContextBase>()); var umbracoContext = umbracoContextReference.UmbracoContext; var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext); var helper = new UmbracoHelper( content.Object, Mock.Of <ITagQuery>(), Mock.Of <ICultureDictionaryFactory>(), Mock.Of <IUmbracoComponentRenderer>(), Mock.Of <IPublishedContentQuery>(query => query.Content(2) == content.Object), new MembershipHelper(umbracoContext.HttpContext, Mock.Of <IPublishedMemberCache>(), Mock.Of <MembershipProvider>(), Mock.Of <RoleProvider>(), Mock.Of <IMemberService>(), Mock.Of <IMemberTypeService>(), Mock.Of <IUserService>(), Mock.Of <IPublicAccessService>(), AppCaches.Disabled, Mock.Of <ILogger>())); var ctrl = new TestSurfaceController(umbracoContextAccessor, helper); var result = ctrl.GetContent(2) as PublishedContentResult; Assert.IsNotNull(result); Assert.IsNotNull(result.Content); Assert.AreEqual(2, result.Content.Id); }
public void Umbraco_Helper_Not_Null() { var appCtx = new ApplicationContext( new DatabaseContext(new Mock <IScopeProviderInternal>().Object, Mock.Of <ILogger>(), Mock.Of <ISqlSyntaxProvider>(), "test"), MockHelper.GetMockedServiceContext(), CacheHelper.CreateDisabledCacheHelper(), new ProfilingLogger(Mock.Of <ILogger>(), Mock.Of <IProfiler>())); var umbCtx = UmbracoContext.EnsureContext( new Mock <HttpContextBase>().Object, appCtx, new Mock <WebSecurity>(null, null).Object, Mock.Of <IUmbracoSettingsSection>(), Enumerable.Empty <IUrlProvider>(), true); var ctrl = new TestSurfaceController(umbCtx); Assert.IsNotNull(ctrl.Umbraco); }
public void Umbraco_Context_Not_Null() { var appCtx = new ApplicationContext( CacheHelper.CreateDisabledCacheHelper(), new ProfilingLogger(Mock.Of <ILogger>(), Mock.Of <IProfiler>())); ApplicationContext.EnsureContext(appCtx, true); var umbCtx = UmbracoContext.EnsureContext( new Mock <HttpContextBase>().Object, appCtx, new Mock <WebSecurity>(null, null).Object, Mock.Of <IUmbracoSettingsSection>(), Enumerable.Empty <IUrlProvider>(), true); var ctrl = new TestSurfaceController(umbCtx); Assert.IsNotNull(ctrl.UmbracoContext); }
public void Can_Construct_And_Get_Result() { IHostingEnvironment hostingEnvironment = Mock.Of <IHostingEnvironment>(); IBackOfficeSecurityAccessor backofficeSecurityAccessor = Mock.Of <IBackOfficeSecurityAccessor>(); Mock.Get(backofficeSecurityAccessor).Setup(x => x.BackOfficeSecurity).Returns(Mock.Of <IBackOfficeSecurity>()); var globalSettings = new GlobalSettings(); var umbracoContextFactory = TestUmbracoContextFactory.Create(globalSettings, _umbracoContextAccessor); UmbracoContextReference umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext(); IUmbracoContext umbracoContext = umbracoContextReference.UmbracoContext; var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext); var ctrl = new TestSurfaceController(umbracoContextAccessor, Mock.Of <IPublishedContentQuery>(), Mock.Of <IPublishedUrlProvider>()); IActionResult result = ctrl.Index(); Assert.IsNotNull(result); }
public void Mock_Current_Page() { var globalSettings = new GlobalSettings(); IHostingEnvironment hostingEnvironment = Mock.Of <IHostingEnvironment>(); IBackOfficeSecurityAccessor backofficeSecurityAccessor = Mock.Of <IBackOfficeSecurityAccessor>(); Mock.Get(backofficeSecurityAccessor).Setup(x => x.BackOfficeSecurity).Returns(Mock.Of <IBackOfficeSecurity>()); var umbracoContextFactory = TestUmbracoContextFactory.Create(globalSettings, _umbracoContextAccessor); UmbracoContextReference umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext(); IUmbracoContext umbracoContext = umbracoContextReference.UmbracoContext; var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext); IPublishedContent content = Mock.Of <IPublishedContent>(publishedContent => publishedContent.Id == 12345); var builder = new PublishedRequestBuilder(umbracoContext.CleanedUmbracoUrl, Mock.Of <IFileService>()); builder.SetPublishedContent(content); IPublishedRequest publishedRequest = builder.Build(); var routeDefinition = new UmbracoRouteValues(publishedRequest, null); var httpContext = new DefaultHttpContext(); httpContext.Features.Set(routeDefinition); var ctrl = new TestSurfaceController(umbracoContextAccessor, Mock.Of <IPublishedContentQuery>(), Mock.Of <IPublishedUrlProvider>()) { ControllerContext = new ControllerContext() { HttpContext = httpContext, RouteData = new RouteData() } }; var result = ctrl.GetContentFromCurrentPage() as PublishedContentResult; Assert.AreEqual(12345, result.Content.Id); }