Created
November 27, 2011 18:43
-
-
Save MattHoneycutt/1397956 to your computer and use it in GitHub Desktop.
SpecsFor.Mvc examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[SetUpFixture] | |
public class DemoWebAppConfig : SpecsForMvcConfig | |
{ | |
public DemoWebAppConfig() | |
{ | |
UseIISExpressWith(Project("SpecsFor.Mvc.Demo")); | |
BuildRoutesUsing(r => MvcApplication.RegisterRoutes(r)); | |
UseBrowser(BrowserDriver.InternetExplorer); | |
//TODO: Open questions to be answered: | |
//1) How do we point the app at a database for testing? | |
} | |
[SetUp] | |
public override void SetupTestRun() | |
{ | |
base.SetupTestRun(); | |
} | |
[TearDown] | |
public override void TearDownTestRun() | |
{ | |
base.TearDownTestRun(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class LoginSpecs | |
{ | |
public class when_logging_in_with_an_invalid_username_and_password : SpecsFor<MvcWebApp> | |
{ | |
protected override void Given() | |
{ | |
SUT.NavigateTo<AccountController>(c => c.LogOn()); | |
} | |
protected override void When() | |
{ | |
SUT.FindFormFor<LogOnModel>() | |
//TODO: Eventually expose a fluent API like: | |
//.ForField(m => m.UserName).TypeText("bad@user.com") | |
.SetFieldValue(m => m.UserName, "bad@user.com") | |
.SetFieldValue(m => m.Password, "BadPass") | |
.Submit(); | |
} | |
[Test] | |
public void then_it_should_redisplay_the_page() | |
{ | |
SUT.Route.ShouldMapTo<AccountController>(c => c.LogOn()); | |
} | |
[Test] | |
public void then_it_should_contain_a_validation_error() | |
{ | |
SUT.ValidationSummary.Text.ShouldContain("The user name or password provided is incorrect."); | |
} | |
} | |
public class when_logging_in_with_valid_credentials : SpecsFor<MvcWebApp> | |
{ | |
protected override void Given() | |
{ | |
SUT.NavigateTo<AccountController>(c => c.LogOn()); | |
} | |
protected override void When() | |
{ | |
SUT.FindFormFor<LogOnModel>() | |
.SetFieldValue(m => m.UserName, "real@user.com") | |
.SetFieldValue(m => m.Password, "RealPassword") | |
.Submit(); | |
} | |
[Test] | |
public void then_it_redirects_to_the_home_page() | |
{ | |
SUT.Route.ShouldMapTo<HomeController>(c => c.Index()); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[TestFixture] | |
public class LoginSpecsWithoutSpecsForMvc | |
{ | |
[Test] | |
public void when_logging_in_with_an_invalid_username_and_password() | |
{ | |
var capabilities = new DesiredCapabilities(); | |
capabilities.SetCapability(InternetExplorerDriver.IntroduceInstabilityByIgnoringProtectedModeSettings, true); | |
var driver = new InternetExplorerDriver(capabilities); | |
try | |
{ | |
driver.Navigate().GoToUrl("http://localhost:52125/Account/LogOn"); | |
driver.FindElement(By.Name("UserName")).SendKeys("bad@user.com"); | |
driver.FindElement(By.Name("Password")).SendKeys("BadPass"); | |
driver.FindElement(By.TagName("form")).Submit(); | |
driver.Url.ShouldEqual("http://localhost:52125/Account/LogOn"); | |
driver.FindElement(By.ClassName("validation-summary-errors")).Text.ShouldContain( | |
"The user name or password provided is incorrect."); | |
} | |
finally | |
{ | |
driver.Close(); | |
} | |
} | |
[Test] | |
public void when_logging_in_with_a_valid_username_and_password() | |
{ | |
var capabilities = new DesiredCapabilities(); | |
capabilities.SetCapability(InternetExplorerDriver.IntroduceInstabilityByIgnoringProtectedModeSettings, true); | |
var driver = new InternetExplorerDriver(capabilities); | |
try | |
{ | |
driver.Navigate().GoToUrl("http://localhost:52125/Account/LogOn"); | |
driver.FindElement(By.Name("UserName")).SendKeys("real@user.com"); | |
driver.FindElement(By.Name("Password")).SendKeys("RealPassword"); | |
driver.FindElement(By.TagName("form")).Submit(); | |
driver.Url.ShouldEqual("http://localhost:52125/"); | |
} | |
finally | |
{ | |
driver.Close(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment