Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[Test]
public void CanSignUp() {
Assert.That(db.Users.Count(), Is.EqualTo(0));
ClickLink("Register");
FillInFields(new {
Username = "bobsmith",
Email = "bob@smith.com",
Password = "secret",
PasswordConfirmation = "secret"
});
ClickButton("Register");
Assert.That(db.Users.Count(), Is.EqualTo(1));
var user = db.Users.First();
Assert.That(user.Username, Is.EqualTo("bobsmith"));
Assert.That(user.Email, Is.EqualTo("bob@smith.com"));
}
[Test]
public void AutomaticallyLoggedInAfterSigningUp() {
AssertLoggedOut();
Register(new { Username = "bobsmith" });
AssertFlash("Registration complete. Logged in as bobsmith");
AssertLoggedIn();
}
[Test]
public void RequiresUsername() {
AssertThrows<ConstraintException>("This property cannot be set to a null value", () => {
f.User.Build(new { Username = f.Null });
});
AssertNotValid( f.User.Build(new { Username = "" }));
AssertValid( f.User.Build(new { Username = "bobsmith" }));
}
[Test]
public void UsernameMustBeUnique() {
Assert.That(db.Users.Count(), Is.EqualTo(0));
AssertValid( f.User.Create(new { Username = "bobsmith" }));
AssertNotValid( f.User.Create(new { Username = "bobsmith" })); // <--- same username
AssertValid( f.User.Create(new { Username = "different" }));
Assert.That(db.Users.Count(), Is.EqualTo(2)); // only 2 records were actually saved
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.