public void EngineHasPropertyTest()
        {
            string propertyName = "testProp";
            var    content      = _unitTestEngine.WithPublishedContentPage(contentType: _unitTestEngine.WithPublishedContentType(propertyTypes: new[] { UmbracoUnitTestHelper.GetPropertyType(alias: propertyName) }));

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

            _unitTestEngine.RegisterController(controller);
            var res   = controller.BasicHasPropertyAction(content.Id, propertyName);
            var model = (bool)res.Model;

            Assert.IsTrue(model);
        }
        public void HelperHasPropertyTest()
        {
            //Uses our special service context object (it mocks all services!!)
            var mockServiceContext = new MockServiceContext();

            var appCtx = UmbracoUnitTestHelper.GetApplicationContext(serviceContext: mockServiceContext.ServiceContext);
            var ctx    = UmbracoUnitTestHelper.GetUmbracoContext(appCtx);

            UmbracoUnitTestHelper.StartCoreBootManager(UmbracoUnitTestHelper.GetCustomBootManager(serviceContext: mockServiceContext.ServiceContext));

            string propertyName = "testProp";

            //THIS TIME we do need a property type defined.... this is more complicated...
            UmbracoUnitTestHelper.SetupServicesForPublishedContentTypeResolution(mockServiceContext, new[] { UmbracoUnitTestHelper.GetPropertyType(alias: propertyName) });

            var contentId = 2;
            //get a mocked IPublishedContent
            var contentType = UmbracoUnitTestHelper.GetPublishedContentType();
            var contentMock = UmbracoUnitTestHelper.GetPublishedContentMock(contentType: 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 = UmbracoUnitTestHelper.GetUmbracoHelper(ctx, typedQuery: mockedTypedQuery.Object);

            var controller = new BasicTestSurfaceController(ctx, helper);
            var res        = controller.BasicHasPropertyAction(contentId, propertyName);
            var model      = (bool)res.Model;

            Assert.IsTrue(model);

            //clean up resolved so we can use this again...
            UmbracoUnitTestHelper.CleanupCoreBootManager(appCtx);
        }
Ejemplo n.º 3
0
        public void BasicHasPropertyTest()
        {
            //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
            //core boot manager requires Services.TextService to not be null (pass in mock of ILocalizedTextService)
            var serviceContext = new ServiceContext(contentTypeService: mockContentService.Object, localizedTextService: Mock.Of <ILocalizedTextService>());

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

            //Have to use an inherited instance of boot manager to remove methods we can't use
            var bm = new CustomBoot(new UmbracoApplication(), serviceContext);

            bm.Initialize().Startup(null).Complete(null);

            string ctAlias      = "testAlias";
            string propertyName = "testProp";

            //THIS TIME we do need a property type defined.... this is more complicated...
            var mockContentType = new Mock <IContentType>();

            mockContentType.Setup(s => s.Alias).Returns(ctAlias);
            mockContentType.Setup(s => s.CompositionPropertyTypes).Returns(new PropertyType[] { new PropertyType(propertyName, DataTypeDatabaseType.Nvarchar, propertyName) });

            mockContentService.Setup(s => s.GetContentType(ctAlias)).Returns(mockContentType.Object);

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

            var contentId = 2;
            //get a mocked IPublishedContent
            var contentMock = new Mock <IPublishedContent>();

            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.BasicHasPropertyAction(contentId, propertyName);
            var model      = (bool)res.Model;

            Assert.IsTrue(model);

            //clean up resolved so we can use this again...
            appCtx.DisposeIfDisposable();
        }