public void Find_CohortAggregateContainer_ByFreeText(bool userSetting)
        {
            var container = WhenIHaveA <CohortAggregateContainer>();

            container.Name = "All the trolls in the troll kingdom";

            UserSettings.ScoreZeroForCohortAggregateContainers = userSetting;

            var scorer = new SearchablesMatchScorer();

            scorer.TypeNames.Add("CohortAggregateContainer");

            var childProvider = new DataExportChildProvider(RepositoryLocator, null, new ThrowImmediatelyCheckNotifier(), null);

            // user is searching for the text 'troll'
            var scores = scorer.ScoreMatches(childProvider.GetAllSearchables(), "troll", CancellationToken.None, new List <Type>());

            var score = scores.Single(d => Equals(d.Key.Key, container));

            if (userSetting)
            {
                // although the text appears in the search they are not doing it by exact type name and their settings
                // mean they don't want to see these objects by default.
                Assert.AreEqual(0, score.Value);
            }
            else
            {
                Assert.Greater(score.Value, 0);
            }
        }
        private void TestScoringFlag(Action <Catalogue, ExtractableDataSet> setter, bool expectedResult)
        {
            // Filter is hungry and eager to please.  If you want to see ProjectSpecific Catalogues then
            // that it will show you them regardless of other settings.  Likewise clicking Deprecated shows
            // all deprecated catalogues regardless of other settings.
            //
            // So set all to false to except the condition we are testing
            UserSettings.ShowDeprecatedCatalogues      = false;
            UserSettings.ShowNonExtractableCatalogues  = false;
            UserSettings.ShowProjectSpecificCatalogues = false;
            UserSettings.ShowInternalCatalogues        = false;
            UserSettings.ShowColdStorageCatalogues     = false;

            var c = WhenIHaveA <Catalogue>();

            c.Name = "Bunny";
            c.SaveToDatabase();

            // this makes c extractable (the usual case for Catalogues)
            var eds = new ExtractableDataSet(Repository, c);

            eds.SaveToDatabase();

            setter(c, eds);
            c.SaveToDatabase();


            var scorer = new SearchablesMatchScorer()
            {
                RespectUserSettings = true
            };

            var childProvider = new DataExportChildProvider(RepositoryLocator, null, new ThrowImmediatelyCheckNotifier(), null);

            // user is searching for the text 'troll'
            var scores = scorer.ScoreMatches(childProvider.GetAllSearchables(), "Bunny", CancellationToken.None, new List <Type>());

            var score = scores.Single(d => Equals(d.Key.Key, c));

            if (expectedResult)
            {
                Assert.Greater(score.Value, 0);
            }
            else
            {
                // score 0 and don't be included in results
                Assert.AreEqual(0, score.Value);
            }

            // Cleanup test
            foreach (var d in Repository.GetAllObjects <ExtractableDataSet>())
            {
                d.DeleteInDatabase();
            }
            foreach (var cat in Repository.GetAllObjects <Catalogue>())
            {
                cat.DeleteInDatabase();
            }
        }
        public void Find_CohortAggregateContainer_ByTypeName(bool userSetting)
        {
            var container = WhenIHaveA <CohortAggregateContainer>();

            UserSettings.ScoreZeroForCohortAggregateContainers = userSetting;

            var scorer = new SearchablesMatchScorer();

            scorer.TypeNames.Add("CohortAggregateContainer");

            var childProvider = new DataExportChildProvider(RepositoryLocator, null, new ThrowImmediatelyCheckNotifier(), null);

            var scores = scorer.ScoreMatches(childProvider.GetAllSearchables(), "", CancellationToken.None, new List <Type>()
            {
                typeof(CohortAggregateContainer)
            });

            var score = scores.Single(d => Equals(d.Key.Key, container));

            Assert.Greater(score.Value, 0);
        }
        public void Find_ExactMatch_ScoresHigher()
        {
            var cata = WhenIHaveA <Catalogue>();

            cata.Name = "FF";
            var proj = WhenIHaveA <Project>();

            proj.Name = "FFFF";

            var scorer = new SearchablesMatchScorer();

            var childProvider = new DataExportChildProvider(RepositoryLocator, null, new ThrowImmediatelyCheckNotifier(), null);
            var scores        = scorer.ScoreMatches(childProvider.GetAllSearchables(), "FF", CancellationToken.None, new List <Type>());

            var cataScore = scores.Single(d => Equals(d.Key.Key, cata));
            var projScore = scores.Single(d => Equals(d.Key.Key, proj));

            // Both score because they have the text FF
            Assert.Greater(cataScore.Value, 0);
            Assert.Greater(projScore.Value, 0);

            // Catalogue scores higher because it is an exact match to the name
            Assert.Greater(cataScore.Value, projScore.Value);
        }