public void FilesOnStaticPageTest()
{
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 page = browser.GoTo<FormFilePage>();
page.Result.TraceResults();
page.SomeData.Value = textValue;
page.File1.Value = firstFile;
page.File2.Value = secondFile;
var postedPage = page.Submit.Click<FormFilePage>();
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);
}
}