Ejemplo n.º 1
0
        public static ServiceLocationMock ConfigureStructureMap()
        {
            ServiceLocationMock result = new ServiceLocationMock
            {
                ServiceLocatorMock = new Mock <IServiceLocator>(),
                StateAssesorMock   = new Mock <IPublishedStateAssessor>(),
                TemplateResolver   = GetTemplateResolver()
            };

            result.ServiceLocatorMock.Setup(m => m.GetInstance <IPublishedStateAssessor>()).Returns(result.StateAssesorMock.Object);
            result.ServiceLocatorMock.Setup(m => m.GetInstance <ITemplateResolver>()).Returns(result.TemplateResolver);
            result.ServiceLocatorMock.Setup(m => m.GetInstance <ContentAssetHelper>()).Returns(new Mock <ContentAssetHelper>().Object);

            ServiceLocator.SetLocator(result.ServiceLocatorMock.Object);
            return(result);
        }
Ejemplo n.º 2
0
        internal static ServiceLocationMock SetupServiceLocator()
        {
            var result = new ServiceLocationMock
            {
                ServiceLocatorMock         = new Mock <IServiceLocator>(),
                StateAssesorMock           = new Mock <IPublishedStateAssessor>(),
                ScheduledJobRepositoryMock = new Mock <IScheduledJobRepository>(),
                ScheduledJobExecutorMock   = new Mock <IScheduledJobExecutor>(),
                TemplateResolver           = GetTemplateResolver()
            };

            result.StateAssesorMock = new Mock <IPublishedStateAssessor>();
            result.StateAssesorMock
            .Setup(m => m.IsPublished(It.IsAny <IContent>(), It.IsAny <PublishedStateCondition>()))
            .Returns(true);

            var pathLinks = new[]
            {
                GetPageReference(),
                GetPageReference(),
                GetPageReference()
            };
            var dbExecMock = new Mock <IDatabaseExecutor>();

            dbExecMock
            .Setup(m => m.Execute(It.IsAny <Func <ContentPath> >()))
            .Returns(new ContentPath(pathLinks));

            var contentPathMock = new Mock <ContentPathDB>(dbExecMock.Object);
            var bestbetMock     = new Mock <IBestBetsRepository>();
            var boostMock       = new Mock <IBoostingRepository>();

            boostMock
            .Setup(m => m.GetByType(It.IsAny <Type>()))
            .Returns(new Dictionary <string, int>());

            var languageMock = new Mock <ILanguageBranchRepository>();

            languageMock.Setup(m => m.ListEnabled()).Returns(new List <LanguageBranch>
            {
                new LanguageBranch(new CultureInfo("en")),
                new LanguageBranch(new CultureInfo("no"))
            });
            result.LanguageBranchRepositoryMock = languageMock;

            var settings = new Mock <IElasticSearchSettings>();

            settings.Setup(m => m.BulkSize).Returns(1000);
            settings.Setup(m => m.CloseIndexDelay).Returns(2000);
            settings.Setup(m => m.EnableFileIndexing).Returns(true);
            settings.Setup(m => m.IgnoreXhtmlStringContentFragments).Returns(false);
            settings.Setup(m => m.Index).Returns(ElasticFixtureSettings.IndexName);
            settings.Setup(m => m.Indices).Returns(new[] { ElasticFixtureSettings.IndexNameWithoutLang });
            settings.Setup(m => m.GetLanguage(It.IsAny <string>())).Returns("no");
            settings.Setup(m => m.GetDefaultIndexName(It.IsAny <string>()))
            .Returns(ElasticFixtureSettings.IndexName);
            settings.Setup(m => m.Host).Returns("http://example.com");
            result.SettingsMock = settings;

            var httpClient = new Mock <IHttpClientHelper>();

            httpClient.Setup(m => m.Delete(It.IsAny <Uri>())).Returns(true);
            httpClient.Setup(m => m.Head(It.IsAny <Uri>())).Returns(HttpStatusCode.OK);

            result.HttpClientMock = httpClient;

            var serverInfo = new Mock <IServerInfoService>();

            serverInfo.Setup(m => m.GetInfo())
            .Returns(new ServerInfo
            {
                ElasticVersion = new ServerInfo.InternalVersion
                {
                    Number        = "6.0.0",
                    LuceneVersion = "7.0.1"
                }
            });

            result.ServerInfoMock = serverInfo;

            var synonymRepositoryMock = new Mock <ISynonymRepository>();

            synonymRepositoryMock
            .Setup(m => m.GetSynonyms(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(new List <Synonym>());
            result.SynonymRepositoryMock = synonymRepositoryMock;

            result.IndexerMock             = new Mock <IIndexer>();
            result.CoreIndexerMock         = new Mock <ICoreIndexer>();
            result.ContentLoaderMock       = new Mock <IContentLoader>();
            result.ContentIndexServiceMock = new Mock <IContentIndexService>();
            result.ServiceMock             = new Mock <IElasticSearchService <IContent> >();

            result.ServiceLocatorMock.Setup(m => m.GetInstance <IHttpClientHelper>()).Returns(httpClient.Object);
            result.ServiceLocatorMock.Setup(m => m.GetInstance <ILanguageBranchRepository>()).Returns(languageMock.Object);
            result.ServiceLocatorMock.Setup(m => m.GetInstance <IContentLoader>()).Returns(result.ContentLoaderMock.Object);
            result.ServiceLocatorMock.Setup(m => m.GetInstance <IIndexer>()).Returns(result.IndexerMock.Object);
            result.ServiceLocatorMock.Setup(m => m.GetInstance <ICoreIndexer>()).Returns(result.CoreIndexerMock.Object);
            result.ServiceLocatorMock.Setup(m => m.GetInstance <IContentVersionRepository>()).Returns(new Mock <IContentVersionRepository>().Object);
            result.ServiceLocatorMock.Setup(m => m.GetInstance <IBoostingRepository>()).Returns(boostMock.Object);
            result.ServiceLocatorMock.Setup(m => m.GetInstance <IBestBetsRepository>()).Returns(bestbetMock.Object);
            result.ServiceLocatorMock.Setup(m => m.GetInstance <IServerInfoService>()).Returns(serverInfo.Object);
            result.ServiceLocatorMock.Setup(m => m.GetInstance <IElasticSearchSettings>()).Returns(settings.Object);
            result.ServiceLocatorMock.Setup(m => m.GetInstance <IElasticSearchService>()).Returns(new ElasticSearchService(serverInfo.Object, settings.Object, httpClient.Object));
            result.ServiceLocatorMock.Setup(m => m.GetInstance <IPublishedStateAssessor>()).Returns(result.StateAssesorMock.Object);
            result.ServiceLocatorMock.Setup(m => m.GetInstance <ITemplateResolver>()).Returns(result.TemplateResolver);
            result.ServiceLocatorMock.Setup(m => m.GetInstance <ContentPathDB>()).Returns(contentPathMock.Object);
            result.ServiceLocatorMock.Setup(m => m.GetInstance <IScheduledJobRepository>()).Returns(result.ScheduledJobRepositoryMock.Object);
            result.ServiceLocatorMock.Setup(m => m.GetInstance <IScheduledJobExecutor>()).Returns(result.ScheduledJobExecutorMock.Object);
            result.ServiceLocatorMock.Setup(m => m.GetInstance <ContentAssetHelper>()).Returns(new Mock <ContentAssetHelper>().Object);

            ServiceLocator.SetLocator(result.ServiceLocatorMock.Object);
            return(result);
        }
Ejemplo n.º 3
0
        public static ServiceLocationMock SetupServiceLocator(string testHost = null, string username = null, string password = null)
        {
            ServiceLocationMock result = new ServiceLocationMock
            {
                ServiceLocatorMock = new Mock <IServiceLocator>(),
                StateAssesorMock   = new Mock <IPublishedStateAssessor>(),
                TemplateResolver   = GetTemplateResolver()
            };

            result.StateAssesorMock = new Mock <IPublishedStateAssessor>();
            result.StateAssesorMock
            .Setup(m => m.IsPublished(It.IsAny <IContent>(), It.IsAny <PublishedStateCondition>()))
            .Returns(true);

            Mock <ContentPathDB>       contentPathMock = new Mock <ContentPathDB>(new Mock <IDatabaseExecutor>().Object);
            Mock <IBestBetsRepository> bestbetMock     = new Mock <IBestBetsRepository>();
            Mock <IBoostingRepository> boostMock       = new Mock <IBoostingRepository>();

            boostMock
            .Setup(m => m.GetByType(It.IsAny <Type>()))
            .Returns(new Dictionary <string, int>());

            Mock <ILanguageBranchRepository> language = new Mock <ILanguageBranchRepository>();

            language.Setup(m => m.ListEnabled()).Returns(new List <LanguageBranch>
            {
                new LanguageBranch(new CultureInfo("no"))
            });


            Mock <IElasticSearchSettings> settings = new Mock <IElasticSearchSettings>();

            settings.Setup(m => m.BulkSize).Returns(1000);
            settings.Setup(m => m.CloseIndexDelay).Returns(2000);
            if (username != null)
            {
                settings.Setup(m => m.Username).Returns(username);
            }
            if (password != null)
            {
                settings.Setup(m => m.Password).Returns(password);
            }
            settings.Setup(m => m.EnableFileIndexing).Returns(true);
            settings.Setup(m => m.IgnoreXhtmlStringContentFragments).Returns(false);
            settings.Setup(m => m.Index).Returns(ElasticFixtureSettings.IndexName);
            settings.Setup(m => m.GetLanguage(It.IsAny <string>())).Returns("no");
            settings.Setup(m => m.GetDefaultIndexName(It.IsAny <string>()))
            .Returns(ElasticFixtureSettings.IndexName);
            if (testHost != null)
            {
                settings.Setup(m => m.Host).Returns(testHost.TrimEnd('/'));
            }

            Mock <IIndexer> indexer = new Mock <IIndexer>();

            result.ServiceLocatorMock.Setup(m => m.GetInstance <IIndexer>()).Returns(indexer.Object);
            result.ServiceLocatorMock.Setup(m => m.GetInstance <IBoostingRepository>()).Returns(boostMock.Object);
            result.ServiceLocatorMock.Setup(m => m.GetInstance <IBestBetsRepository>()).Returns(bestbetMock.Object);
            result.ServiceLocatorMock.Setup(m => m.GetInstance <IElasticSearchSettings>()).Returns(settings.Object);
            result.ServiceLocatorMock.Setup(m => m.GetInstance <ILanguageBranchRepository>()).Returns(language.Object);
            //result.ServiceLocatorMock.Setup(m => m.GetInstance<IContentAccessEvaluator>()).Returns(new Mock<IContentAccessEvaluator>().Object);
            //result.ServiceLocatorMock.Setup(m => m.GetInstance<IPrincipalAccessor>()).Returns(new Mock<IPrincipalAccessor>().Object);
            result.ServiceLocatorMock.Setup(m => m.GetInstance <IElasticSearchService>()).Returns(new ElasticSearchService(settings.Object));

            result.ServiceLocatorMock.Setup(m => m.GetInstance <IPublishedStateAssessor>()).Returns(result.StateAssesorMock.Object);
            result.ServiceLocatorMock.Setup(m => m.GetInstance <ITemplateResolver>()).Returns(result.TemplateResolver);
            result.ServiceLocatorMock.Setup(m => m.GetInstance <ContentPathDB>()).Returns(contentPathMock.Object);
            result.ServiceLocatorMock.Setup(m => m.GetInstance <ContentAssetHelper>()).Returns(new Mock <ContentAssetHelper>().Object);

            ServiceLocator.SetLocator(result.ServiceLocatorMock.Object);
            return(result);
        }