コード例 #1
0
        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);
        }