コード例 #1
0
        public void Categories_VerifyAllTaxaIsRetrieved()
        {
            var model = new HierarchicalTaxonomyModel();
            model.TaxaToDisplay = HierarchicalTaxaToDisplay.All;
            model.ShowEmptyTaxa = true;

            var viewModel = model.CreateViewModel();

            Assert.AreEqual(this.taxaNamesWithParents.Count, viewModel.Taxa.Count);

            for (int i = 0; i < viewModel.Taxa.Count; i++)
            {
                string parentName;
                string taxonName;
                this.GetTaxonNameAndParentName(this.taxaNamesWithParents[i], out parentName, out taxonName);

                var actual = viewModel.Taxa[i];

                Assert.AreEqual(taxonName, actual.Title);
            }
        }
コード例 #2
0
        public void Categories_VerifyEmptyTaxaIsNotRetrieved()
        {
            var model = new HierarchicalTaxonomyModel();
            model.TaxaToDisplay = HierarchicalTaxaToDisplay.All;

            var viewModel = model.CreateViewModel();

            var expectedFilteredTaxa = new List<string>() { "c1", "c3", "c3|c3c2c1" };

            Assert.AreEqual(expectedFilteredTaxa.Count, viewModel.Taxa.Count);

            for (var i = 0; i < expectedFilteredTaxa.Count; i++)
            {
                var actual = viewModel.Taxa[i];

                var expectedTaxon = expectedFilteredTaxa[i];

                string taxonParentName;
                string taxonName;
                this.GetTaxonNameAndParentName(expectedTaxon, out taxonParentName, out taxonName);

                Assert.AreEqual(taxonName, actual.Title);
            }
        }
コード例 #3
0
        public void Categories_VerifyHierarchicalTaxaFilteredByContentTypeIsRetrieved()
        {
            var model = new HierarchicalTaxonomyModel();
            model.TaxaToDisplay = HierarchicalTaxaToDisplay.UsedByContentType;
            model.ContentTypeName = typeof(NewsItem).FullName;
            model.FlattenHierarchy = false;

            var viewModel = model.CreateViewModel();

            var expectedTaxaTree = this.GetExpectedTaxaTree(new List<string>() { "c1", "c3", "c3|c3c2c1" });

            foreach (var taxon in expectedTaxaTree)
            {
                this.AssertTaxonIsInPlace(viewModel.Taxa, taxon);
            }
        }
コード例 #4
0
        public void Categories_VerifyTopLevelTaxaIsRetrieved()
        {
            var model = new HierarchicalTaxonomyModel();
            model.TaxaToDisplay = HierarchicalTaxaToDisplay.TopLevel;
            model.ShowEmptyTaxa = true;

            var viewModel = model.CreateViewModel();

            var topLevelNames = this.taxaNamesWithParents.Where(tn => !tn.Contains('|')).ToList();

            Assert.AreEqual(topLevelNames.Count, viewModel.Taxa.Count);

            for (int i = 0; i < viewModel.Taxa.Count; i++)
            {
                var expected = topLevelNames[i];
                var actual = viewModel.Taxa[i];

                Assert.AreEqual(expected, actual.Title);
            }
        }
コード例 #5
0
        public void Categories_VerifyTaxaUnderParticularParentIsRetrieved()
        {
            var model = new HierarchicalTaxonomyModel();
            model.TaxaToDisplay = HierarchicalTaxaToDisplay.UnderParticularTaxon;
            model.ShowEmptyTaxa = true;

            var rootTaxon = TaxonomyManager.GetManager().GetTaxa<HierarchicalTaxon>().FirstOrDefault(t => t.Title == "c3");
            model.RootTaxonId = rootTaxon.Id;

            var viewModel = model.CreateViewModel();

            var innerLevelNames = this.taxaNamesWithParents
                .Where(tn => tn.Contains("c3|"))
                .Select(tn => tn.Split('|')[1])
                .ToList();

            Assert.AreEqual(innerLevelNames.Count, viewModel.Taxa.Count);

            for (int i = 0; i < viewModel.Taxa.Count; i++)
            {
                var expected = innerLevelNames[i];
                var actual = viewModel.Taxa[i];

                Assert.AreEqual(expected, actual.Title);
            }
        }
コード例 #6
0
        public void Categories_VerifyTaxaFromContentItemIsRetrieved()
        {
            var item = NewsManager.GetManager().GetNewsItems().FirstOrDefault();

            var model = new HierarchicalTaxonomyModel();
            model.ContentId = item.Id;

            var viewModel = model.CreateViewModel();

            var itemTaxa = (IList<Guid>)item.GetValue("Category");

            Assert.AreEqual(itemTaxa.Count, viewModel.Taxa.Count);

            var taxonomyManager = TaxonomyManager.GetManager();
            for (var i = 0; i < itemTaxa.Count; i++)
            {
                var taxon = taxonomyManager.GetTaxa<HierarchicalTaxon>().FirstOrDefault(t => t.Id == itemTaxa[i]);
                Assert.AreEqual(taxon.Title.ToString(), viewModel.Taxa[i].Title);
            }
        }
コード例 #7
0
        public void Categories_VerifySpecificTaxaIsRetrieved()
        {
            var model = new HierarchicalTaxonomyModel();
            model.TaxaToDisplay = HierarchicalTaxaToDisplay.Selected;
            model.ShowEmptyTaxa = true;

            var selectedTaxaIds = TaxonomyManager.GetManager()
                .GetTaxa<HierarchicalTaxon>()
                .Where(t => this.taxaNamesWithParents[1] == t.Title.ToString() || this.taxaNamesWithParents[2] == t.Title.ToString())
                .Select(t => t.Id);

            var serializer = new JavaScriptSerializer();
            model.SerializedSelectedTaxaIds = serializer.Serialize(selectedTaxaIds);

            var viewModel = model.CreateViewModel();

            Assert.AreEqual(2, viewModel.Taxa.Count);

            for (int i = 0; i < viewModel.Taxa.Count; i++)
            {
                var expected = this.taxaNamesWithParents[i + 1];
                var actual = viewModel.Taxa[i];

                Assert.AreEqual(expected, actual.Title);
            }
        }
コード例 #8
0
        public void Categories_VerifyHierarchicalTaxaIsRetrieved()
        {
            var model = new HierarchicalTaxonomyModel();
            model.TaxaToDisplay = HierarchicalTaxaToDisplay.TopLevel;
            model.ShowEmptyTaxa = true;
            model.FlattenHierarchy = false;

            var viewModel = model.CreateViewModel();

            var expectedTaxaTree = this.GetExpectedTaxaTree(this.taxaNamesWithParents);

            foreach (var taxon in expectedTaxaTree)
            {
                this.AssertTaxonIsInPlace(viewModel.Taxa, taxon);
            }
        }