Exemplo n.º 1
0
        public void CanFollowAllAuthorsAndGetAllEMails()
        {
            // Arrange
            HashSet <string> foundEMails = new HashSet <string>();
            Request          blogRequest = Session.Bind(BlogRootPath);

            // Act ...

            // - GET blog
            using (var r = blogRequest.Get <Resources.Blog>())
            {
                Resources.Blog blog = r.Body;
                foreach (Resources.Blog.Post post in blog.Posts)
                {
                    // - GET post
                    using (var fullPost = post.Links.Select("self").Follow(Session).Get <Resources.Post>())
                    {
                        // - Follow author link
                        using (var author = fullPost.Body.Links.Select("author").Follow(Session).Get <Resources.Author>())
                        {
                            // - Register e-mail
                            foundEMails.Add(author.Body.EMail);
                        }
                    }
                }

                // Assert ...
                Assert.AreEqual(2, foundEMails.Count);
                Assert.IsTrue(foundEMails.Contains("*****@*****.**"));
                Assert.IsTrue(foundEMails.Contains("*****@*****.**"));
            }
        }
Exemplo n.º 2
0
        public void CanFollowAuthorLinkFromBlog()
        {
            // Arrange
            Request blogRequest = Session.Bind(BlogRootPath);

            // Act ...

            // - GET blog
            using (var response = blogRequest.Get <Resources.Blog>())
            {
                Resources.Blog blog = response.Body;

                // - Fetch author link
                ILink authorLink = blog.Links.Select("author");

                // - Follow author link and get author data
                using (var author = authorLink.Follow(Session).Get <Resources.Author>())
                {
                    // Assert ...
                    Assert.IsNotNull(author.Body);

                    // - Check e-mail of author
                    Assert.AreEqual("Pete Peterson", author.Body.Name);
                    Assert.AreEqual("*****@*****.**", author.Body.EMail);
                }
            }
        }
Exemplo n.º 3
0
        public void CanAddNewBlogItemIncludingImage()
        {
            // Arrange
            Request blogRequest = Session.Bind(BlogRootPath);

            // Act ...

            // - GET blog
            Resources.Blog blog = blogRequest.Get <Resources.Blog>().Body;

            // - Follow "edit" link and GET form describing how to input
            Response <Resources.CreatePostDescriptor> createDescriptor
                = blog.Links.Select("edit").Follow(Session).Get <Resources.CreatePostDescriptor>();

            // - Extract "create" form
            IKeyValueForm form = createDescriptor.Body.Form;

            // - Populate form inputs
            Resources.CreatePostArgs args = new Resources.CreatePostArgs
            {
                Title = "New item",
                Text  = "Yaj!",
                Image = new File("..\\..\\data1.gif", "image/gif")
            };
            form.Value(args);

            // - Submit the form
            Resources.Post createdPost = form.Bind().Submit <Resources.Post>().Created();

            // Assert ...
            Assert.IsNotNull(createdPost);
            Assert.AreEqual("New item", createdPost.Title);
            Assert.AreEqual("Yaj!", createdPost.Text);
        }
Exemplo n.º 4
0
        ILink GetSearchLink()
        {
            Request blogRequest = Session.Bind(BlogRootPath);

            Resources.Blog blog       = blogRequest.Get <Resources.Blog>().Body;
            ILink          searchLink = blog.Links.Select("search", "application/opensearchdescription+xml");

            return(searchLink);
        }
Exemplo n.º 5
0
        public void CanGetSearchLinkFromBlog()
        {
            // Arrange
            Request blogRequest = Session.Bind(BlogRootPath);

            // Act - get blog resource and select Open Search link
            Resources.Blog blog       = blogRequest.Get <Resources.Blog>().Body;
            ILink          searchLink = blog.Links.Select("search", "application/opensearchdescription+xml");

            // Assert
            Assert.IsNotNull(searchLink);
        }
Exemplo n.º 6
0
        public void CanLoadBlog()
        {
            // Arrange
            Request blogRequest = Session.Bind(BlogRootPath);

            // Act
            Resources.Blog blog = blogRequest.Get <Resources.Blog>().Body;

            // Assert ...
            Assert.IsNotNull(blog);
            Assert.AreEqual("A mixed blog", blog.Title);
            Assert.IsNotNull(blog.Posts);
            Assert.AreEqual(2, blog.Posts.Count);

            // - Check content of first post
            Resources.Blog.Post post1 = blog.Posts[0];
            Assert.IsNotNull(post1);
            Assert.AreEqual("Hot summer", post1.Title);
            Assert.AreEqual("It is a hot summer this year.", post1.Text);
        }