public void HelperContentTypeTest()
        {
            var mocks = new MockServiceContext();

            var appCtx = UmbracoUnitTestHelper.GetApplicationContext(serviceContext: mocks.ServiceContext);

            var ctx = UmbracoUnitTestHelper.GetUmbracoContext(appCtx);

            //pass in emtpy proprty types to avoid uninitialized resolver issue. To bypass, must use CoreBootManager
            UmbracoUnitTestHelper.SetupServicesForPublishedContentTypeResolution(mocks, new PropertyType[] { });

            var alias       = "test_alias";
            var contentType = UmbracoUnitTestHelper.GetPublishedContentType(alias: alias);

            var contentId = 2;
            //get a mocked IPublishedContent
            var contentMock = UmbracoUnitTestHelper.GetPublishedContentMock(contentType: contentType);

            var mockedTypedQuery = new Mock <ITypedPublishedContentQuery>();

            mockedTypedQuery.Setup(s => s.TypedContent(It.IsAny <int>())).Returns(contentMock.Object);

            //give our dynamic query mock to the longer version of the UmbracoHelper constructor
            var helper = UmbracoUnitTestHelper.GetUmbracoHelper(ctx, typedQuery: mockedTypedQuery.Object);

            var controller = new BasicTestSurfaceController(ctx, helper);
            var res        = controller.BasicContentTypeAction(contentId);
            var model      = (string)res.Model;

            Assert.AreEqual(alias, model);
        }
        public void EngineContentTypeTest()
        {
            var content = _unitTestEngine.WithPublishedContentPage(contentType: _unitTestEngine.WithPublishedContentType());

            var controller = new BasicTestSurfaceController(_unitTestEngine.UmbracoContext, _unitTestEngine.UmbracoHelper);

            _unitTestEngine.RegisterController(controller);
            var res   = controller.BasicContentTypeAction(content.Id);
            var model = (string)res.Model;

            Assert.AreEqual(content.ContentType.Alias, model);
        }
Ejemplo n.º 3
0
        public void BasicContentTypeTest()
        {
            //create a mock of the content type service
            var mockContentService = new Mock <IContentTypeService>();
            //this time we will make our own service context, which can take in all of the umbraco services
            //Pass the context the mocked content service object
            var serviceContext = new ServiceContext(contentTypeService: mockContentService.Object);

            var appCtx = ApplicationContext.EnsureContext(
                new DatabaseContext(Mock.Of <IDatabaseFactory>(), Mock.Of <ILogger>(), new SqlSyntaxProviders(new[] { Mock.Of <ISqlSyntaxProvider>() })),
                serviceContext,
                CacheHelper.CreateDisabledCacheHelper(),
                new ProfilingLogger(
                    Mock.Of <ILogger>(),
                    Mock.Of <IProfiler>()), true);

            var ctx = UmbracoContext.EnsureContext(
                Mock.Of <HttpContextBase>(),
                appCtx,
                new Mock <WebSecurity>(null, null).Object,
                Mock.Of <IUmbracoSettingsSection>(),
                Enumerable.Empty <IUrlProvider>(), true);

            var alias = "test_alias";

            //we need to mock a content type composition with our alias
            var mockContentType = new Mock <IContentType>();

            mockContentType.Setup(s => s.Alias).Returns(alias);
            //we are not going to give any property types because this will cause an error down the line
            mockContentType.Setup(s => s.CompositionPropertyTypes).Returns(new PropertyType[] { });

            //PublishedContentType.Get will eventually request a content type from one of the data services (content, media, member)
            //In our case content
            //We tell it which content type object to return
            mockContentService.Setup(s => s.GetContentType(alias)).Returns(mockContentType.Object);

            var ContentType = PublishedContentType.Get(PublishedItemType.Content, alias);

            var contentId = 2;
            //get a mocked IPublishedContent
            var contentMock = BasicHelpers.GetPublishedContentMock();

            contentMock.Setup(s => s.ContentType).Returns(ContentType);

            var mockedTypedQuery = new Mock <ITypedPublishedContentQuery>();

            mockedTypedQuery.Setup(s => s.TypedContent(contentId)).Returns(contentMock.Object);

            //give our dynamic query mock to the longer version of the UmbracoHelper constructor
            var helper = new UmbracoHelper(ctx,
                                           Mock.Of <IPublishedContent>(),
                                           mockedTypedQuery.Object,
                                           Mock.Of <IDynamicPublishedContentQuery>(),
                                           Mock.Of <ITagQuery>(),
                                           Mock.Of <IDataTypeService>(),
                                           new UrlProvider(ctx, Mock.Of <IWebRoutingSection>(section => section.UrlProviderMode == UrlProviderMode.Auto.ToString()), new[] { Mock.Of <IUrlProvider>() }),
                                           Mock.Of <ICultureDictionary>(),
                                           Mock.Of <IUmbracoComponentRenderer>(),
                                           new MembershipHelper(ctx, Mock.Of <MembershipProvider>(), Mock.Of <RoleProvider>()));


            var controller = new BasicTestSurfaceController(ctx, helper);
            var res        = controller.BasicContentTypeAction(contentId);
            var model      = (string)res.Model;

            Assert.AreEqual(alias, model);
        }