Castle.MonoRail.TestSupport
Base class for tests cases using the ASP.Net Runtime
to run the web project. Deprecated.
Reinstates the request.
The serialized request.
Gets the serialized request.
Performs a GET operation on the specified path.
DoGet("home/index.rails");
The resource being request, for example home/index.rails
A list of key/value pair, for example name=johndoe
Performs a GET operation on the specified path.
DoGet("home/index.rails");
The resource being request, for example home/index.rails
if set to true [resend cookies].
A list of key/value pair, for example name=johndoe
Performs a POST operation on the specified path.
DoPost("producto/search.rails", "name=mac", "page=1");
The resource being request, for example home/index.rails
A list of key/value pair, for example name=johndoe
Performs a POST operation on the specified path.
DoPost("producto/search.rails", "name=mac", "page=1");
The resource being request, for example home/index.rails
if set to true [resend cookies].
A list of key/value pair, for example name=johndoe
Performs a HEAD operation on the specified path.
DoHead("producto/search.rails", "name=mac", "page=1");
The resource being request, for example home/index.rails
A list of key/value pair, for example name=johndoe
Asserts that the response contains a number of nodes matching an XPath expression.
The xpath expression to match against.
The number of expected nodes.
Asserts that the response was NOT a redirect to the specified
url - for example check that your request was not sent to a login screen.
Asserts the return status code is less than 400
Asserts that reply has exactly the samme
content of expectedContents
Asserts that reply starts with
expectedContents
Asserts that reply ends with
expectedContents
Asserts that reply contains the specified
expectedContents
Asserts that reply have only whitespace characters
Asserts that reply contents match the specified pattern, ignoring any whitespaces
pattern
Asserts that reply contents match the specified pattern
pattern
Asserts that reply contents match the specified pattern
pattern
Asserts that reply does not contain
expectedContents
Asserts that the response was a redirect to the specified
url
Asserts that the content-type header is equals to the specified
value
value to assert to
Asserts that the content-type header starts with to the specified
value
value to assert to
Asserts that the content-type header ends with the specified
value
value to assert to
Asserts that response contains the specified header.
value to assert to
Asserts that PropertyBag contains the specified key.
key name
Asserts that PropertyBag's entry value equals to the specified value.
key name
value to assert to
Asserts that Flash contains the specified key.
key name
Asserts that Flash does not contains the specified key.
key name
Asserts that Flash's entry value equals to the specified value.
key name
value to assert to
Asserts that Session contains the specified key.
key name
Asserts that Session does not contains the specified key.
key name
Asserts that Session's entry value equals to the specified value.
key name
value to assert to
Asserts that the response contains the specified cookie.
cookie name
Asserts that Response cookie entry value equals to the specified value.
cookie name
value to assert to
Asserts that the response cookie has the specified expiration.
cookie name
value to assert to
Ensures that cookies (and therefore the session) will persist between requests,
emulating the behaviour of a genuine web client.
Gets the TestRequest
Gets the TestResponse
Gets the request response
Returns the sessionId related to the current session
Base class that set ups the necessary infrastructure
to test controllers without the need
for an ASP.Net Runtime.
The following code is an example of a controller test:
[TestFixture]
public class LoginControllerTestCase : BaseControllerTest
{
private LoginController controller;
[SetUp]
public void Init()
{
controller = new LoginController();
PrepareController(controller);
}
[Test]
public void Authenticate_Should_Use_The_AuthenticationService()
{
// set up a mock authentication service before
controller.Authenticate("username", "my password", false);
Assert.AreEqual(3, controller.PropertyBag.Count);
Assert.AreEqual("username", controller.PropertyBag["username"]);
Assert.AreEqual("my password", controller.PropertyBag["password"]);
Assert.AreEqual(false, controller.PropertyBag["autoLogin"]);
}
}
The following is a more sophisticate test for an action that sends emails.
[Test]
public void Register_Should_Add_Registration_Using_The_Repository()
{
Registration reg = new Registration("John Doe", "johndoe@gmail.com");
using(mockRepository.Record())
{
registrationRepositoryMock.Add(reg);
}
using(mockRepository.Playback())
{
controller.Register(reg); // This action sends two emails
Assert.IsTrue(HasRenderedEmailTemplateNamed("emailToManager"));
Assert.IsTrue(HasRenderedEmailTemplateNamed("emailToParticipant"));
Assert.AreEqual("manager@gmail.com", MessagesSent[0].To);
Assert.AreEqual("johndoe@gmail.com", MessagesSent[1].To);
Assert.AreEqual("Registration\\Success", controller.SelectedViewName);
}
}
You must invoke -- or a different overload -
before making invocations to the controller.
Initializes a new instance of the class.
Initializes a new instance of the class.
The domain.
The domain prefix.
The port.
Override to perform any pre-test set up
Prepares the controller giving it mock implementations
of the service it requires to function normally.
The controller.
Prepares the controller giving it mock implementations
of the service it requires to function normally.
The controller.
The context initializer.
Prepares the controller giving it mock implementations
of the service it requires to function normally.
The controller.
Name of the controller.
Name of the action.
Prepares the controller giving it mock implementations
of the service it requires to function normally.
The controller.
Name of the area (cannot be null).
Name of the controller.
Name of the action.
Constructs a mock context.
Name of the area.
Name of the controller.
Name of the action.
Builds the request.
Builds the response.
Builds the trace.
Builds the a mock context. You can override this method to
create a special configured mock context.
The request.
The response.
The trace.
The URL info.
Builds the URL info that represents the contextual Url.
Name of the area.
Name of the controller.
Name of the action.
Determines whether a specified template was rendered -- to send an email.
Name of the template.
true if was rendered; otherwise, false.
Gets the cookies.
The cookies.
Gets the context.
The context.
Gets the request.
The request.
Gets the response.
The response.
Gets the trace.
The trace.
Gets the fake email messages sent.
The messages sent.
Gets the rendered email templates.
The rendered email templates.
Base class to test view components.
The following test makes sure the component rendered the inner sections correctly.
[TestFixture]
public class DiggStylePaginationTestCase : BaseViewComponentTest
{
private DiggStylePagination diggComponent;
private IPaginatedPage singlePage, secondPageOfThree;
[SetUp]
public void Init()
{
diggComponent = new DiggStylePagination();
singlePage = new Page(new string[] { "a", "b", "c" }, 1, 4, 1);
secondPageOfThree = new Page(new string[] { "a", "b", "c", "d" }, 2, 4, 10);
}
[TearDown]
public void Terminate()
{
CleanUp();
}
[Test]
public void PageWithNoLinksInvokesStartAndEndSections()
{
List<string> actions = new List<string>();
// pass mock inner sections to component
SectionRender["startblock"] = delegate(IDictionary context, TextWriter writer) { actions.Add("started"); };
SectionRender["endblock"] = delegate(IDictionary context, TextWriter writer) { actions.Add("ended"); };
SectionRender["link"] = delegate(IDictionary context, TextWriter writer) { actions.Add("link"); };
diggComponent.Page = singlePage;
PrepareViewComponent(diggComponent);
diggComponent.Render();
// make sure component "rendered" inner sections
Assert.AreEqual(2, actions.Count);
Assert.AreEqual("started", actions[0]);
Assert.AreEqual("ended", actions[1]);
}
}
You must call before testing a view component instance
and you should call after each test case (use the TearDown).
Use this dictionary to add inner sections as available inner sections to
the view component.
This delegate is called when the viewcomponent renders its body.
This delegate is called when the viewcomponent renders a view
Initializes a new instance of the class.
Initialize the view component with mock services it needs to
be functional.
The component instance.
Cleans the up all state created to test a view component.
Builds the view engine.
Builds the view component context.
Name of the view component.
Gets the output -- ie what the viewcomponent wrote to the output stream.
The output.
Base controller test that uses the controller as a generic parameter.
Controller type
The typed controller instance
Base test for wizard steps.
The wizard step page type
The wizard controller -- the one that implements
The step typed field
Runs the page pre-condition
Runs the step render method.
Used to integrate with the ASP.Net Runtime
Manages a instance. This is useful
to start/stop a lightweight webserver to run acceptance tests.
Starts the web server. The web project folder is going to be
extracted from the appSettings.webapp entry (from the configuration file)
If the path is relative, it is going to be converted to an absolute path.
Starts the web server using the specified web project path. Note
that the path must be absolute.
The web application absolute path.
Stops the web server.
Gets or sets the port to run the server. Defaults to 88.
The port.
Gets or sets the virtual dir to be used by the server. Defaults to /
The virtual dir.
Gets a value indicating whether this is started.
true if started; otherwise, false.