-
Notifications
You must be signed in to change notification settings - Fork 4
Changing state on the server
jennifersmith edited this page Mar 10, 2012
·
2 revisions
Plasma sets up an ASP.NET application to run in an AppDomain embedded within the running process (see here for an explanation of AppDomains). Your tests can communicate with the running application via the magic of remoting via a number of helper functions that Plasma provides. You can use this to change state or add things to session.
[Test]
public void ShouldShowDetailsOfTheCurrentCheeseBeingViewed()
{
// we are using static state here cos it's an example. See later for a better way of doing it when you have an IoC container to hand
aspNetApplication.InvokeInAspAppDomain(()=>{
CheeseRepository.AddCheese(new Cheese(){
Name = "Stilton",
Region = "Derby, Leicestershire, Nottingham",
SourceOfMilk = Milk.Cow
});
});
var stiltonPage = aspNetApplication.ProcessRequest("/cheeses/Stilton").Html();
Assert.That(stiltonPage.FindElement(By.Id("region")), Is.StringContaining("Derby, Leicestershire, Nottingham"));
}
Obviously this example is not ideal as you must let in static/global state, methods for testing and all manner of evils into your production code. Another technique is to make use of your IoC container. Override dependencies with new stub versions for your tests and set test data on these.