public PageCheckResult PageResponseValid(string baseUrl, SitecoreItem sitecoreItem)
        {
            Uri pageUrl = GeneratePageUrl(baseUrl, sitecoreItem);

            Driver.Navigate().GoToUrl(pageUrl);
            Driver.Manage().Window.Maximize();

            IWebElement header = Driver.FindElement(By.TagName("head"));

            IWebElement body = Driver.FindElement(By.TagName("body"));

            Screenshot screenShot = ((ITakesScreenshot)Driver).GetScreenshot();

            if (screenShot != null)
            {
                screenShot.SaveAsFile(GenerateScreenShotFileName(sitecoreItem), ScreenshotImageFormat.Png);
            }

            if (header == null || body == null)
            {
                return(new PageCheckResult {
                    Success = false
                });
            }

            return(new PageCheckResult {
                Success = true
            });
        }
        public void Service_client_handles_multiple_child_nodes_with_no_children()
        {
            // Arrange
            var configurationParameters = new ConfigurationParameters
            {
                BaseUrl    = "http://baseurl.com",
                RootNodeId = Guid.NewGuid()
            };
            var restClient = new Mock <IRestClient>();

            var rootNode = new SitecoreItem
            {
                DisplayName = "display name",
                HasChildren = false,
                ItemID      = Guid.NewGuid(),
                ItemPath    = "/path/to/item",
                ExternalUrl = "/item/root"
            };

            var itemList = new List <SitecoreItem>
            {
                new SitecoreItem
                {
                    DisplayName = "display name",
                    HasChildren = false,
                    ItemID      = Guid.NewGuid(),
                    ItemPath    = "/path/to/item",
                    ExternalUrl = "/item/url"
                },
                new SitecoreItem
                {
                    DisplayName = "display name 2",
                    HasChildren = false,
                    ItemID      = Guid.NewGuid(),
                    ItemPath    = "/path/to/item2",
                    ExternalUrl = "/item/url2"
                }
            };

            var rootResponse = new RestResponse <SitecoreItem> {
                Data = rootNode, StatusCode = HttpStatusCode.OK
            };

            var response = new RestResponse <List <SitecoreItem> > {
                Data = itemList, StatusCode = HttpStatusCode.OK
            };

            restClient.Setup(x => x.Execute <SitecoreItem>(It.IsAny <IRestRequest>())).Returns(rootResponse);

            restClient.Setup(x => x.Execute <List <SitecoreItem> >(It.IsAny <IRestRequest>())).Returns(response);

            var serviceClient = new SitecoreItemServiceClient(restClient.Object, configurationParameters);

            // Act
            var urlList = serviceClient.GetSitecoreCmsTreeUrls();

            // Assert
            Assert.IsNotNull(urlList);
            Assert.AreEqual(3, urlList.Count);
        }
        public List <SitecoreItem> Run()
        {
            var sitecoreItemList = new List <SitecoreItem>();

            var fileStream = File.OpenRead(Config.InputFileName);

            var reader = new StreamReader(fileStream);

            reader.ReadLine();  // Skip headers

            string line = string.Empty;

            while ((line = reader.ReadLine()) != null)
            {
                string[] segments     = line.Split(',');
                var      sitecoreItem = new SitecoreItem
                {
                    ItemPath    = segments[1],
                    ItemID      = new Guid(segments[2]),
                    ItemName    = segments[3],
                    HasChildren = Convert.ToBoolean(segments[4]),
                    DisplayName = segments[5],
                    ExternalUrl = segments[6]
                };
                sitecoreItemList.Add(sitecoreItem);
            }

            return(sitecoreItemList);
        }
        public void Service_client_handles_login_and_logout_if_credentials_specified()
        {
            // Arrange
            var configurationParameters = new ConfigurationParameters
            {
                BaseUrl    = "http://baseurl.com",
                RootNodeId = Guid.NewGuid(),
                Domain     = "sitecore",
                UserName   = "******",
                Password   = "******"
            };

            var restClient = new Mock <IRestClient>();

            var loginResponse = new RestResponse <LoginResult> {
                Data = new LoginResult(), StatusCode = HttpStatusCode.OK
            };

            restClient.Setup(x => x.Execute <LoginResult>(It.IsAny <IRestRequest>())).Returns(loginResponse).Verifiable();

            var rootNode = new SitecoreItem
            {
                DisplayName = "display name",
                HasChildren = false,
                ItemID      = Guid.NewGuid(),
                ItemPath    = "/path/to/item",
                ExternalUrl = "/item/root"
            };

            var rootResponse = new RestResponse <SitecoreItem> {
                Data = rootNode, StatusCode = HttpStatusCode.OK
            };

            restClient.Setup(x => x.Execute <SitecoreItem>(It.IsAny <IRestRequest>())).Returns(rootResponse);

            var response = new RestResponse <List <SitecoreItem> > {
                Data = new List <SitecoreItem>(), StatusCode = HttpStatusCode.OK
            };

            restClient.Setup(x => x.Execute <List <SitecoreItem> >(It.IsAny <IRestRequest>())).Returns(response);

            var logoutResponse = new RestResponse <LogoutResult> {
                Data = new LogoutResult(), StatusCode = HttpStatusCode.OK
            };

            restClient.Setup(x => x.Execute <LogoutResult>(It.IsAny <IRestRequest>())).Returns(logoutResponse).Verifiable();

            var serviceClient = new SitecoreItemServiceClient(restClient.Object, configurationParameters);

            // Act
            var sitecoreItems = serviceClient.GetSitecoreCmsTreeUrls();

            // Assert
            Assert.AreEqual(1, sitecoreItems.Count);
            Assert.IsFalse(sitecoreItems[0].HasChildren);
            restClient.VerifyAll();
        }
