コード例 #1
0
        public void BasicTypedSearchActionTest()
        {
            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 searchTerm = "test";

            //Create some content to be returned by search
            var searchItems = new IPublishedContent[] { BasicHelpers.GetPublishedContent(), BasicHelpers.GetPublishedContent() };

            //mock the search call of the typed query
            var mockedTypedQuery = new Mock <ITypedPublishedContentQuery>();

            mockedTypedQuery.Setup(s => s.TypedSearch(searchTerm, true, null)).Returns(searchItems);

            //give our typed 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.BasicTypedSearchAction(searchTerm);
            var model      = (int)res.Model;

            Assert.AreEqual(searchItems.Count(), model);
        }
コード例 #2
0
        public void HelperTypedSearchActionTest()
        {
            var ctx = UmbracoUnitTestHelper.GetUmbracoContext();

            var searchTerm = "test";

            //Create some content to be returned by search
            var searchItems = new IPublishedContent[] { BasicHelpers.GetPublishedContent(), BasicHelpers.GetPublishedContent() };

            //mock the search call of the typed query
            var mockedTypedQuery = new Mock <ITypedPublishedContentQuery>();

            mockedTypedQuery.Setup(s => s.TypedSearch(searchTerm, true, null)).Returns(searchItems);

            //give our typed 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.BasicTypedSearchAction(searchTerm);
            var model      = (int)res.Model;

            Assert.AreEqual(searchItems.Count(), model);
        }