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

            // Act ...

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

            foreach (Resources.Blog.Post post in blog.Posts)
            {
                // - GET post
                Resources.Post fullPost = post.Links.Select("self").Follow(Session).Get <Resources.Post>().Body;

                // - Follow author link
                Resources.Author author = fullPost.Links.Select("author").Follow(Session).Get <Resources.Author>().Body;

                // - Register e-mail
                foundEMails.Add(author.EMail);
            }

            // Assert ...
            Assert.AreEqual(2, foundEMails.Count);
            Assert.IsTrue(foundEMails.Contains("*****@*****.**"));
            Assert.IsTrue(foundEMails.Contains("*****@*****.**"));
        }
예제 #2
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);
        }