本文整理汇总了C#中Browser.PostTo方法的典型用法代码示例。如果您正苦于以下问题:C# Browser.PostTo方法的具体用法?C# Browser.PostTo怎么用?C# Browser.PostTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Browser
的用法示例。
在下文中一共展示了Browser.PostTo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanPostFileDirectlyWithoutPreloadingPageTest
public void CanPostFileDirectlyWithoutPreloadingPageTest()
{
var firstFileName = Guid.NewGuid().ToString("N") + ".txt";
var firstFile = Path.Combine(Path.GetTempPath(), firstFileName);
var firstFileContent = Guid.NewGuid().ToString();
var secondFileName = Guid.NewGuid().ToString("N") + ".txt";
var secondFile = Path.Combine(Path.GetTempPath(), secondFileName);
var secondFileContent = Guid.NewGuid().ToString();
try
{
File.WriteAllText(firstFile, firstFileContent);
File.WriteAllText(secondFile, secondFileContent);
using (var browser = new Browser())
{
var textValue = Guid.NewGuid().ToString();
var parameters = new List<PostEntry>
{
new PostFileEntry("files", firstFile),
new PostFileEntry("files", secondFile),
new PostEntry("SomeData", textValue)
};
var postedPage = browser.PostTo<FormFilePage>(parameters);
postedPage.Result.TraceResults();
postedPage.SomeData.Value.Should().Be(textValue);
postedPage.FileCount.Text.Should().Be("2");
var firstFileCells =
postedPage.PostedFiles.Find<HtmlTableRow>()
.ByPredicate(x => x.Html.Contains(firstFileName))
.Cells.ToList();
firstFileCells[0].Text.Should().Be(firstFileName);
firstFileCells[1].Text.Should().Be("text/plain");
firstFileCells[2].Text.Should().Be(firstFileContent);
var secondFileCells =
postedPage.PostedFiles.Find<HtmlTableRow>()
.ByPredicate(x => x.Html.Contains(secondFileName))
.Cells.ToList();
secondFileCells[0].Text.Should().Be(secondFileName);
secondFileCells[1].Text.Should().Be("text/plain");
secondFileCells[2].Text.Should().Be(secondFileContent);
}
}
finally
{
File.Delete(firstFile);
File.Delete(secondFile);
}
}
示例2: CanPostStreamDirectlyWithoutPreloadingPageTest
public void CanPostStreamDirectlyWithoutPreloadingPageTest()
{
var firstFileName = Guid.NewGuid().ToString("N") + ".txt";
var secondFileName = Guid.NewGuid().ToString("N") + ".txt";
using (var firstStream = new MemoryStream())
{
using (var secondStream = new MemoryStream())
{
using (var browser = new Browser())
{
var firstFileContent = Guid.NewGuid().ToString();
var firstFileBuffer = Encoding.UTF8.GetBytes(firstFileContent);
var secondFileContent = Guid.NewGuid().ToString();
var secondFileBuffer = Encoding.UTF8.GetBytes(secondFileContent);
firstStream.Write(firstFileBuffer, 0, firstFileBuffer.Length);
secondStream.Write(secondFileBuffer, 0, secondFileBuffer.Length);
firstStream.Position = 0;
secondStream.Position = 0;
var textValue = Guid.NewGuid().ToString();
var parameters = new List<PostEntry>
{
new PostFileStreamEntry("files", firstFileName, firstStream),
new PostFileStreamEntry("files", secondFileName, secondStream),
new PostEntry("SomeData", textValue)
};
var postedPage = browser.PostTo<FormFilePage>(parameters);
postedPage.Result.TraceResults();
postedPage.SomeData.Value.Should().Be(textValue);
postedPage.FileCount.Text.Should().Be("2");
var firstFileCells =
postedPage.PostedFiles.Find<HtmlTableRow>()
.ByPredicate(x => x.Html.Contains(firstFileName))
.Cells.ToList();
firstFileCells[0].Text.Should().Be(firstFileName);
firstFileCells[1].Text.Should().Be("text/plain");
firstFileCells[2].Text.Should().Be(firstFileContent);
var secondFileCells =
postedPage.PostedFiles.Find<HtmlTableRow>()
.ByPredicate(x => x.Html.Contains(secondFileName))
.Cells.ToList();
secondFileCells[0].Text.Should().Be(secondFileName);
secondFileCells[1].Text.Should().Be("text/plain");
secondFileCells[2].Text.Should().Be(secondFileContent);
}
}
}
}