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 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 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); }