/// <summary>
        /// Adds a multipart/form-data encoded request body to the <see cref="Browser"/>.
        /// </summary>
        /// <param name="browserContext">The <see cref="BrowserContext"/> that the data should be added to.</param>
        /// <param name="multipartFormData">The multipart/form-data encoded data that should be added.</param>
        /// <param name="boundaryName">The name of the boundary to be used</param>
        public static void MultiPartFormData(this BrowserContext browserContext, BrowserContextMultipartFormData multipartFormData, string boundaryName)
        {
            var contextValues =
                (IBrowserContextValues)browserContext;

            contextValues.Body = multipartFormData.Body;
            contextValues.Headers["Content-Type"] = new[] { "multipart/form-data; boundary=" + boundaryName };
        }
 /// <summary>
 /// Adds a multipart/form-data encoded request body to the <see cref="Browser"/>, using the default boundary name.
 /// </summary>
 /// <param name="browserContext">The <see cref="BrowserContext"/> that the data should be added to.</param>
 /// <param name="multipartFormData">The multipart/form-data encoded data that should be added.</param>
 public static void MultiPartFormData(this BrowserContext browserContext, BrowserContextMultipartFormData multipartFormData)
 {
     MultiPartFormData(browserContext, multipartFormData, BrowserContextMultipartFormData.DefaultBoundaryName);
 }
Пример #3
0
        public void Should_be_able_to_save_a_cms_item()
        {
            // Given

            var bootstrapper = new CustomBootstrapper();
            var browser = new Browser(bootstrapper);
            var streamReader = new StreamReader(Path.Combine(Environment.CurrentDirectory, "Content", "Logo.png"));
            var multipart = new BrowserContextMultipartFormData(x =>
                x.AddFile("Logo.png", "Logo.png", "image/png", streamReader.BaseStream));
            // When
            var result = browser.Post("/cms/",
                                      delegate(BrowserContext with)
                                      {
                                          with.HttpRequest();
                                          with.FormValue("key", "Homepage_Title_Background");
                                          with.MultiPartFormData(multipart);

                                      });

            // Then
            Assert.Equal(HttpStatusCode.OK, result.StatusCode);
        }