예제 #5
0
        /// <summary>
        /// Gets the calculated namespace for the template
        /// </summary>
        /// <param name="defaultNamespace">
        /// The default Namespace.
        /// </param>
        /// <param name="item">
        /// The item.
        /// </param>
        /// <param name="includeGlobal">
        /// The include Global.
        /// </param>
        /// <returns>
        /// The namespace of the supplied item.
        /// </returns>
        public static string GetNamespace(string defaultNamespace, SitecoreItem item, bool includeGlobal = false)
        {
            var namespaceSegments = new HashSet <string>
            {
                item.Namespace
            };

            ////namespaceSegments.Add(defaultNamespace);
            var @namespace = namespaceSegments.AsNamespace().Replace(".sitecore.templates", string.Empty);             // use an extension method in the supporting assembly

            return(includeGlobal ? string.Concat("global::", @namespace) : @namespace);
        }
        public Comment(XmlNode xn)
        {
            if (xn != null)
            {
                XmlNode author = xn.SelectSingleNode("User");

                string   commentId   = xn["CommentId"].InnerText;
                string   commentDate = xn["CreatedDate"].InnerText;
                DateTime parsedDate  = DateTime.Parse(commentDate);

                Id = commentId;



                //Url = xn["Url"].InnerText;
                //   ParentId = xn["ParentId"].InnerText;
                //   ContentId = xn["ContentId"].InnerText;
                IsApproved           = xn["IsApproved"].InnerText;
                ReplyCount           = xn["ReplyCount"].InnerText;
                CommentId            = commentId;
                CommentContentTypeId = xn["CommentContentTypeId"].InnerText;
                Body              = xn["Body"].InnerText;
                PublishedDate     = UnderstoodDotOrg.Common.Helpers.DataFormatHelper.FormatDate(commentDate);
                AuthorId          = author["Id"].InnerText;
                AuthorAvatarUrl   = author["AvatarUrl"].InnerText;
                AuthorDisplayName = author["DisplayName"].InnerText;
                AuthorProfileUrl  = author["ProfileUrl"].InnerText;
                AuthorUsername    = author["Username"].InnerText;
                Likes             = CommunityHelper.GetTotalLikes(commentId).ToString();
                CommentDate       = parsedDate;
                ParentTitle       = xn["Content"]["Application"]["Container"]["HtmlName"].InnerText;
                CommentTitle      = xn["Content"]["HtmlName"].InnerText;
                SitecoreItemId    = CommentTitle.Substring(CommentTitle.IndexOf("{"));
                if (!string.IsNullOrEmpty(SitecoreItemId))
                {
                    CommentTitle = CommentTitle.Replace(SitecoreItemId, "");
                }
                SitecoreItem = !string.IsNullOrEmpty(SitecoreItemId) ?
                               Sitecore.Context.Database.GetItem(SitecoreItemId) :
                               null;
                Type = xn["Content"]["Application"]["HtmlName"].InnerText;
                Url  = SitecoreItem != null?SitecoreItem.GetUrl() : "/";
            }
        }
