public void GetItemsByTemplateIdTest() { var itemObject = _clientObject.GetItemsByTemplateId(_configData.TemplateId, _configData.ProjectId); Assert.IsNotNull(itemObject); CollectionAssert.AllItemsAreUnique(itemObject.ToList()); CollectionAssert.AllItemsAreNotNull(itemObject.ToList()); }
public void GetItemsByTemplateId_InvalidCredential() { var invalidCredential = new GcConnectClient("abc", _configData.Email); var itemObject = invalidCredential.GetItemsByTemplateId(0000, 14041); Assert.IsNotNull(itemObject); Assert.AreEqual(itemObject.Count, 0); }
private void PopulateForm() { // Set the project and template Ids from query string. Session["TemplateId"] = Server.UrlDecode(Request.QueryString["TemplateId"]); Session["ProjectId"] = Server.UrlDecode(Request.QueryString["ProjectId"]); // If the DDS for credentials is null or empty, turn off the page visibility and alert the user to set up the config. if (_credentialsStore.IsNullOrEmpty()) { Response.Write("<script>alert('Please setup your GatherContent config first!');" + "window.location='/modules/GcEpiPlugin/GatherContentConfigSetup.aspx'</script>"); Visible = false; return; } // This is to validate the user to not access this page directly. if (Session["TemplateId"] == null || Session["ProjectId"] == null) { Response.Write("<script>alert('This page is not directly accessible! Review your GatherContent items from Template Mappings page!');" + "window.location='/modules/GcEpiPlugin/GcEpiTemplateMappings.aspx'</script>"); Visible = false; return; } // Local variables initialization and setting the values for some of the form components. Client = new GcConnectClient(_credentialsStore.First().ApiKey, _credentialsStore.First().Email); // This is to make sure we only fetch mappings associated with this GcAccount. _mappingsStore = GcDynamicUtilities.RetrieveStore <GcDynamicTemplateMappings>(). FindAll(i => i.AccountId == _credentialsStore.First().AccountId); // Fetch the mapping for current template. var currentMapping = _mappingsStore.First(i => i.TemplateId == Session["TemplateId"].ToString()); // Make a usable templateId and projectId var templateId = Convert.ToInt32(Session["TemplateId"]); var projectId = Convert.ToInt32(Session["ProjectId"]); // Fetch Template details from GatherContentConnect. var gcTemplate = Client.GetTemplateById(templateId); // Set the labels with the gathered values. templateName.Text = gcTemplate.Name; projectName.Text = Client.GetProjectById(projectId).Name; templateDescription.Text = gcTemplate.Description; // Fetch the items (if there are any) from trash. var recycleBin = _contentRepository.GetDescendents(ContentReference.WasteBasket).ToList(); // This is to make sure that the drop down doesn't persist previous values upon page refresh. ddlDefaultParent.Items.Clear(); // Create an empty list to store all the content descendants. List <IContent> sortedDescendants = new EditableList <IContent>(); // Populating the default parent selection drop down based on the type of the post type. switch (currentMapping.PostType) { case "PageType": // Add the root parent before everything else. ddlDefaultParent.Items.Add(new ListItem("Root", "1")); SortContent <PageData>(_contentRepository.Get <PageData>(ContentReference.RootPage), sortedDescendants); foreach (var pageData in sortedDescendants) { // If the page is in recycle bin or if the page itself is recycle bin, // Then do not add it to the drop down. if (recycleBin.Contains(pageData.ContentLink) || pageData.ContentLink.ID == 2) { continue; } // Fetch the page data of its immediate parent. var parentPage = _contentRepository.Get <PageData>(pageData.ParentLink); // Add the parent's name along with the page name to avoid the confusion between the same page names. ddlDefaultParent.Items.Add(new ListItem(parentPage.Name + " => " + pageData.Name, pageData.ContentLink.ID.ToString())); } break; case "BlockType": // Add the root parent before everything else. ddlDefaultParent.Items.Add(new ListItem("SysGlobalAssets", "3")); SortContent <ContentFolder>(_contentRepository.Get <ContentFolder>(ContentReference.GlobalBlockFolder), sortedDescendants); foreach (var contentFolder in sortedDescendants) { // If the block is in recycle bin, // Then do not add it to the drop down. if (recycleBin.Contains(contentFolder.ContentLink)) { continue; } // Fetch the block data of its immediate parent. var parentFolder = _contentRepository.Get <ContentFolder>(contentFolder.ParentLink); // Add the parent's name along with the block name to avoid the confusion between the same block names. ddlDefaultParent.Items.Add(new ListItem(parentFolder.Name + " => " + contentFolder.Name, contentFolder.ContentLink.ID.ToString())); } break; } // Add the data source to the repeater and bind it. rptGcItems.DataSource = Client.GetItemsByTemplateId(templateId, projectId); rptGcItems.DataBind(); }
private void PopulateForm() { var credentialsStore = GcDynamicCredentials.RetrieveStore(); Session["TemplateId"] = Server.UrlDecode(Request.QueryString["TemplateId"]); Session["ProjectId"] = Server.UrlDecode(Request.QueryString["ProjectId"]); if (credentialsStore.IsNullOrEmpty()) { Response.Write("<script>alert('Please setup your GatherContent config first!');window.location='/modules/GatherContentImport/GatherContent.aspx'</script>"); Visible = false; return; } if (Session["TemplateId"] == null || Session["ProjectId"] == null) { Response.Write("<script>alert('This page is not directly accessible! Review your GatherContent items from Template Mappings page!');window.location='/modules/GatherContentImport/GcEpiTemplateMappings.aspx'</script>"); Visible = false; return; } var currentMapping = GcDynamicTemplateMappings .RetrieveStore().First(i => i.TemplateId == Session["TemplateId"].ToString()); Client = new GcConnectClient(credentialsStore.ToList().First().ApiKey, credentialsStore.ToList().First().Email); var templateId = Convert.ToInt32(Session["TemplateId"]); var gcTemplate = Client.GetTemplateById(templateId); templateName.Text = gcTemplate.Name; var projectId = Convert.ToInt32(Session["ProjectId"]); projectName.Text = Client.GetProjectById(projectId).Name; templateDescription.Text = gcTemplate.Description; var contentRepository = ServiceLocator.Current.GetInstance <IContentRepository>(); var recycleBin = contentRepository.GetDescendents(ContentReference.Parse("2")).ToList(); switch (currentMapping.PostType) { case "PageType": ddlDefaultParent.Items.Add(new ListItem("Root Page", "1")); foreach (var cr in contentRepository.GetDescendents(ContentReference.RootPage)) { try { var pageData = contentRepository.Get <PageData>(cr); if (recycleBin.Contains(pageData.ContentLink) || pageData.ContentLink.ID == 2) { continue; } ddlDefaultParent.Items.Add(new ListItem(pageData.PageName, pageData.ContentLink.ID.ToString())); } catch (TypeMismatchException ex) { Console.WriteLine(ex); } } break; case "BlockType": // Add the root parent before everything else. ddlDefaultParent.Items.Add(new ListItem("SysGlobalAssets", "3")); foreach (var cr in contentRepository.GetDescendents(ContentReference.Parse("3"))) { try { var blockData = contentRepository.Get <ContentFolder>(cr); // ReSharper disable once SuspiciousTypeConversion.Global var content = blockData as IContent; // If the block is in recycle bin, // Then do not add it to the drop down. if (recycleBin.Contains(content.ContentLink)) { continue; } // ReSharper disable once PossibleNullReferenceException if (recycleBin.Contains(content.ContentLink) || content.ContentLink.ID == 2) { continue; } ddlDefaultParent.Items.Add(new ListItem(content.Name, content.ContentLink.ID.ToString())); } catch (TypeMismatchException ex) { Console.WriteLine(ex); } } break; } rptGcItems.DataSource = Client.GetItemsByTemplateId(templateId, projectId); rptGcItems.DataBind(); }