Ejemplo n.º 1
0
        public void CanAddNewBlogItemIncludingImage()
        {
            // Arrange
              Request blogRequest = Session.Bind(BlogRootPath);

              // Act ...

              // - GET blog
              Response<HtmlDocument> blog = blogRequest.Get<HtmlDocument>();

              // - Extract "edit" anchor
              ILink editLink = blog.Body.DocumentNode.SelectNodes(@"//a[@rel=""edit""]").First().Anchor(blog);

              // - GET form describing how to input
              Response<HtmlDocument> createDescriptor = editLink.Follow(Session).Get<HtmlDocument>();

              // - Extract "create" form
              IKeyValueForm form = createDescriptor.Body.DocumentNode.SelectNodes(@"//form[@id=""create""]").First().Form(createDescriptor);

              // - Populate form inputs
              IFile file = new File("..\\..\\data1.gif", "image/gif");
              form.Value("Title", "New item");
              form.Value("Text", "Yaj!");
              form.Value("Image", file);

              // - Submit the form
              HtmlDocument createdBlogItem = form.Bind().Submit<HtmlDocument>().Created();

              // Assert ...
              Assert.IsNotNull(createdBlogItem);
              HtmlNode postTitle = createdBlogItem.DocumentNode.SelectNodes(@"//*[@class=""post-title""]").First();
              HtmlNode postContent = createdBlogItem.DocumentNode.SelectNodes(@"//*[@class=""post-content""]").First();
              Assert.AreEqual("New item", postTitle.InnerText);
              Assert.AreEqual("Yaj!", postContent.InnerText);
        }
        public void CanPostMultipartFormDataWithBinaryFile()
        {
            // Arrange
              IFile file = new File("..\\..\\data1.gif", "image/gif");
              MultipartDataFile data = new MultipartDataFile { DataFile = file, Age = 99 };
              Request formdataReq = Session.Bind(MultipartFormDataFileTemplate);

              // Act
              Response<string> response = formdataReq.Accept("text/plain").ContentType("multipart/form-data").Post<string>(data);

              // Assert
              Assert.IsTrue(response.Headers["x-contenttype"].StartsWith("multipart/form-data"));
              Assert.AreEqual("data1.gif-image/gif-R0lGODlhAgACAA==-99", response.Body);
        }
        public void CanPostMultipartFormDataWithFile()
        {
            // Arrange
              IFile file = new File("..\\..\\data1.txt");
              MultipartDataFile data = new MultipartDataFile { DataFile = file, Age = 10 };
              Request formdataReq = Session.Bind(MultipartFormDataFileTemplate);

              // Act
              Response<string> response = formdataReq.Accept("text/plain")
                                             .ContentType("multipart/form-data")
                                             .Post<string>(data);

              // Assert
              Assert.IsTrue(response.Headers["x-contenttype"].StartsWith("multipart/form-data"));
              Assert.AreEqual("data1.txt-text/plain-w4bDvMOuwrRgJw==-10", response.Body);
        }