public void NewsWidget_OnBootstrapPageTemplate()
        {
            string templateName = "Bootstrap.defaultNew3";
            string placeHolder = "Contentplaceholder1";
            string url = UrlPath.ResolveAbsoluteUrl("~/" + UrlNamePrefix);
            Guid templateId = default(Guid);

            try
            {
                var mvcProxy = new MvcControllerProxy();
                mvcProxy.ControllerName = typeof(NewsController).FullName;
                var newsController = new NewsController();
                mvcProxy.Settings = new ControllerSettings(newsController);

                templateId = this.templateOperation.DuplicatePageTemplate(OldTemplateName, templateName);

                this.templateOperation.AddControlToTemplate(templateId, mvcProxy, placeHolder, CaptionNews);
                Guid pageId = this.locationGenerator.CreatePage(PageNamePrefix, PageTitlePrefix, UrlNamePrefix, null, null);
                Telerik.Sitefinity.TestUtilities.CommonOperations.ServerOperations.Templates().SetTemplateToPage(pageId, templateId);
                Telerik.Sitefinity.TestUtilities.CommonOperations.ServerOperations.News().CreateNewsItem(NewsTitle);

                string responseContent = PageInvoker.ExecuteWebRequest(url);

                Assert.IsTrue(responseContent.Contains(NewsTitle), "The news with this title was not found!");
            }
            finally
            {
                Telerik.Sitefinity.TestUtilities.CommonOperations.ServerOperations.Pages().DeleteAllPages();
                Telerik.Sitefinity.TestUtilities.CommonOperations.ServerOperations.Templates().DeletePageTemplate(templateId);
            }
        }
        public void NewsWidget_SelectListTemplate()
        {
            string testName = System.Reflection.MethodInfo.GetCurrentMethod().Name;
            string pageNamePrefix = testName + "NewsPage";
            string pageTitlePrefix = testName + "News Page";
            string urlNamePrefix = testName + "news-page";
            int pageIndex = 1;
            string textEdited = "<p> Test paragraph </p>";
            string paragraphText = "Test paragraph";
            string url = UrlPath.ResolveAbsoluteUrl("~/" + urlNamePrefix + pageIndex);

            string listTemplate = "NewsListNew";
            var listTemplatePath = Path.Combine(this.templateOperation.SfPath, "ResourcePackages", "Bootstrap", "MVC", "Views", "News", "List.NewsList.cshtml");
            var newListTemplatePath = Path.Combine(this.templateOperation.SfPath, "MVC", "Views", "Shared", "List.NewsListNew.cshtml");

            try
            {
                File.Copy(listTemplatePath, newListTemplatePath);

                using (StreamWriter output = File.AppendText(newListTemplatePath))
                {
                    output.WriteLine(textEdited);
                }

                var mvcProxy = new MvcControllerProxy();
                mvcProxy.ControllerName = typeof(NewsController).FullName;
                var newsController = new NewsController();
                newsController.ListTemplateName = listTemplate;
                mvcProxy.Settings = new ControllerSettings(newsController);

                Telerik.Sitefinity.TestUtilities.CommonOperations.ServerOperations.News().CreateNewsItem(NewsTitle);

                this.pageOperations.CreatePageWithControl(mvcProxy, pageNamePrefix, pageTitlePrefix, urlNamePrefix, pageIndex);

                string responseContent = PageInvoker.ExecuteWebRequest(url);

                Assert.IsTrue(responseContent.Contains(paragraphText), "The news with this template was not found!");
            }
            finally
            {
                Telerik.Sitefinity.TestUtilities.CommonOperations.ServerOperations.Pages().DeleteAllPages();
                File.Delete(newListTemplatePath);
            }
        }
        public void NewsWidget_SelectDetailTemplate()
        {
            string testName = System.Reflection.MethodInfo.GetCurrentMethod().Name;
            string pageNamePrefix = testName + "NewsPage";
            string pageTitlePrefix = testName + "News Page";
            string urlNamePrefix = testName + "news-page";
            int pageIndex = 1;
            string textEdited = "<p> Test paragraph </p>";
            string paragraphText = "Test paragraph";
            var newsManager = NewsManager.GetManager();
            string url = UrlPath.ResolveAbsoluteUrl("~/" + urlNamePrefix + pageIndex);

            string detailTemplate = "DetailPageNew";
            var detailTemplatePath = Path.Combine(this.templateOperation.SfPath, "ResourcePackages", "Bootstrap", "MVC", "Views", "News", "Detail.DetailPage.cshtml");
            var newDetailTemplatePath = Path.Combine(this.templateOperation.SfPath, "MVC", "Views", "Shared", "Detail.DetailPageNew.cshtml");

            try
            {
                File.Copy(detailTemplatePath, newDetailTemplatePath);
                this.EditFile(newDetailTemplatePath, textEdited);

                var mvcProxy = new MvcControllerProxy();
                mvcProxy.ControllerName = typeof(NewsController).FullName;
                var newsController = new NewsController();
                newsController.DetailTemplateName = detailTemplate;
                mvcProxy.Settings = new ControllerSettings(newsController);

                this.pageOperations.CreatePageWithControl(mvcProxy, pageNamePrefix, pageTitlePrefix, urlNamePrefix, pageIndex);

                NewsItem newsItem = newsManager.GetNewsItems().Where<NewsItem>(ni => ni.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Master && ni.Title == NewsTitleDetail).FirstOrDefault();
                string detailNewsUrl = url + newsItem.ItemDefaultUrl;

                string responseContent = PageInvoker.ExecuteWebRequest(detailNewsUrl);

                Assert.IsTrue(responseContent.Contains(NewsTitleDetail), "The news with this title was not found!");
                Assert.IsTrue(responseContent.Contains(paragraphText), "The news with this template was not found!");
            }
            finally
            {
                File.Delete(newDetailTemplatePath);
            }
        }
        public void SearchResultsWidget_DefaultLanguage_Limit_OldestOrder()
        {
            Guid searchIndex1Id = Guid.Empty;

            try
            {
                searchIndex1Id = SitefinityOperations.ServerOperations.Search().CreateSearchIndex(SearchResultsWidgetTests.SearchIndexName, new[] { SitefinityOperations.SearchContentType.Pages, SitefinityOperations.SearchContentType.News });
                SitefinityOperations.ServerOperations.Search().Reindex(searchIndex1Id);

                int index = 1;
                string testName = System.Reflection.MethodInfo.GetCurrentMethod().Name;
                string pageNamePrefix = testName + "NewsPage" + index;
                string pageTitlePrefix = testName + "NewsPage" + index;
                string urlNamePrefix = testName + "news-page" + index;

                string orderBy = "Oldest";
                var searchResultsController = new SearchResultsController();
                searchResultsController.Model.DisplayMode = Telerik.Sitefinity.Frontend.Search.Mvc.Models.ListDisplayMode.Limit;
                searchResultsController.Model.ItemsPerPage = 2;
                int expectedResultsCount = 2;

                var mvcProxy = new MvcControllerProxy();
                mvcProxy.ControllerName = typeof(NewsController).FullName;
                var newsController = new NewsController();
                mvcProxy.Settings = new ControllerSettings(newsController);

                this.pageOperations.CreatePageWithControl(mvcProxy, pageNamePrefix, pageTitlePrefix, urlNamePrefix, index);

                searchResultsController.Index(null, SearchResultsWidgetTests.NewsTitle, SearchResultsWidgetTests.SearchIndexName, null, null, orderBy);

                //// ignored because total count of returned results is 5 instead of 2
                Assert.AreEqual(expectedResultsCount, searchResultsController.Model.Results.TotalCount);
                Assert.AreEqual(SearchResultsWidgetTests.NewsTitle + "1", searchResultsController.Model.Results.Data[0].GetValue("Title"));
                Assert.AreEqual(SearchResultsWidgetTests.NewsTitle + "2", searchResultsController.Model.Results.Data[1].GetValue("Title"));
            }
            finally
            {
                Telerik.Sitefinity.TestUtilities.CommonOperations.ServerOperations.Search().DeleteAllIndexes();
            }
        }
        public void NewsWidget_SelectByCategoryAndTagNewsFunctionality()
        {
            string newsTitle = "News ";
            string tagTitle = "Tag1";
            string categoryTitle = "Category1";

            var newsController = new NewsController();

            try
            {
                Guid tagId = this.serverOperationsTaxonomies.CreateFlatTaxon(Telerik.Sitefinity.TestUtilities.CommonOperations.TaxonomiesConstants.TagsTaxonomyId, tagTitle);

                this.serverOperationsTaxonomies.CreateCategory(categoryTitle);
                Guid categoryId = TaxonomyManager.GetManager().GetTaxa<HierarchicalTaxon>().SingleOrDefault(t => t.Title == categoryTitle).Id;

                ServerOperationsFeather.NewsOperations().CreatePublishedNewsItem(newsTitle + 0, "Content", "AuthorName", "SourceName", null, new List<string> { tagTitle }, null);
                ServerOperationsFeather.NewsOperations().CreatePublishedNewsItem(newsTitle + 1, "Content", "AuthorName", "SourceName", new List<string> { categoryTitle }, new List<string> { tagTitle }, null);
                ServerOperationsFeather.NewsOperations().CreatePublishedNewsItem(newsTitle + 2, "Content", "AuthorName", "SourceName", new List<string> { categoryTitle }, null, null);

                newsController.Model.SelectionMode = SelectionMode.FilteredItems;
                newsController.Model.SerializedAdditionalFilters = "{\"__msdisposeindex\":205,\"Title\":null,\"Id\":\"00000000-0000-0000-0000-000000000000\"," +
                                                                   "\"QueryItems\":[{\"IsGroup\":true,\"Ordinal\":0,\"Join\":\"AND\",\"ItemPath\":\"_0\",\"Value\":null,\"Condition\":null," +
                                                                   "\"Name\":\"Category\",\"_itemPathSeparator\":\"_\",\"__msdisposeindex\":206},{\"IsGroup\":false,\"Ordinal\":0,\"Join\":\"OR\",\"ItemPath\":\"_0_0\",\"Value\":" + categoryId + ",\"Condition\":" +
                                                                   "{\"FieldName\":\"Category\",\"FieldType\":\"System.Guid\",\"Operator\":\"Contains\",\"__msdisposeindex\":207},\"Name\":" + categoryTitle + ",\"_itemPathSeparator\":\"_\",\"__msdisposeindex\":208}," +
                                                                   "{\"IsGroup\":true,\"Ordinal\":1,\"Join\":\"AND\",\"ItemPath\":\"_1\",\"Value\":null,\"Condition\":null," +
                                                                   "\"Name\":\"Tags\",\"_itemPathSeparator\":\"_\",\"__msdisposeindex\":209},{\"IsGroup\":false,\"Ordinal\":0,\"Join\":\"OR\",\"ItemPath\":\"_1_0\",\"Value\":" + tagId + ",\"Condition\":" +
                                                                   "{\"FieldName\":\"Tags\",\"FieldType\":\"System.Guid\",\"Operator\":\"Contains\",\"__msdisposeindex\":210},\"Name\":" + tagTitle + ",\"_itemPathSeparator\":\"_\",\"__msdisposeindex\":211}]," +
                                                                   "\"TypeProperties\":[],\"_itemPathSeparator\":\"_\"}";

                var items = newsController.Model.CreateListViewModel(null, 1).Items.ToArray();

                Assert.IsTrue(items.Length.Equals(1), "The count of news items is not correct");
                Assert.IsTrue(items[0].Fields.Title.Equals(newsTitle + 1, StringComparison.CurrentCulture), "The news with this title was not found!");
            }
            finally
            {
                this.serverOperationsTaxonomies.DeleteTags(tagTitle);
                this.serverOperationsTaxonomies.DeleteCategories(categoryTitle);
            }
        }
        public void NewsWidget_VerifyDateSelectorAnyTimeOption()
        {
            var newsManager = NewsManager.GetManager();
            int newsCount = 3;

            var newsController = new NewsController();
            newsController.Model.SelectionMode = SelectionMode.FilteredItems;
            newsController.Model.SerializedAdditionalFilters = "{\"QueryItems\":[]}";

            DateTime publicationDate = DateTime.UtcNow.AddYears(-2);

            NewsItem modified = newsManager.GetNewsItems().Where<NewsItem>(ni => ni.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Master && ni.Title == "Boat").FirstOrDefault();
            newsManager.Lifecycle.PublishWithSpecificDate(modified, publicationDate);
            newsManager.SaveChanges();

            var items = newsController.Model.CreateListViewModel(null, 1).Items.ToArray();
            Assert.AreEqual(newsCount, items.Length, "The count of the news item is not as expected");

            Assert.IsTrue(items[0].Fields.Title.Equals(this.newsTitles[1]), "The news with this title was not found!");
            Assert.IsTrue(items[1].Fields.Title.Equals(this.newsTitles[0]), "The news with this title was not found!");
            Assert.IsTrue(items[2].Fields.Title.Equals(this.newsTitles[2]), "The news with this title was not found!");
        }
        public void NewsWidget_SocialShareButtonsFunctionality()
        {
            string socialShare = "list-inline sf-social-share";
            string testName = System.Reflection.MethodInfo.GetCurrentMethod().Name;
            string pageNamePrefix = testName + "NewsPage" + Guid.NewGuid();
            string pageTitlePrefix = testName + "NewsPage" + Guid.NewGuid();
            string urlNamePrefix = testName + "news-page" + Guid.NewGuid();
            int index = 1;
            var newsManager = NewsManager.GetManager();
            string url = UrlPath.ResolveAbsoluteUrl("~/" + urlNamePrefix + index);

            var mvcProxy = new MvcControllerProxy();
            mvcProxy.ControllerName = typeof(NewsController).FullName;
            var newsController = new NewsController();
            newsController.Model.EnableSocialSharing = true;
            mvcProxy.Settings = new ControllerSettings(newsController);

            try
            {
                this.pageOperations.CreatePageWithControl(mvcProxy, pageNamePrefix, pageTitlePrefix, urlNamePrefix, index);

                Telerik.Sitefinity.TestUtilities.CommonOperations.ServerOperations.News().CreateNewsItem(NewsTitle);

                NewsItem newsItem = newsManager.GetNewsItems().Where<NewsItem>(ni => ni.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Master && ni.Title == NewsTitle).FirstOrDefault();

                string detailNewsUrl = url + newsItem.ItemDefaultUrl;

                string responseContent = PageInvoker.ExecuteWebRequest(detailNewsUrl);

                Assert.IsTrue(responseContent.Contains(socialShare), "Social share button was not found!");
                Assert.IsTrue(responseContent.Contains(NewsTitle), "The news with this title was not found!");
            }
            finally
            {
                this.pageOperations.DeletePages();
                Telerik.Sitefinity.TestUtilities.CommonOperations.ServerOperations.News().DeleteAllNews();
            }
        }
        public void NewsWidget_VerifyUsePagingFunctionality()
        {
            string testName = System.Reflection.MethodInfo.GetCurrentMethod().Name;
            string pageNamePrefix = testName + "NewsPage";
            string pageTitlePrefix = testName + "News Page";
            string urlNamePrefix = testName + "news-page";
            int index = 1;
            string index2 = "/2";
            int itemsPerPage = 3;
            string url = UrlPath.ResolveAbsoluteUrl("~/" + urlNamePrefix + index);
            string url2 = UrlPath.ResolveAbsoluteUrl("~/" + urlNamePrefix + index + index2);

            var mvcProxy = new MvcControllerProxy();
            mvcProxy.ControllerName = typeof(NewsController).FullName;
            var newsController = new NewsController();
            newsController.Model.ItemsPerPage = itemsPerPage;
            mvcProxy.Settings = new Telerik.Sitefinity.Mvc.Proxy.ControllerSettings(newsController);

            try
            {
                this.pageOperations.CreatePageWithControl(mvcProxy, pageNamePrefix, pageTitlePrefix, urlNamePrefix, index);

                int newsCount = 5;

                for (int i = 1; i <= newsCount; i++)
                    Telerik.Sitefinity.TestUtilities.CommonOperations.ServerOperations.News().CreateNewsItem(NewsTitle + i);

                string responseContent = PageInvoker.ExecuteWebRequest(url);
                string responseContent2 = PageInvoker.ExecuteWebRequest(url2);

                for (int i = 1; i <= newsCount; i++)
                {
                    if (i <= 2)
                    {
                        Assert.IsFalse(responseContent.Contains(NewsTitle + i), "The news with this title was found!");
                    }
                    else
                    {
                        Assert.IsTrue(responseContent.Contains(NewsTitle + i), "The news with this title was not found!");
                    }
                }

                for (int i = 1; i <= newsCount; i++)
                {
                    if (i <= 2)
                    {
                        Assert.IsTrue(responseContent2.Contains(NewsTitle + i), "The news with this title was not found!");
                    }
                    else
                    {
                        Assert.IsFalse(responseContent2.Contains(NewsTitle + i), "The news with this title was found!");
                    }
                }
            }
            finally
            {
                this.pageOperations.DeletePages();
            }
        }
        public void NewsWidget_VerifySelectedItemsFunctionalityWithUseLimit()
        {
            string testName = System.Reflection.MethodInfo.GetCurrentMethod().Name;
            string pageNamePrefix = testName + "NewsPage";
            string pageTitlePrefix = testName + "News Page";
            string urlNamePrefix = testName + "news-page";
            int index = 1;
            string sortExpession = "AsSetManually";
            string url = UrlPath.ResolveAbsoluteUrl("~/" + urlNamePrefix + index);

            int newsCount = 20;
            string[] selectedNewsTitles = { "Title7", "Title15", "Title11", "Title3", "Title5", "Title8", "Title2", "Title16", "Title6" };
            var selectedNewsItems = new NewsItem[9];

            for (int i = 0; i < newsCount; i++)
            {
                this.serverOperationsNews.CreatePublishedNewsItem(newsTitle: NewsTitle + i, newsContent: NewsTitle + i, author: NewsTitle + i);
            }

            var mvcProxy = new MvcControllerProxy();
            mvcProxy.ControllerName = typeof(NewsController).FullName;
            var newsController = new NewsController();
            newsController.Model.SelectionMode = SelectionMode.SelectedItems;
            newsController.Model.DisplayMode = ListDisplayMode.Limit;
            newsController.Model.SortExpression = sortExpession;
            newsController.Model.ItemsPerPage = 5;

            var newsManager = NewsManager.GetManager();

            for (int i = 0; i < selectedNewsTitles.Count(); i++)
            {
                selectedNewsItems[i] = newsManager.GetNewsItems().FirstOrDefault(n => n.Title == selectedNewsTitles[i] && n.OriginalContentId != Guid.Empty);
            }

            //// SerializedSelectedItemsIds string should appear in the following format: "[\"ca782d6b-9e3d-6f9e-ae78-ff00006062c4\",\"66782d6b-9e3d-6f9e-ae78-ff00006062c4\"]"
            newsController.Model.SerializedSelectedItemsIds =
                                                             "[\"" + selectedNewsItems[0].Id.ToString() + "\"," +
                                                             "\"" + selectedNewsItems[1].Id.ToString() + "\"," +
                                                             "\"" + selectedNewsItems[2].Id.ToString() + "\"," +
                                                             "\"" + selectedNewsItems[3].Id.ToString() + "\"," +
                                                             "\"" + selectedNewsItems[4].Id.ToString() + "\"," +
                                                             "\"" + selectedNewsItems[5].Id.ToString() + "\"," +
                                                             "\"" + selectedNewsItems[6].Id.ToString() + "\"," +
                                                             "\"" + selectedNewsItems[7].Id.ToString() + "\"," +
                                                             "\"" + selectedNewsItems[8].Id.ToString() + "\"]";

            mvcProxy.Settings = new ControllerSettings(newsController);

            this.VerifyCorrectNewsOnPageWithUseLimitsOption(mvcProxy, pageNamePrefix, pageTitlePrefix, urlNamePrefix, index, url, selectedNewsTitles);
        }
        public void NewsWidget_VerifySortNewsLastModifiedDateDescending()
        {
            string sortExpession = "LastModified DESC";
            string[] newsTitles = { "Cat", "Boat", "Angel" };

            var newsController = new NewsController();
            newsController.Model.DisplayMode = ListDisplayMode.Limit;
            newsController.Model.SortExpression = sortExpession;
            var newsManager = NewsManager.GetManager();

            for (int i = 0; i < newsTitles.Length; i++)
                Telerik.Sitefinity.TestUtilities.CommonOperations.ServerOperations.News().CreateNewsItem(newsTitles[i]);

            NewsItem modified = newsManager.GetNewsItems().Where<NewsItem>(ni => ni.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Master && ni.Title == "Boat").FirstOrDefault();

            NewsItem temp = newsManager.Lifecycle.CheckOut(modified) as NewsItem;

            temp.Title = "BoatNew";

            modified = newsManager.Lifecycle.CheckIn(temp) as NewsItem;

            var newsItem = newsManager.GetNewsItem(modified.Id);
            newsManager.Lifecycle.Publish(newsItem);
            newsManager.SaveChanges();

            var items = newsController.Model.CreateListViewModel(null, 1).Items.ToArray();

            Assert.IsTrue(items[0].Fields.LastModified.Equals(modified.LastModified), "The news with this title was not found!");
            Assert.IsTrue(items[0].Fields.Title.Equals(modified.Title.Value), "The news with this title was not found!");
            Assert.IsTrue(items[1].Fields.Title.Equals(newsTitles[2]), "The news with this title was not found!");
            Assert.IsTrue(items[2].Fields.Title.Equals(newsTitles[0]), "The news with this title was not found!");
        }
        public void NewsWidget_VerifySortNewsPublicationDateDescending()
        {
            string sortExpession = "PublicationDate DESC";
            string[] newsTitles = { "Cat", "Boat", "Angel" };

            var newsController = new NewsController();
            newsController.Model.DisplayMode = ListDisplayMode.Limit;
            newsController.Model.SortExpression = sortExpession;

            for (int i = 0; i < newsTitles.Length; i++)
                Telerik.Sitefinity.TestUtilities.CommonOperations.ServerOperations.News().CreateNewsItem(newsTitles[i]);

            var items = newsController.Model.CreateListViewModel(null, 1).Items.ToArray();

            int lastIndex = newsTitles.Length - 1;

            var newsManager = NewsManager.GetManager();
            var newsItems = newsManager.GetNewsItems().Where<NewsItem>(ni => ni.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Master);

            foreach (NewsItem item in newsItems)
            {
                Assert.IsTrue(items[lastIndex].Fields.PublicationDate.Equals(item.PublicationDate), "The news with this title was not found!");
                lastIndex--;
            }
        }
        public void SearchResultsWidget_NonDefaultLanguage_ResultsFound_OldestOrder()
        {
            Guid searchIndex1Id = Guid.Empty;
            try
            {
                searchIndex1Id = SitefinityOperations.ServerOperations.Search().CreateSearchIndex(SearchResultsWidgetTests.SearchIndexName, new[] { SitefinityOperations.SearchContentType.Pages, SitefinityOperations.SearchContentType.News });
                SitefinityOperations.ServerOperations.Search().Reindex(searchIndex1Id);

                int index = 1;
                string testName = System.Reflection.MethodInfo.GetCurrentMethod().Name;
                string pageNamePrefix = testName + "NewsPage" + index;
                string pageTitlePrefix = testName + "NewsPage" + index;
                string urlNamePrefix = testName + "news-page" + index;

                var frontEndLanguages = AppSettings.CurrentSettings.DefinedFrontendLanguages;
                var language = frontEndLanguages[2].Name;
                string orderBy = "Oldest";
                var searchResultsController = new SearchResultsController();

                var mvcProxy = new MvcControllerProxy();
                mvcProxy.ControllerName = typeof(NewsController).FullName;
                var newsController = new NewsController();
                mvcProxy.Settings = new ControllerSettings(newsController);

                this.pageOperations.CreatePageWithControl(mvcProxy, pageNamePrefix, pageTitlePrefix, urlNamePrefix, index);

                searchResultsController.Index(null, SearchResultsWidgetTests.NewsTitle, SearchResultsWidgetTests.SearchIndexName, null, language, orderBy);

                Assert.AreEqual(1, searchResultsController.Model.Results.TotalCount);
                Assert.AreEqual(SearchResultsWidgetTests.NewsTitle + "20", searchResultsController.Model.Results.Data[0].GetValue("Title"));
            }
            finally
            {
                Telerik.Sitefinity.TestUtilities.CommonOperations.ServerOperations.Search().DeleteAllIndexes();
            }
        }
        public void NewsWidget_SelectByCategoryNewsFunctionalityAndPaging()
        {
            var newsController = new NewsController();
            newsController.Model.DisplayMode = ListDisplayMode.Paging;
            int itemsPerPage = 3;
            newsController.Model.ItemsPerPage = itemsPerPage;
            string categoryTitle = "Category";
            string[] newsTitles = { "Boat", "Cat", "Angel", "Kitty", "Dog" };
            Guid[] newsId = new Guid[newsTitles.Count()];

            try
            {
                this.serverOperationsTaxonomies.CreateCategory(categoryTitle + "0");
                this.serverOperationsTaxonomies.CreateCategory(categoryTitle + "1", categoryTitle + "0");

                TaxonomyManager taxonomyManager = TaxonomyManager.GetManager();
                var category0 = taxonomyManager.GetTaxa<HierarchicalTaxon>().SingleOrDefault(t => t.Title == categoryTitle + "0");
                var category1 = taxonomyManager.GetTaxa<HierarchicalTaxon>().SingleOrDefault(t => t.Title == categoryTitle + "1");

                for (int i = 0; i < newsTitles.Count(); i++)
                {
                    if (i == 0)
                    {
                        newsId[i] = this.serverOperationsNews.CreatePublishedNewsItem(newsTitles[i]);
                        this.serverOperationsNews.AssignTaxonToNewsItem(newsId[i], "Category", category0.Id);
                    }
                    else if (i > 0 && i <= 3)
                    {
                        newsId[i] = this.serverOperationsNews.CreatePublishedNewsItem(newsTitles[i]);
                        this.serverOperationsNews.AssignTaxonToNewsItem(newsId[i], "Category", category0.Id);
                        this.serverOperationsNews.AssignTaxonToNewsItem(newsId[i], "Category", category1.Id);
                    }
                    else
                    {
                        newsId[i] = this.serverOperationsNews.CreatePublishedNewsItem(newsTitles[i]);
                        this.serverOperationsNews.AssignTaxonToNewsItem(newsId[i], "Category", category1.Id);
                    }
                }

                this.VerifyCorrectNewsOnPageWithCategoryFilterAndPaging(category0, category1, newsController, newsTitles);
            }
            finally
            {
                this.serverOperationsTaxonomies.DeleteCategories("Category0", "Category1");
            }
        }
        public void NewsWidget_VerifyDateSelectorLastOneWeekOption()
        {
            var newsManager = NewsManager.GetManager();
            int newsCount = 2;

            var newsController = new NewsController();
            newsController.Model.SelectionMode = SelectionMode.FilteredItems;
            newsController.Model.SerializedAdditionalFilters = @"{
                ""QueryItems"": [
                    {
                        ""IsGroup"":true,
                        ""Ordinal"":0,
                        ""Join"":""AND"",
                        ""ItemPath"":""_0"",
                        ""Value"":null,
                        ""Condition"":null,
                        ""Name"":""PublicationDate""
                    },
                    {
                        ""IsGroup"":false,
                        ""Ordinal"":0,
                        ""Join"":""AND"",
                        ""ItemPath"":""_0_0"",
                        ""Value"":""DateTime.UtcNow.AddDays(-7.0)"",
                        ""Condition"": {
                            ""FieldName"":""PublicationDate"",
                            ""FieldType"":""System.DateTime"",
                            ""Operator"":"">""
                        },
                        ""Name"":""PublicationDate.DateTime.UtcNow.AddDays(-7.0)""
                    }
                ]
            }";

            DateTime publicationDate = DateTime.UtcNow.AddDays(-10);

            NewsItem modified = newsManager.GetNewsItems().Where<NewsItem>(ni => ni.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Master && ni.Title == "Boat").FirstOrDefault();
            newsManager.Lifecycle.PublishWithSpecificDate(modified, publicationDate);
            newsManager.SaveChanges();

            var items = newsController.Model.CreateListViewModel(null, 1).Items.ToArray();
            var newsItemsCount = items.Length;

            Assert.AreEqual(newsCount, newsItemsCount, "The count of the news item is not as expected");

            for (int i = 0; i < newsItemsCount; i++)
            {
                Assert.IsFalse(items[i].Fields.Title.Equals(this.newsTitles[2]), "The news with this title was found!");
            }

            Assert.IsTrue(items[0].Fields.Title.Equals(this.newsTitles[1]), "The news with this title was not found!");
            Assert.IsTrue(items[1].Fields.Title.Equals(this.newsTitles[0]), "The news with this title was not found!");
        }
        public void NewsWidget_VerifyDateSelectorCustomRangeOption()
        {
            var newsManager = NewsManager.GetManager();
            int newsCount = 2;
            DateTime publicationDateOld = new DateTime(2014, 10, 14, 12, 00, 00);
            DateTime publicationDateNew = new DateTime(2014, 10, 23, 12, 00, 00);

            var newsController = new NewsController();
            newsController.Model.SelectionMode = SelectionMode.FilteredItems;
            newsController.Model.SerializedAdditionalFilters = @"{
            ""QueryItems"":[
                {
                    ""IsGroup"":true,
                    ""Ordinal"":0,
                    ""Join"":""AND"",
                    ""ItemPath"":""_0"",
                    ""Value"":null,
                    ""Condition"":null,
                    ""Name"":""PublicationDate""
                },
                {
                    ""IsGroup"":false,
                    ""Ordinal"":0,
                    ""Join"":""AND"",
                    ""ItemPath"":""_0_0"",
                    ""Value"":""Wed, 22 Oct 2014 21:00:00 GMT"",
                    ""Condition"":
                        {
                            ""FieldName"":""PublicationDate"",
                            ""FieldType"":""System.DateTime"",
                            ""Operator"":"">""
                        },
                    ""Name"":""PublicationDate.Wed, 22 Oct 2014 21:00:00 GMT""
                },
                {
                    ""IsGroup"":false,
                    ""Ordinal"":1,
                    ""Join"":""AND"",
                    ""ItemPath"":""_0_1"",
                    ""Value"":""Fri, 24 Oct 2014 21:00:00 GMT"",
                    ""Condition"":
                        {
                            ""FieldName"":""PublicationDate"",
                            ""FieldType"":""System.DateTime"",
                            ""Operator"":""<""
                        },
                    ""Name"":""PublicationDate.Fri, 24 Oct 2014 21:00:00 GMT""
                }";

            NewsItem modifiedBoat = newsManager.GetNewsItems().Where<NewsItem>(ni => ni.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Master && ni.Title == "Boat").FirstOrDefault();
            newsManager.Lifecycle.PublishWithSpecificDate(modifiedBoat, publicationDateOld);

            NewsItem modifiedCat = newsManager.GetNewsItems().Where<NewsItem>(ni => ni.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Master && ni.Title == "Cat").FirstOrDefault();
            newsManager.Lifecycle.PublishWithSpecificDate(modifiedCat, publicationDateNew);

            NewsItem modifiedAngel = newsManager.GetNewsItems().Where<NewsItem>(ni => ni.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Master && ni.Title == "Angel").FirstOrDefault();
            newsManager.Lifecycle.PublishWithSpecificDate(modifiedAngel, publicationDateNew);
            newsManager.SaveChanges();

            var items = newsController.Model.CreateListViewModel(null, 1).Items.ToArray();
            var newsItemsCount = items.Length;

            Assert.AreEqual(newsCount, newsItemsCount, "The count of the news item is not as expected");

            for (int i = 0; i < newsItemsCount; i++)
            {
                Assert.IsFalse(items[i].Fields.Title.Equals(this.newsTitles[2]), "The news with this title was found!");
            }

            Assert.IsTrue(items[0].Fields.Title.Equals(this.newsTitles[0]), "The news with this title was not found!");
            Assert.IsTrue(items[1].Fields.Title.Equals(this.newsTitles[1]), "The news with this title was not found!");
        }
        public void NewsWidget_VerifySelectedItemsFunctionalityWithSortNewsDescending()
        {
            int newsCount = 10;
            string sortExpession = "Title DESC";
            string[] selectedNewsTitles = { "Title2", "Title7", "Title5" };
            string[] descendingNewsTitles = { "Title7", "Title5", "Title2" };
            var selectedNewsItems = new NewsItem[3];

            for (int i = 0; i < newsCount; i++)
            {
                this.serverOperationsNews.CreatePublishedNewsItem(newsTitle: NewsTitle + i, newsContent: NewsTitle + i, author: NewsTitle + i);
            }

            var newsController = new NewsController();
            newsController.Model.SelectionMode = SelectionMode.SelectedItems;
            newsController.Model.SortExpression = sortExpession;

            var newsManager = NewsManager.GetManager();

            for (int i = 0; i < selectedNewsTitles.Count(); i++)
            {
                selectedNewsItems[i] = newsManager.GetNewsItems().FirstOrDefault(n => n.Title == selectedNewsTitles[i] && n.OriginalContentId != Guid.Empty);
            }

            //// SerializedSelectedItemsIds string should appear in the following format: "[\"ca782d6b-9e3d-6f9e-ae78-ff00006062c4\",\"66782d6b-9e3d-6f9e-ae78-ff00006062c4\"]"
            newsController.Model.SerializedSelectedItemsIds =
                                                             "[\"" + selectedNewsItems[0].Id.ToString() + "\"," +
                                                             "\"" + selectedNewsItems[1].Id.ToString() + "\"," +
                                                             "\"" + selectedNewsItems[2].Id.ToString() + "\"]";

            var items = newsController.Model.CreateListViewModel(null, 1).Items.ToArray();

            Assert.AreEqual(3, items.Length, "The count of news is not as expected");

            for (int i = 0; i < items.Length; i++)
            {
                Assert.IsTrue(items[i].Fields.Title.Equals(descendingNewsTitles[i]), "The news with this title was not found!");
            }

            newsController.Model.SelectionMode = SelectionMode.AllItems;

            items = newsController.Model.CreateListViewModel(null, 1).Items.ToArray();

            int lastIndex = 9;
            for (int i = 0; i < 10; i++)
            {
                Assert.IsTrue(items[i].Fields.Title.Equals(NewsTitle + lastIndex), "The news with this title was not found!");
                lastIndex--;
            }
        }
        public void NewsWidget_VerifyInvalidSortingOptionAsSetInAdvancedMode()
        {
            string sortExpession = "Content ASC";
            var itemsCount = 5;
            string[] newsContent = { "Ivan", "George", "Steve", "Ana", "Tom" };
            string[] expectedSortedNewsTitles = { "news3", "news1", "news0", "news2", "news4" };

            var newsController = new NewsController();
            newsController.Model.SortExpression = sortExpession;

            for (int i = 0; i < itemsCount; i++)
                Telerik.Sitefinity.TestUtilities.CommonOperations.ServerOperations.News().CreateNewsItem("news" + i, content: newsContent[i]);

            var items = newsController.Model.CreateListViewModel(null, 1).Items.ToArray();

            for (int i = 0; i < itemsCount; i++)
            {
                Assert.AreEqual(expectedSortedNewsTitles[i], items[i].Fields.Title.Value, "The news with this title was not found!");
            }
        }
        public void NewsWidget_VerifySelectedItemsFunctionality()
        {
            int newsCount = 5;

            for (int i = 0; i < newsCount; i++)
            {
                this.serverOperationsNews.CreatePublishedNewsItem(newsTitle: NewsTitle + i, newsContent: NewsTitle + i, author: NewsTitle + i);
            }

            var newsController = new NewsController();
            newsController.Model.SelectionMode = SelectionMode.SelectedItems;

            var newsManager = NewsManager.GetManager();
            var selectedNewsItem = newsManager.GetNewsItems().FirstOrDefault(n => n.Title == "Title2" && n.OriginalContentId != Guid.Empty);
            newsController.Model.SerializedSelectedItemsIds = "[\"" + selectedNewsItem.Id.ToString() + "\"]";

            var items = newsController.Model.CreateListViewModel(null, 1).Items.ToArray();
            Assert.AreEqual(1, items.Length, "The count of news is not as expected");

            Assert.IsTrue(items[0].Fields.Title.Equals("Title2", StringComparison.CurrentCulture), "The news with this title was not found!");
        }
        public void NewsWidget_VerifyAllNewsFunctionality()
        {
            string testName = System.Reflection.MethodInfo.GetCurrentMethod().Name;
            string pageNamePrefix = testName + "NewsPage";
            string pageTitlePrefix = testName + "News Page";
            string urlNamePrefix = testName + "news-page";
            int index = 1;
            string url = UrlPath.ResolveAbsoluteUrl("~/" + urlNamePrefix + index);

            var mvcProxy = new MvcControllerProxy();
            mvcProxy.ControllerName = typeof(NewsController).FullName;
            var newsController = new NewsController();
            newsController.Model.SelectionMode = SelectionMode.AllItems;
            mvcProxy.Settings = new ControllerSettings(newsController);

            try
            {
                this.pageOperations.CreatePageWithControl(mvcProxy, pageNamePrefix, pageTitlePrefix, urlNamePrefix, index);

                int newsCount = 5;

                for (int i = 1; i <= newsCount; i++)
                    this.serverOperationsNews.CreateNewsItem(NewsTitle + i);

                string responseContent = PageInvoker.ExecuteWebRequest(url);

                for (int i = 1; i <= newsCount; i++)
                    Assert.IsTrue(responseContent.Contains(NewsTitle + i), "The news with this title was not found!");
            }
            finally
            {
                this.pageOperations.DeletePages();
            }
        }
        public void NewsWidget_SelectByTagAndSortNewsFunctionality()
        {
            int tagsCount = 3;
            Guid[] taxonId = new Guid[tagsCount];
            string tagTitle = "Tag ";
            string sortExpession = "Title ASC";
            string[] newsTitles = { "Boat", "Cat", "Angel", "Kitty", "Dog" };
            string[] sortedTitles = { "Angel", "Boat", "Cat" };
            Guid[] newsId = new Guid[newsTitles.Count()];
            var newsController = new NewsController();
            newsController.Model.SortExpression = sortExpession;
            string[] tagTitles = new string[tagsCount];

            try
            {
                for (int i = 0; i < tagsCount; i++)
                {
                    taxonId[i] = this.serverOperationsTaxonomies.CreateFlatTaxon(Telerik.Sitefinity.TestUtilities.CommonOperations.TaxonomiesConstants.TagsTaxonomyId, tagTitle + i);
                    tagTitles[i] = tagTitle + i;
                }

                for (int i = 0; i < newsTitles.Count(); i++)
                {
                    if (i <= 2)
                    {
                        newsId[i] = this.serverOperationsNews.CreatePublishedNewsItem(newsTitles[i]);
                        this.serverOperationsNews.AssignTaxonToNewsItem(newsId[i], "Tags", taxonId[0]);
                    }
                    else
                    {
                        newsId[i] = this.serverOperationsNews.CreatePublishedNewsItem(newsTitles[i]);
                        this.serverOperationsNews.AssignTaxonToNewsItem(newsId[i], "Tags", taxonId[i - 2]);
                    }
                }

                newsController.Index(null);
                TaxonomyManager taxonomyManager = TaxonomyManager.GetManager();

                for (int i = 0; i < tagsCount; i++)
                {
                    ITaxon taxonomy = taxonomyManager.GetTaxon(taxonId[i]);
                    var items = newsController.Model.CreateListViewModel(taxonomy, 1).Items.ToArray();

                    if (i == 0)
                    {
                        for (int j = 0; j < items.Length; j++)
                            Assert.IsTrue(items[j].Fields.Title.Equals(sortedTitles[j], StringComparison.CurrentCulture), "The news with this title was not found!");
                    }
                    else
                    {
                        for (int j = 0; j < items.Length; j++)
                            Assert.IsTrue(items[j].Fields.Title.Equals(newsTitles[i + 2], StringComparison.CurrentCulture), "The news with this title was not found!");
                    }
                }
            }
            finally
            {
                this.serverOperationsTaxonomies.DeleteTags(tagTitles);
            }
        }
        public void NewsWidget_SelectByTagNewsFunctionalityAndPaging()
        {
            var newsController = new NewsController();
            newsController.Model.DisplayMode = ListDisplayMode.Paging;
            newsController.Model.ItemsPerPage = 2;

            string tagTitle = "Tag1";
            string newsTitle = "News ";

            try
            {
                Guid taxonId = this.serverOperationsTaxonomies.CreateFlatTaxon(Telerik.Sitefinity.TestUtilities.CommonOperations.TaxonomiesConstants.TagsTaxonomyId, tagTitle);

                Guid newsId0 = this.serverOperationsNews.CreatePublishedNewsItem(newsTitle + 0);
                this.serverOperationsNews.AssignTaxonToNewsItem(newsId0, "Tags", taxonId);

                Guid newsId1 = this.serverOperationsNews.CreatePublishedNewsItem(newsTitle + 1);
                this.serverOperationsNews.AssignTaxonToNewsItem(newsId1, "Tags", taxonId);

                Guid newsId2 = this.serverOperationsNews.CreatePublishedNewsItem(newsTitle + 2);
                this.serverOperationsNews.AssignTaxonToNewsItem(newsId2, "Tags", taxonId);

                this.serverOperationsNews.CreatePublishedNewsItem(newsTitle + 3);

                ITaxon tagTaxonomy = TaxonomyManager.GetManager().GetTaxon(taxonId);
                var items = newsController.Model.CreateListViewModel(tagTaxonomy, 1).Items.ToArray();

                Assert.IsTrue(items.Length.Equals(2), "The count of news items is not correct - first page");
                Assert.IsTrue(items[0].Fields.Title.Equals(newsTitle + 2, StringComparison.CurrentCulture), "The news with this title was found!");
                Assert.IsTrue(items[1].Fields.Title.Equals(newsTitle + 1, StringComparison.CurrentCulture), "The news with this title was found!");

                items = newsController.Model.CreateListViewModel(tagTaxonomy, 2).Items.ToArray();

                Assert.IsTrue(items.Length.Equals(1), "The count of news items is not correct - second page");
                Assert.IsTrue(items[0].Fields.Title.Equals(newsTitle + 0, StringComparison.CurrentCulture), "The news with this title was found!");

                newsController.Model.DisplayMode = ListDisplayMode.Paging;
                newsController.Model.ItemsPerPage = 20;
                items = newsController.Model.CreateListViewModel(tagTaxonomy, 1).Items.ToArray();

                Assert.IsTrue(items.Length.Equals(3), "The count of news items is not correct - all items");
                Assert.IsTrue(items[0].Fields.Title.Equals(newsTitle + 2, StringComparison.CurrentCulture), "The news with this title was found!");
                Assert.IsTrue(items[1].Fields.Title.Equals(newsTitle + 1, StringComparison.CurrentCulture), "The news with this title was found!");
                Assert.IsTrue(items[2].Fields.Title.Equals(newsTitle + 0, StringComparison.CurrentCulture), "The news with this title was found!");
            }
            finally
            {
                this.serverOperationsTaxonomies.DeleteTags(tagTitle);
            }
        }
        public void NewsWidget_SelectByTagNewsFunctionality()
        {
            int newsCount = 2;
            Guid[] taxonId = new Guid[newsCount];
            Guid[] newsId = new Guid[newsCount];
            string newsTitle = "News ";
            string tagTitle = "Tag ";
            var newsController = new NewsController();
            string[] tagTitles = new string[newsCount];

            try
            {
                for (int i = 0; i < newsCount; i++)
                {
                    taxonId[i] = this.serverOperationsTaxonomies.CreateFlatTaxon(Telerik.Sitefinity.TestUtilities.CommonOperations.TaxonomiesConstants.TagsTaxonomyId, tagTitle + i);
                    tagTitles[i] = tagTitle + i;
                    newsId[i] = this.serverOperationsNews.CreatePublishedNewsItem(newsTitle + i);
                    this.serverOperationsNews.AssignTaxonToNewsItem(newsId[i], "Tags", taxonId[i]);
                }

                for (int i = 0; i < newsCount; i++)
                {
                    ITaxon taxonomy = TaxonomyManager.GetManager().GetTaxon(taxonId[i]);
                    var items = newsController.Model.CreateListViewModel(taxonomy, 1).Items.ToArray();

                    for (int j = 0; j < items.Length; j++)
                        Assert.IsTrue(items[j].Fields.Title.Equals(newsTitle + i, StringComparison.CurrentCulture), "The news with this title was not found!");
                }
            }
            finally
            {
                this.serverOperationsTaxonomies.DeleteTags(tagTitles);
            }
        }
        public void NewsWidget_VerifyDateSelectorCustomRangeOptionNotExisting()
        {
            int newsCount = 0;

            var mvcProxy = new MvcControllerProxy();
            mvcProxy.ControllerName = typeof(NewsController).FullName;
            var newsController = new NewsController();
            newsController.Model.SelectionMode = SelectionMode.FilteredItems;
            newsController.Model.SerializedAdditionalFilters = @"{
            ""QueryItems"":[
                {
                    ""IsGroup"":true,
                    ""Ordinal"":0,
                    ""Join"":""AND"",
                    ""ItemPath"":""_0"",
                    ""Value"":null,
                    ""Condition"":null,
                    ""Name"":""PublicationDate""
                },
                {
                    ""IsGroup"":false,
                    ""Ordinal"":0,
                    ""Join"":""AND"",
                    ""ItemPath"":""_0_0"",
                    ""Value"":""Wed, 22 Oct 2014 21:00:00 GMT"",
                    ""Condition"":
                        {
                            ""FieldName"":""PublicationDate"",
                            ""FieldType"":""System.DateTime"",
                            ""Operator"":"">""
                        },
                    ""Name"":""PublicationDate.Wed, 22 Oct 2014 21:00:00 GMT""
                },
                {
                    ""IsGroup"":false,
                    ""Ordinal"":1,
                    ""Join"":""AND"",
                    ""ItemPath"":""_0_1"",
                    ""Value"":""Fri, 24 Oct 2014 21:00:00 GMT"",
                    ""Condition"":
                        {
                            ""FieldName"":""PublicationDate"",
                            ""FieldType"":""System.DateTime"",
                            ""Operator"":""<""
                        },
                    ""Name"":""PublicationDate.Fri, 24 Oct 2014 21:00:00 GMT""
                }";

            mvcProxy.Settings = new ControllerSettings(newsController);

            var newsItemsCount = newsController.Model.CreateListViewModel(null, 1).Items.Count();
            Assert.AreEqual(newsCount, newsItemsCount, "The count of the news item is not as expected");
        }
        private void VerifyCorrectNewsOnPageWithCategoryFilterAndPaging(HierarchicalTaxon category0, HierarchicalTaxon category1, NewsController newsController, string[] newsTitles)
        {
            ITaxon taxonomy = TaxonomyManager.GetManager().GetTaxon(category0.Id);
            var items = newsController.Model.CreateListViewModel(taxonomy, 1).Items.ToArray();

            Assert.IsTrue(items.Length.Equals(3), "Number of news items is not correct");
            for (int i = 0; i <= 2; i++)
            {
                Assert.IsTrue(items[i].Fields.Title.Equals(newsTitles[3 - i], StringComparison.CurrentCulture), "The news with this title was found!");
            }

            items = newsController.Model.CreateListViewModel(taxonomy, 2).Items.ToArray();

            Assert.IsTrue(items.Length.Equals(1), "Number of news items is not correct");
            Assert.IsTrue(items[0].Fields.Title.Equals(newsTitles[0], StringComparison.CurrentCulture), "The news with this title was found!");

            taxonomy = TaxonomyManager.GetManager().GetTaxon(category1.Id);
            items = newsController.Model.CreateListViewModel(taxonomy, 1).Items.ToArray();

            Assert.IsTrue(items.Length.Equals(3), "Number of news items is not correct");
            for (int i = 0; i <= 2; i++)
            {
                Assert.IsTrue(items[i].Fields.Title.Equals(newsTitles[4 - i], StringComparison.CurrentCulture), "The news with this title was found!");
            }

            items = newsController.Model.CreateListViewModel(taxonomy, 2).Items.ToArray();

            Assert.IsTrue(items.Length.Equals(1), "Number of news items is not correct");
            Assert.IsTrue(items[0].Fields.Title.Equals(newsTitles[1], StringComparison.CurrentCulture), "The news with this title was found!");
        }
 private MvcControllerProxy CreateNewsControl()
 {
     var newsSelectorControl = new MvcControllerProxy();
     newsSelectorControl.ControllerName = typeof(NewsController).FullName;
     var newsController = new NewsController();
     newsSelectorControl.Settings = new ControllerSettings(newsController);
     return newsSelectorControl;
 }
        public void SearchResultsWidget_DefaultLanguage_NoLimit_NewestOrder()
        {
            Guid searchIndex1Id = Guid.Empty;
            try
            {
                searchIndex1Id = SitefinityOperations.ServerOperations.Search().CreateSearchIndex(SearchResultsWidgetTests.SearchIndexName, new[] { SitefinityOperations.SearchContentType.News });
                SitefinityOperations.ServerOperations.Search().Reindex(searchIndex1Id);

                int index = 1;
                string testName = System.Reflection.MethodInfo.GetCurrentMethod().Name;
                string pageNamePrefix = testName + "NewsPage" + index;
                string pageTitlePrefix = testName + "NewsPage" + index;
                string urlNamePrefix = testName + "news-page" + index;

                string orderBy = "Newest";
                var searchResultsController = new SearchResultsController();
                searchResultsController.Model.DisplayMode = Telerik.Sitefinity.Frontend.Search.Mvc.Models.ListDisplayMode.All;
                searchResultsController.Model.ItemsPerPage = 2;

                var mvcProxy = new MvcControllerProxy();
                mvcProxy.ControllerName = typeof(NewsController).FullName;
                var newsController = new NewsController();
                mvcProxy.Settings = new ControllerSettings(newsController);

                this.pageOperations.CreatePageWithControl(mvcProxy, pageNamePrefix, pageTitlePrefix, urlNamePrefix, index);

                searchResultsController.Index(null, SearchResultsWidgetTests.NewsTitle, SearchResultsWidgetTests.SearchIndexName, null, this.frontEndLanguages[0].Name, orderBy);

                Assert.AreEqual(SearchResultsWidgetTests.NewsCount, searchResultsController.Model.Results.TotalCount);
                for (int i = 0; i < SearchResultsWidgetTests.NewsCount; i++)
                {
                    Assert.AreEqual(SearchResultsWidgetTests.NewsTitle + (SearchResultsWidgetTests.NewsCount - i), searchResultsController.Model.Results.Data[i].GetValue("Title"));
                }
            }
            finally
            {
                Telerik.Sitefinity.TestUtilities.CommonOperations.ServerOperations.Search().DeleteAllIndexes();
            }
        }
        public void SearchResultsWidget_DefaultLanguage_NoResultsFound()
        {
            Guid searchIndex1Id = Guid.Empty;
            try
            {
                searchIndex1Id = SitefinityOperations.ServerOperations.Search().CreateSearchIndex(SearchResultsWidgetTests.SearchIndexName, new[] { SitefinityOperations.SearchContentType.Pages, SitefinityOperations.SearchContentType.News });
                SitefinityOperations.ServerOperations.Search().Reindex(searchIndex1Id);

                int index = 1;
                string testName = System.Reflection.MethodInfo.GetCurrentMethod().Name;
                string pageNamePrefix = testName + "NewsPage" + index;
                string pageTitlePrefix = testName + "NewsPage" + index;
                string urlNamePrefix = testName + "news-page" + index;

                string orderBy = "Oldest";
                string searchString = "TestEvents";
                int expectedCount = 0;
                var searchResultsController = new SearchResultsController();

                var mvcProxy = new MvcControllerProxy();
                mvcProxy.ControllerName = typeof(NewsController).FullName;
                var newsController = new NewsController();
                mvcProxy.Settings = new ControllerSettings(newsController);

                this.pageOperations.CreatePageWithControl(mvcProxy, pageNamePrefix, pageTitlePrefix, urlNamePrefix, index);

                searchResultsController.Index(null, searchString, SearchResultsWidgetTests.SearchIndexName, null, null, orderBy);

                Assert.AreEqual(expectedCount, searchResultsController.Model.Results.TotalCount);
            }
            finally
            {
                Telerik.Sitefinity.TestUtilities.CommonOperations.ServerOperations.Search().DeleteAllIndexes();
            }
        }
        public void NewsWidget_VerifySortNewsDescending()
        {
            string sortExpession = "Title DESC";
            string[] newsTitles = { "Cat", "Boat", "Angel" };

            var newsController = new NewsController();
            newsController.Model.DisplayMode = ListDisplayMode.Limit;
            newsController.Model.SortExpression = sortExpession;

            for (int i = 0; i < newsTitles.Length; i++)
                Telerik.Sitefinity.TestUtilities.CommonOperations.ServerOperations.News().CreateNewsItem(newsTitles[i]);

            var items = newsController.Model.CreateListViewModel(null, 1).Items.ToArray();

            int lastIndex = 0;
            for (int i = 0; i < newsTitles.Length; i++)
            {
                Assert.IsTrue(items[i].Fields.Title.Equals(newsTitles[lastIndex]), "The news with this title was not found!");
                lastIndex++;
            }
        }
        public void NewsWidget_SelectByCategoryNewsFunctionality()
        {
            int newsCount = 4;
            string newsTitle = "Title";
            string categoryTitle = "Category ";
            var newsController = new NewsController();
            string[] categoryTitles = new string[newsCount + 1];

            try
            {
                this.serverOperationsTaxonomies.CreateCategory(categoryTitle + "0");

                for (int i = 0; i <= newsCount; i++)
                {
                    categoryTitles[i] = categoryTitle + i;
                    this.serverOperationsTaxonomies.CreateCategory(categoryTitle + (i + 1), categoryTitle + i);
                    ServerOperationsFeather.NewsOperations().CreatePublishedNewsItem(NewsTitle + i, "Content", "AuthorName", "SourceName", new List<string> { categoryTitle + i }, null, null);
                }

                TaxonomyManager taxonomyManager = TaxonomyManager.GetManager();

                for (int i = 0; i < newsCount; i++)
                {
                    var category = taxonomyManager.GetTaxa<HierarchicalTaxon>().SingleOrDefault(t => t.Title == categoryTitle + i);
                    ITaxon taxonomy = taxonomyManager.GetTaxon(category.Id);
                    var items = newsController.Model.CreateListViewModel(taxonomy, 1).Items.ToArray();

                    for (int j = 0; j < items.Length; j++)
                        Assert.IsTrue(items[j].Fields.Title.Equals(newsTitle + i, StringComparison.CurrentCulture), "The news with this title was not found!");
                }
            }
            finally
            {
                this.serverOperationsTaxonomies.DeleteCategories(categoryTitles);
            }
        }
        public void NewsWidget_SelectByCategoryNewsFunctionalityAndLimits()
        {
            var newsController = new NewsController();
            newsController.Model.DisplayMode = ListDisplayMode.Limit;
            int itemsPerPage = 3;
            newsController.Model.ItemsPerPage = itemsPerPage;
            string categoryTitle = "Category";
            string[] newsTitles = { "Boat", "Cat", "Angel", "Kitty", "Dog" };
            Guid[] newsId = new Guid[newsTitles.Count()];

            try
            {
                this.serverOperationsTaxonomies.CreateCategory(categoryTitle + "0");
                this.serverOperationsTaxonomies.CreateCategory(categoryTitle + "1", categoryTitle + "0");

                TaxonomyManager taxonomyManager = TaxonomyManager.GetManager();
                var category0 = taxonomyManager.GetTaxa<HierarchicalTaxon>().SingleOrDefault(t => t.Title == categoryTitle + "0");
                var category1 = taxonomyManager.GetTaxa<HierarchicalTaxon>().SingleOrDefault(t => t.Title == categoryTitle + "1");

                for (int i = 0; i < newsTitles.Count(); i++)
                {
                    if (i <= 3)
                    {
                        newsId[i] = this.serverOperationsNews.CreatePublishedNewsItem(newsTitles[i]);
                        this.serverOperationsNews.AssignTaxonToNewsItem(newsId[i], "Category", category0.Id);
                    }
                    else
                    {
                        newsId[i] = this.serverOperationsNews.CreatePublishedNewsItem(newsTitles[i]);
                        this.serverOperationsNews.AssignTaxonToNewsItem(newsId[i], "Category", category1.Id);
                    }
                }

                ITaxon taxonomy = taxonomyManager.GetTaxon(category0.Id);
                var items = newsController.Model.CreateListViewModel(taxonomy, 1).Items.ToArray();

                Assert.IsTrue(items.Length.Equals(3), "Number of news items is not correct");
                for (int i = 0; i <= 2; i++)
                {
                    Assert.IsTrue(items[i].Fields.Title.Equals(newsTitles[3 - i], StringComparison.CurrentCulture), "The news with this title was found!");
                }

                taxonomy = taxonomyManager.GetTaxon(category1.Id);
                items = newsController.Model.CreateListViewModel(taxonomy, 1).Items.ToArray();

                Assert.IsTrue(items.Length.Equals(1), "Number of news items is not correct");
                Assert.IsTrue(items[0].Fields.Title.Equals(newsTitles[4], StringComparison.CurrentCulture), "The news with this title was found!");

                newsController.Model.DisplayMode = ListDisplayMode.All;
                taxonomy = taxonomyManager.GetTaxon(category0.Id);
                items = newsController.Model.CreateListViewModel(taxonomy, 1).Items.ToArray();

                Assert.IsTrue(items.Length.Equals(4), "Number of news items is not correct");
                for (int i = 0; i <= 3; i++)
                {
                    Assert.IsTrue(items[i].Fields.Title.Equals(newsTitles[3 - i], StringComparison.CurrentCulture), "The news with this title was found!");
                }

                taxonomy = taxonomyManager.GetTaxon(category1.Id);
                items = newsController.Model.CreateListViewModel(taxonomy, 1).Items.ToArray();

                Assert.IsTrue(items.Length.Equals(1), "Number of news items is not correct");
                Assert.IsTrue(items[0].Fields.Title.Equals(newsTitles[4], StringComparison.CurrentCulture), "The news with this title was found!");
            }
            finally
            {
                this.serverOperationsTaxonomies.DeleteCategories("Category0", "Category1");
            }
        }