Skip to content

Commit

Permalink
Glory! All tests pass!
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Lovell-Smith committed Sep 19, 2013
1 parent f67ef2f commit 1bd8547
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 27 deletions.
3 changes: 0 additions & 3 deletions src/NuGetGallery/Controllers/AuthenticationController.cs
Expand Up @@ -93,9 +93,6 @@ public virtual ActionResult Register(RegisterRequest request, string returnUrl)
return View();
}

// TODO: consider client-side validation for unique username
// TODO: add email validation

User user;
try
{
Expand Down
7 changes: 6 additions & 1 deletion src/NuGetGallery/Helpers/HttpContextBaseExtensions.cs
Expand Up @@ -21,7 +21,12 @@ public static void SetConfirmationContext(this HttpContextBase httpContext, stri

public static string GetConfirmationReturnUrl(this HttpContextBase httpContext)
{
var cookie = httpContext.Request.Cookies.Get("ConfirmationContext");
HttpCookie cookie = null;
if (httpContext.Request.Cookies != null)
{
cookie = httpContext.Request.Cookies.Get("ConfirmationContext");
}

if (cookie == null)
{
return null;
Expand Down
Expand Up @@ -210,13 +210,13 @@ public void WillInvalidateModelStateAndShowTheViewWhenAnEntityExceptionIsThrow()
.Setup(x => x.Create(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
.Throws(new EntityException("aMessage"));

var result = controller.Register(
new RegisterRequest
{
Username = "theUsername",
Password = "thePassword",
EmailAddress = "theEmailAddress",
}, null);
var request = new RegisterRequest
{
Username = "theUsername",
Password = "thePassword",
EmailAddress = "theEmailAddress",
};
var result = controller.Register(request, null);

ResultAssert.IsView(result);
Assert.False(controller.ModelState.IsValid);
Expand Down
29 changes: 17 additions & 12 deletions tests/NuGetGallery.Facts/Controllers/UsersControllerFacts.cs
Expand Up @@ -118,18 +118,20 @@ public void Returns404WhenTokenIsEmpty()
public void ReturnsConfirmedWhenTokenMatchesUser()
{
var user = new User
{
UnconfirmedEmailAddress = "email@example.com",
EmailConfirmationToken = "the-token"
};
{
Username = "username",
UnconfirmedEmailAddress = "email@example.com",
EmailConfirmationToken = "the-token"
};
var controller = GetController<UsersController>();
controller.SetUser(user);

GetMock<IUserService>()
.Setup(u => u.FindByUsername("username"))
.Returns(user);
GetMock<IUserService>()
.Setup(u => u.ConfirmEmailAddress(user, "the-token"))
.Returns(true);
controller.SetUser(user);

var model = (controller.Confirm("username", "the-token") as ViewResult).Model as ConfirmationViewModel;

Expand All @@ -140,20 +142,22 @@ public void ReturnsConfirmedWhenTokenMatchesUser()
public void SendsAccountChangedNoticeWhenConfirmingChangedEmail()
{
var user = new User
{
EmailAddress = "old@example.com",
UnconfirmedEmailAddress = "new@example.com",
EmailConfirmationToken = "the-token"
};
{
Username = "username",
EmailAddress = "old@example.com",
UnconfirmedEmailAddress = "new@example.com",
EmailConfirmationToken = "the-token"
};
var controller = GetController<UsersController>();
controller.SetUser(user);

GetMock<IUserService>()
.Setup(u => u.FindByUsername("username"))
.Returns(user);
GetMock<IUserService>()
.Setup(u => u.ConfirmEmailAddress(user, "the-token"))
.Returns(true);
controller.SetUser(user);


var model = (controller.Confirm("username", "the-token") as ViewResult).Model as ConfirmationViewModel;

Assert.True(model.SuccessfulConfirmation);
Expand All @@ -167,6 +171,7 @@ public void DoesntSendAccountChangedEmailsWhenNoOldConfirmedAddress()
{
var user = new User
{
Username = "username",
EmailAddress = null,
UnconfirmedEmailAddress = "new@example.com",
EmailConfirmationToken = "the-token"
Expand Down
10 changes: 6 additions & 4 deletions tests/NuGetGallery.Facts/TestUtils/ResultAssert.cs
Expand Up @@ -38,10 +38,6 @@ public static ViewResult IsView(ActionResult result, string viewName = "", strin
{
DictionariesMatch(new RouteValueDictionary(viewData), view.ViewData);
}
else
{
Assert.Equal(0, view.ViewData.Count);
}
return view;
}

Expand All @@ -67,6 +63,12 @@ public static void IsStatusCode(ActionResult result, HttpStatusCode code)

public static void IsStatusCode(ActionResult result, int code)
{
if (result is EmptyResult)
{
Assert.Equal(code, 200);
return;
}

var statusCodeResult = Assert.IsAssignableFrom<HttpStatusCodeResult>(result);
Assert.Equal(code, statusCodeResult.StatusCode);
}
Expand Down

0 comments on commit 1bd8547

Please sign in to comment.