예제 #7
0
        public PageCheckResult PageResponseValid(string baseUrl, SitecoreItem sitecoreItem)
        {
            try
            {
                Uri pageUrl        = GeneratePageUrl(baseUrl, sitecoreItem);
                var httpWebRequest = RequestFactory.Create(pageUrl.AbsoluteUri);
                httpWebRequest.AllowAutoRedirect = false;
                var response = (HttpWebResponse)httpWebRequest.GetResponse();

                bool success = (response.StatusCode == HttpStatusCode.OK ||
                                response.StatusCode == HttpStatusCode.Moved ||
                                response.StatusCode == HttpStatusCode.Redirect);

                return(new HttpPageCheckResult {
                    Success = success, StatusCode = response.StatusCode
                });
            }
            catch (WebException webException)
            {
                if (webException.Status == WebExceptionStatus.Timeout)
                {
                    return(new HttpPageCheckResult {
                        Success = false, StatusCode = HttpStatusCode.RequestTimeout
                    });
                }

                HttpWebResponse exceptionResponse = (HttpWebResponse)webException.Response;
                if (exceptionResponse != null)
                {
                    return(new HttpPageCheckResult {
                        Success = false, StatusCode = exceptionResponse.StatusCode
                    });
                }
                return(new HttpPageCheckResult {
                    Success = false, StatusCode = HttpStatusCode.BadRequest
                });
            }
        }
        private string GenerateScreenShotFileName(SitecoreItem sitecoreItem)
        {
            string fileName = sitecoreItem.ItemPath.Replace('/', '-');

            return($"{ScreenShotsFolder}\\{fileName}.png");
        }
예제 #9
0
 protected Uri GeneratePageUrl(string baseUrl, SitecoreItem sitecoreItem)
 {
     return(new Uri($"{baseUrl}/{sitecoreItem.ExternalUrl}"));
 }
예제 #10
0
 /// <summary>
 /// Gets the fully qualified name of the supplied Sitecore Item.
 /// </summary>
 /// <param name="defaultNamespace">
 /// The default namespace.
 /// </param>
 /// <param name="item">
 /// The template.
 /// </param>
 /// <param name="methodName">
 /// The function to run the template name through.
 /// </param>
 /// <returns>
 /// The <see cref="string"/>.
 /// </returns>
 public static string GetFullyQualifiedName(string defaultNamespace, SitecoreItem item, Func <string, string> methodName)
 {
     return(string.Concat(GetNamespace(defaultNamespace, item, true), ".", methodName(item.Name)));
 }
