Beispiel #1
0
        public void BasicPublishedContent2Test()
        {
            var appCtx = ApplicationContext.EnsureContext(
                new DatabaseContext(Mock.Of <IDatabaseFactory>(), Mock.Of <ILogger>(), new SqlSyntaxProviders(new[] { Mock.Of <ISqlSyntaxProvider>() })),
                new 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);

            //instead of using the implemenation of IPublishedContent, we mock IPublishedContent
            var mockContent = new Mock <IPublishedContent>();

            //We need to manually setup each field that is needed
            mockContent.Setup(s => s.Name).Returns("test");
            //give our content to the umbraco helper which will be given to the controller
            var helper = new UmbracoHelper(ctx, mockContent.Object);

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

            Assert.IsNotNull(mockContent.Object.Name, model);
        }
Beispiel #2
0
        public void BasicPublishedContent1Test()
        {
            var appCtx = ApplicationContext.EnsureContext(
                new DatabaseContext(Mock.Of <IDatabaseFactory>(), Mock.Of <ILogger>(), new SqlSyntaxProviders(new[] { Mock.Of <ISqlSyntaxProvider>() })),
                new 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 test_name = "test";

            //create an instance of our test implemention of IPublisheContent
            var content = new TestPublishedContent()
            {
                Name = test_name
            };
            //setup a helper object which will be given to the surface controller
            var helper = new UmbracoHelper(ctx, content);
            //we use a surface controller that takes in th context and helper so that we can setup them for our needs
            var controller = new BasicTestSurfaceController(ctx, helper);
            var res        = controller.BasicPublishedContentAction();
            var model      = res.Model as string;

            Assert.AreEqual(test_name, model);
        }
        public void EnginePublishedContent1Test()
        {
            var content = _unitTestEngine.WithCurrentPage("Test");
            //Setup UmbracoContext with mocks. Sets UmbracoContext.Current
            var controller = new BasicTestSurfaceController(_unitTestEngine.UmbracoContext, _unitTestEngine.UmbracoHelper);
            var res        = controller.BasicPublishedContentAction();
            var model      = res.Model as string;

            Assert.AreEqual(content.Name, model);
        }
        public void HelperPublishedContent2Test()
        {
            //Setup UmbracoContext with mocks. Sets UmbracoContext.Current
            var ctx = UmbracoUnitTestHelper.GetUmbracoContext();
            //instead of using the implemenation of IPublishedContent, we mock IPublishedContent
            var mockContent = UmbracoUnitTestHelper.GetPublishedContentMock(name: "test").Object;
            //give our content to the umbraco helper which will be given to the controller
            var helper = UmbracoUnitTestHelper.GetUmbracoHelper(ctx, content: mockContent);

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

            Assert.IsNotNull(mockContent.Name, model);
        }
        public void HelperPublishedContent1Test()
        {
            //Setup UmbracoContext with mocks. Sets UmbracoContext.Current
            var ctx = UmbracoUnitTestHelper.GetUmbracoContext();
            //create an instance of our test implemention of IPublisheContent
            var content = new TestPublishedContent()
            {
                Name = "test"
            };
            //setup a helper object which will be given to the surface controller
            var helper = UmbracoUnitTestHelper.GetUmbracoHelper(context: ctx, content: content);
            //we use a surface controller that takes in th context and helper so that we can setup them for our needs
            var controller = new BasicTestSurfaceController(ctx, helper);
            var res        = controller.BasicPublishedContentAction();
            var model      = res.Model as string;

            Assert.AreEqual(content.Name, model);
        }