Skip to content

Commit

Permalink
Implement history using a list of states. Url, CurrentHtml , etc. are…
Browse files Browse the repository at this point in the history
… now based on the list.
  • Loading branch information
Teun committed May 19, 2012
1 parent af9e917 commit 7bd19df
Show file tree
Hide file tree
Showing 8 changed files with 235 additions and 58 deletions.
35 changes: 35 additions & 0 deletions SimpleBrowser.UnitTests/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,41 @@ internal static string GetFromResources(string resourceName)
}
}
}
internal static IWebRequestFactory GetAllways200RequestMocker()
{
return new Always200RequestMocker();
}
class Always200RequestMocker : IWebRequestFactory
{
public Always200RequestMocker()
{
ResponseContent = "";
}
public string ResponseContent { get; set; }
#region IWebRequestFactory Members

public IHttpWebRequest GetWebRequest(Uri url)
{
var mock = new Mock<IHttpWebRequest>();
mock.SetupAllProperties();
mock.Setup(m => m.GetResponse())
.Returns(() =>
{
var mockResponse = new Mock<IHttpWebResponse>();
mockResponse.SetupAllProperties();
mockResponse.SetupProperty(m => m.Headers, new WebHeaderCollection());
byte[] responseContent = Encoding.UTF8.GetBytes(this.ResponseContent);
mockResponse.Setup(r => r.GetResponseStream()).Returns(new MemoryStream(responseContent));
return mockResponse.Object;
});
mock.SetupProperty(m => m.Headers, new WebHeaderCollection());
mock.Setup(m => m.GetRequestStream()).Returns(new MemoryStream(new byte[2000000]));
return mock.Object;
}

#endregion
}
internal static IWebRequestFactory GetMoviesRequestMocker()
{
return new MoviesRequestMocker();
Expand Down
54 changes: 54 additions & 0 deletions SimpleBrowser.UnitTests/OfflineTests/History.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;

namespace SimpleBrowser.UnitTests.OfflineTests
{
[TestFixture]
public class History
{
[Test]
public void When_Navigate_Back_Current_Url_Should_Change()
{
Browser b = new Browser(Helper.GetMoviesRequestMocker());
HttpRequestLog lastRequest = null;
b.RequestLogged += (br, l) =>
{
lastRequest = l;
};
b.Navigate("http://localhost/movies/");
Assert.That(b.Url == new Uri("http://localhost/movies/"));
b.Navigate("http://localhost/movies2/");
Assert.That(b.Url == new Uri("http://localhost/movies2/"));
b.NavigateBack();
Assert.AreEqual(new Uri("http://localhost/movies/"), b.Url);
var link = b.Find(ElementType.Anchor, FindBy.Text, "Create New");
Assert.NotNull(link, "After navigating back, the 'Create New' link should be found");
b.NavigateForward();
Assert.AreEqual(new Uri("http://localhost/movies2/"), b.Url);
link = b.Find(ElementType.Anchor, FindBy.Text, "Create New");
Assert.AreEqual(false, link.Exists, "After navigating forward, the 'Create New' link should NOT be found");
}

[Test]
public void After_navigating_away_htmlresult_should_throw_exception()
{
Browser b = new Browser(Helper.GetMoviesRequestMocker());
HttpRequestLog lastRequest = null;
b.RequestLogged += (br, l) =>
{
lastRequest = l;
};
b.Navigate("http://localhost/movies/");
Assert.That(b.Url == new Uri("http://localhost/movies/"));
var link = b.Find(ElementType.Anchor, FindBy.Text, "Create New");
link.Click();
Assert.AreEqual(new Uri("http://localhost/movies/Movies/Create?"), b.Url);
Assert.Throws(typeof(InvalidOperationException), () => link.Click(), "Clicking the link should now throw an exception");
}


}
}
4 changes: 2 additions & 2 deletions SimpleBrowser.UnitTests/OfflineTests/Uploading.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ namespace SimpleBrowser.UnitTests.OfflineTests
public class Uploading
{
[Test]
public void SearchingAnInputElementBySeveralSelectingMethods()
public void Uploading_A_File_With_Enctype_MultipartMime()
{
Browser b = new Browser();
Browser b = new Browser(Helper.GetAllways200RequestMocker());
b.SetContent(Helper.GetFromResources("SimpleBrowser.UnitTests.SampleDocs.FileUpload.htm"));
HttpRequestLog lastLog = null;
b.RequestLogged += (br, l) =>
Expand Down
1 change: 1 addition & 0 deletions SimpleBrowser.UnitTests/SimpleBrowser.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
<ItemGroup>
<Compile Include="Helper.cs" />
<Compile Include="Issues.cs" />
<Compile Include="OfflineTests\History.cs" />
<Compile Include="OfflineTests\QueryTests.cs" />
<Compile Include="OfflineTests\Selectors.cs" />
<Compile Include="OfflineTests\Uploading.cs" />
Expand Down
6 changes: 6 additions & 0 deletions SimpleBrowser.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample", "Sample\Sample.csp
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleBrowser.UnitTests", "SimpleBrowser.UnitTests\SimpleBrowser.UnitTests.csproj", "{C0A2F5F6-088D-44E8-BBE3-400A8F84C0D3}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{7C5CA587-1761-43E7-87E5-D7EB62CE2F00}"
ProjectSection(SolutionItems) = preProject
.nuget\NuGet.exe = .nuget\NuGet.exe
.nuget\NuGet.targets = .nuget\NuGet.targets
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down
Loading

0 comments on commit 7bd19df

Please sign in to comment.