本文整理汇总了C#中MockRepository.SetCurrentUser方法的典型用法代码示例。如果您正苦于以下问题:C# MockRepository.SetCurrentUser方法的具体用法?C# MockRepository.SetCurrentUser怎么用?C# MockRepository.SetCurrentUser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MockRepository
的用法示例。
在下文中一共展示了MockRepository.SetCurrentUser方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VerifyPracticeAndEmail_EmptyToken_ValidPractice_HappyPath
public void VerifyPracticeAndEmail_EmptyToken_ValidPractice_HappyPath()
{
AuthenticationController controller;
var utcNow = new DateTime(2012, 08, 31, 0, 0, 0, DateTimeKind.Utc);
string practiceName;
try
{
// Simulating account creation.
string password;
string token;
var userId = CreateAccount_Helper(utcNow, out password, out token);
var mr = new MockRepository();
// Login-in the user that has just been created.
using (var db2 = CreateNewCerebelloEntities())
{
var user = db2.Users.Single(u => u.Id == userId);
mr.SetCurrentUser(user, password);
mr.SetRouteData("Any", "Practice", null, user.Practice.UrlIdentifier);
practiceName = user.Practice.UrlIdentifier;
}
controller = mr.CreateController<AuthenticationController>();
}
catch (Exception ex)
{
InconclusiveInit(ex);
return;
}
ActionResult actionResult;
{
actionResult = controller.VerifyPracticeAndEmail(
new VerifyPracticeAndEmailViewModel { PracticeIdentifier = practiceName });
}
// Asserting.
Assert.IsNotNull(actionResult);
Assert.IsInstanceOfType(actionResult, typeof(ViewResult));
var viewResult = (ViewResult)actionResult;
Assert.IsInstanceOfType(viewResult.Model, typeof(VerifyPracticeAndEmailViewModel));
var model = (VerifyPracticeAndEmailViewModel)viewResult.Model;
//// ATENTION: The value of the token must NEVER go out to a view.
//Assert.AreEqual(null, model.Token);
// ATENTION: The value of the password must NEVER go out to a view.
Assert.AreEqual(null, model.Password);
Assert.AreEqual(practiceName, model.PracticeIdentifier);
}
示例2: VerifyPracticeAndEmail_ExpiredToken_ValidPractice
public void VerifyPracticeAndEmail_ExpiredToken_ValidPractice()
{
AuthenticationController controller;
var utcNow = new DateTime(2012, 08, 31, 0, 0, 0, DateTimeKind.Utc);
string practiceName;
string token;
try
{
// Simulating account creation.
string password;
var userId = CreateAccount_Helper(utcNow.AddDays(-200), out password, out token);
var mr = new MockRepository();
// Login-in the user that has just been created.
using (var db2 = CreateNewCerebelloEntities())
{
var user = db2.Users.Single(u => u.Id == userId);
mr.SetCurrentUser(user, password);
mr.SetRouteData("Any", "Practice", null, user.Practice.UrlIdentifier);
practiceName = user.Practice.UrlIdentifier;
}
controller = mr.CreateController<AuthenticationController>();
}
catch (Exception ex)
{
InconclusiveInit(ex);
return;
}
ActionResult actionResult;
{
actionResult = controller.VerifyPracticeAndEmail(
new VerifyPracticeAndEmailViewModel { Token = token, PracticeIdentifier = practiceName });
}
// Asserting.
Assert.IsNotNull(actionResult);
Assert.IsInstanceOfType(actionResult, typeof(ViewResult));
var viewResult = (ViewResult)actionResult;
Assert.IsInstanceOfType(viewResult.Model, typeof(VerifyPracticeAndEmailViewModel));
var model = (VerifyPracticeAndEmailViewModel)viewResult.Model;
//// ATENTION: The value of the token must NEVER go out to a view.
//Assert.AreEqual(null, model.Token);
// ATENTION: The value of the password must NEVER go out to a view.
Assert.AreEqual(null, model.Password);
Assert.AreEqual(practiceName, model.PracticeIdentifier);
// Asserting ModelState.
Assert.IsTrue(controller.ModelState.ContainsKey("Token"), "ModelState must containt an entry for 'Token'.");
Assert.AreEqual(1, controller.ModelState["Token"].Errors.Count);
Assert.AreEqual("Problema com o token.", controller.ModelState["Token"].Errors.First().ErrorMessage);
}
示例3: TryAccessPractice_JustAfterCreateAccount
public void TryAccessPractice_JustAfterCreateAccount()
{
PracticeController controller;
MockRepository mr;
var utcNow = new DateTime(2012, 08, 31, 0, 0, 0, DateTimeKind.Utc);
string practiceName;
try
{
// Simulating account creation.
string password;
string token;
var userId = CreateAccount_Helper(utcNow, out password, out token);
mr = new MockRepository();
// Login-in the user that has just been created.
using (var db2 = CreateNewCerebelloEntities())
{
var user = db2.Users.Single(u => u.Id == userId);
mr.SetCurrentUser(user, password);
mr.SetRouteData("Any", "Practice", null, user.Practice.UrlIdentifier);
practiceName = user.Practice.UrlIdentifier;
}
controller = mr.CreateController<PracticeController>(callOnActionExecuting: false);
}
catch (Exception ex)
{
InconclusiveInit(ex);
return;
}
ActionResult actionResult;
{
actionResult = Mvc3TestHelper.RunOnActionExecuting(controller, mr);
}
// Asserting.
Assert.IsNotNull(actionResult);
Assert.IsInstanceOfType(actionResult, typeof(RedirectToRouteResult));
var redirectToRouteResult = (RedirectToRouteResult)actionResult;
Assert.AreEqual("CreateAccountCompleted", redirectToRouteResult.RouteValues["action"]);
Assert.AreEqual("Authentication", redirectToRouteResult.RouteValues["controller"]);
Assert.AreEqual("", redirectToRouteResult.RouteValues["area"]);
Assert.AreEqual(practiceName, redirectToRouteResult.RouteValues["practice"]);
Assert.AreEqual(true, redirectToRouteResult.RouteValues["mustValidateEmail"]);
}
示例4: TryAccessPractice_AfterCreateAccountAndValidateEmail
public void TryAccessPractice_AfterCreateAccountAndValidateEmail()
{
PracticeController controller;
MockRepository mr;
var utcNow = new DateTime(2012, 08, 31, 0, 0, 0, DateTimeKind.Utc);
string practiceName;
try
{
// Simulating account creation.
string password;
string token;
var userId = CreateAccount_Helper(utcNow, out password, out token);
mr = new MockRepository();
// Login-in the user that has just been created.
using (var db2 = CreateNewCerebelloEntities())
{
var user = db2.Users.Single(u => u.Id == userId);
mr.SetCurrentUser(user, password);
mr.SetRouteData("Any", "Practice", null, user.Practice.UrlIdentifier);
practiceName = user.Practice.UrlIdentifier;
}
// Verifying the new account.
// Note: the following AuthenticationController is being
// setup with an invalid MockRepository for it,
// however this does not prevent proper operation.
var authController = mr.CreateController<AuthenticationController>();
authController.UtcNowGetter = () => utcNow.AddDays(15.0); // this is up to 30 days
authController.VerifyPracticeAndEmail(
new VerifyPracticeAndEmailViewModel { Token = token, PracticeIdentifier = practiceName });
Assert.IsTrue(authController.ModelState.IsValid, "Could not validate email.");
controller = mr.CreateController<PracticeController>(callOnActionExecuting: false);
}
catch (Exception ex)
{
InconclusiveInit(ex);
return;
}
ActionResult actionResult;
{
// The controller self-filter should let the action being executed,
// so the resulting actionResult from OnActionExecuting, must be null.
actionResult = Mvc3TestHelper.RunOnActionExecuting(controller, mr);
}
// Asserting.
Assert.IsNull(actionResult);
}
示例5: VerifyPracticeAndEmail_ValidToken_ValidPractice_HappyPath
public void VerifyPracticeAndEmail_ValidToken_ValidPractice_HappyPath()
{
AuthenticationController controller;
var utcNow = new DateTime(2012, 08, 31, 0, 0, 0, DateTimeKind.Utc);
string practiceName;
string token;
try
{
// Simulating account creation.
string password;
var userId = CreateAccount_Helper(utcNow, out password, out token);
var mr = new MockRepository();
// Login-in the user that has just been created.
using (var db2 = CreateNewCerebelloEntities())
{
var user = db2.Users.Single(u => u.Id == userId);
mr.SetCurrentUser(user, password);
mr.SetRouteData("Any", "Practice", null, user.Practice.UrlIdentifier);
practiceName = user.Practice.UrlIdentifier;
}
controller = mr.CreateController<AuthenticationController>();
controller.UtcNowGetter = () => utcNow;
}
catch (Exception ex)
{
InconclusiveInit(ex);
return;
}
ActionResult actionResult;
{
actionResult = controller.VerifyPracticeAndEmail(
new VerifyPracticeAndEmailViewModel { Token = token, PracticeIdentifier = practiceName, });
}
// Asserting.
Assert.IsTrue(controller.ModelState.IsValid, "ModelState is not valid.");
Assert.IsNotNull(actionResult);
Assert.IsInstanceOfType(actionResult, typeof(RedirectToRouteResult));
var redirectToRouteResult = (RedirectToRouteResult)actionResult;
Assert.AreEqual("Welcome", redirectToRouteResult.RouteValues["action"]);
Assert.AreEqual("Home", redirectToRouteResult.RouteValues["controller"]);
Assert.AreEqual("", redirectToRouteResult.RouteValues["area"]);
Assert.AreEqual(practiceName, redirectToRouteResult.RouteValues["practice"]);
}
示例6: Index_UserIsSecretary
public void Index_UserIsSecretary()
{
PracticeHomeController homeController;
var mr = new MockRepository();
try
{
var milena = Firestarter.CreateSecretary_Milena(this.db, this.db.Practices.First());
mr.SetCurrentUser(milena.Users.Single(), "milena");
mr.SetRouteData("Index", "practicehome", "App", "consultoriodrhouse");
homeController = mr.CreateController<PracticeHomeController>(callOnActionExecuting: false);
}
catch (Exception ex)
{
InconclusiveInit(ex);
return;
}
// Execute test: owner must have access to this view.
var actionResult = Mvc3TestHelper.RunOnAuthorization(homeController, "Index")
?? Mvc3TestHelper.RunOnActionExecuting(homeController, "Index")
?? homeController.Index();
// Asserts
Assert.IsInstanceOfType(actionResult, typeof(ViewResult));
Assert.AreEqual(null, ((ViewResult)actionResult).View);
}
示例7: EditPost_UserIsSecretary
public void EditPost_UserIsSecretary()
{
PracticeHomeController homeController;
var mr = new MockRepository();
try
{
var milena = Firestarter.CreateSecretary_Milena(this.db, this.db.Practices.First());
mr.SetCurrentUser(milena.Users.Single(), "milena");
mr.SetRouteData("Edit", "practicehome", "App", "consultoriodrhouse");
homeController = mr.CreateController<PracticeHomeController>(callOnActionExecuting: false);
}
catch (Exception ex)
{
InconclusiveInit(ex);
return;
}
// Execute test: owner must have access to this view.
var actionResult = Mvc3TestHelper.RunOnAuthorization(homeController, "Edit", "POST")
?? Mvc3TestHelper.RunOnActionExecuting(homeController, "Edit", "POST")
?? homeController.Edit(new PracticeHomeControllerViewModel
{
PracticeName = "My New Practice Name",
PracticeTimeZone = 3
});
// Asserts
Assert.IsInstanceOfType(actionResult, typeof(UnauthorizedResult));
}