예제 #11
0
 /// <summary>
 /// Gets the fully qualified name of the supplied Sitecore Item.
 /// </summary>
 /// <param name="defaultNamespace">
 /// The default namespace.
 /// </param>
 /// <param name="item">
 /// The template item.
 /// </param>
 /// <returns>
 /// The namespace string of the Item.
 /// </returns>
 public static string GetFullyQualifiedName(string defaultNamespace, SitecoreItem item)
 {
     return(GetFullyQualifiedName(defaultNamespace, item, s => s));
 }
		/// <summary>
		/// Gets the calculated namespace for the template
		/// </summary>
		/// <param name="defaultNamespace">
		/// The default Namespace.
		/// </param>
		/// <param name="item">
		/// The item.
		/// </param>
		/// <param name="includeGlobal">
		/// The include Global.
		/// </param>
		/// <returns>
		/// The namespace of the supplied item.
		/// </returns>
		public static string GetNamespace(string defaultNamespace, SitecoreItem item, bool includeGlobal = false)
		{
			var namespaceSegments = new HashSet<string>
			                            {
			                                item.Namespace
			                            };

			////namespaceSegments.Add(defaultNamespace);
			var @namespace = namespaceSegments.AsNamespace().Replace(".sitecore.templates", string.Empty); // use an extension method in the supporting assembly

			return includeGlobal ? string.Concat("global::", @namespace) : @namespace;
		}
		/// <summary>
		/// Gets the fully qualified name of the supplied Sitecore Item.
		/// </summary>
		/// <param name="defaultNamespace">
		/// The default namespace.
		/// </param>
		/// <param name="item">
		/// The template.
		/// </param>
		/// <param name="methodName">
		/// The function to run the template name through.
		/// </param>
		/// <returns>
		/// The <see cref="string"/>.
		/// </returns>
		public static string GetFullyQualifiedName(string defaultNamespace, SitecoreItem item, Func<string, string> methodName)
		{
			return string.Concat(GetNamespace(defaultNamespace, item, true), ".", methodName(item.Name));
		}
		/// <summary>
		/// Gets the fully qualified name of the supplied Sitecore Item.
		/// </summary>
		/// <param name="defaultNamespace">
		/// The default namespace.
		/// </param>
		/// <param name="item">
		/// The template item.
		/// </param>
		/// <returns>
		/// The namespace string of the Item.
		/// </returns>
		public static string GetFullyQualifiedName(string defaultNamespace, SitecoreItem item)
		{
			return GetFullyQualifiedName(defaultNamespace, item, s => s);
		}
        public void Service_client_handles_multiple_levels_of_children()
        {
            // Arrange
            var configurationParameters = new ConfigurationParameters
            {
                BaseUrl    = "http://baseurl.com",
                RootNodeId = Guid.NewGuid()
            };

            var restClient = new Mock <IRestClient>();

            var rootItem = new SitecoreItem
            {
                DisplayName = "display name",
                HasChildren = true,
                ItemID      = Guid.NewGuid(),
                ItemPath    = "/path/to/item",
                ExternalUrl = "/item/root"
            };

            var rootResponse = new RestResponse <SitecoreItem> {
                Data = rootItem, StatusCode = HttpStatusCode.OK
            };

            var topLevelItemList = new List <SitecoreItem>
            {
                new SitecoreItem
                {
                    DisplayName = "display name",
                    HasChildren = true,
                    ItemID      = Guid.NewGuid(),
                    ItemPath    = "/path/to/item",
                    ExternalUrl = "/item/url"
                },
                new SitecoreItem
                {
                    DisplayName = "display name 2",
                    HasChildren = true,
                    ItemID      = Guid.NewGuid(),
                    ItemPath    = "/path/to/item2",
                    ExternalUrl = "/item/url2"
                }
            };

            var topLevelResponse = new RestResponse <List <SitecoreItem> > {
                Data = topLevelItemList, StatusCode = HttpStatusCode.OK
            };

            var firstChildItemList = new List <SitecoreItem>
            {
                new SitecoreItem
                {
                    DisplayName = "display name child 1",
                    HasChildren = false,
                    ItemID      = Guid.NewGuid(),
                    ItemPath    = "/path/to/item/child1",
                    ExternalUrl = "/item/url/child1"
                },
                new SitecoreItem
                {
                    DisplayName = "display name child 2",
                    HasChildren = true,
                    ItemID      = Guid.NewGuid(),
                    ItemPath    = "/path/to/item/child2",
                    ExternalUrl = "/item/url/child2"
                }
            };

            var firstChildResponse = new RestResponse <List <SitecoreItem> > {
                Data = firstChildItemList, StatusCode = HttpStatusCode.OK
            };

            var child2ChildrenItemList = new List <SitecoreItem>
            {
                new SitecoreItem
                {
                    DisplayName = "display name sub child 1",
                    HasChildren = false,
                    ItemID      = Guid.NewGuid(),
                    ItemPath    = "/path/to/item/child2/item1",
                    ExternalUrl = "/item/url/child2/subchild1"
                },
                new SitecoreItem
                {
                    DisplayName = "display name sub child 2",
                    HasChildren = false,
                    ItemID      = Guid.NewGuid(),
                    ItemPath    = "/path/to/item/child2/item2",
                    ExternalUrl = "/item/url/child2/subchild2"
                }
            };

            var child2ChildrenResponse = new RestResponse <List <SitecoreItem> > {
                Data = child2ChildrenItemList, StatusCode = HttpStatusCode.OK
            };

            var secondChildItemList = new List <SitecoreItem>
            {
                new SitecoreItem
                {
                    DisplayName = "display name child 3",
                    HasChildren = true,
                    ItemID      = Guid.NewGuid(),
                    ItemPath    = "/path/to/item/child1",
                    ExternalUrl = "/item/url2/child3"
                },
                new SitecoreItem
                {
                    DisplayName = "display name child 4",
                    HasChildren = false,
                    ItemID      = Guid.NewGuid(),
                    ItemPath    = "/path/to/item/child2",
                    ExternalUrl = "/item/url2/child4"
                }
            };

            var secondChildResponse = new RestResponse <List <SitecoreItem> > {
                Data = secondChildItemList, StatusCode = HttpStatusCode.OK
            };

            var child3ChildrenItemList = new List <SitecoreItem>
            {
                new SitecoreItem
                {
                    DisplayName = "display name sub child 1",
                    HasChildren = false,
                    ItemID      = Guid.NewGuid(),
                    ItemPath    = "/path/to/item/child3/item1",
                    ExternalUrl = "/item/url/child3/subchild1"
                },
                new SitecoreItem
                {
                    DisplayName = "display name sub child 2",
                    HasChildren = false,
                    ItemID      = Guid.NewGuid(),
                    ItemPath    = "/path/to/item/child3/item2",
                    ExternalUrl = "/item/url/child3/subchild2"
                }
            };

            var child3ChildrenResponse = new RestResponse <List <SitecoreItem> > {
                Data = child3ChildrenItemList, StatusCode = HttpStatusCode.OK
            };

            restClient.Setup(x => x.Execute <SitecoreItem>(It.IsAny <IRestRequest>())).Returns(rootResponse);

            restClient.Setup(x => x.Execute <List <SitecoreItem> >(It.IsAny <IRestRequest>()))
            .ReturnsInOrder(topLevelResponse, firstChildResponse, child2ChildrenResponse, secondChildResponse, child3ChildrenResponse);

            var serviceClient = new SitecoreItemServiceClient(restClient.Object, configurationParameters);

            // Act
            var urlList = serviceClient.GetSitecoreCmsTreeUrls().ToArray();

            // Assert
            Assert.IsNotNull(urlList);
            Assert.AreEqual(11, urlList.Length);
            Assert.AreEqual("/item/root", urlList[0].ExternalUrl);
            Assert.AreEqual("/item/url", urlList[1].ExternalUrl);
            Assert.AreEqual("/item/url/child1", urlList[2].ExternalUrl);
            Assert.AreEqual("/item/url/child2", urlList[3].ExternalUrl);
            Assert.AreEqual("/item/url/child2/subchild1", urlList[4].ExternalUrl);
            Assert.AreEqual("/item/url/child2/subchild2", urlList[5].ExternalUrl);
            Assert.AreEqual("/item/url2", urlList[6].ExternalUrl);
            Assert.AreEqual("/item/url2/child3", urlList[7].ExternalUrl);
            Assert.AreEqual("/item/url/child3/subchild1", urlList[8].ExternalUrl);
            Assert.AreEqual("/item/url/child3/subchild2", urlList[9].ExternalUrl);
            Assert.AreEqual("/item/url2/child4", urlList[10].ExternalUrl);
        }