本文整理汇总了C#中MockRepository.SetRouteData方法的典型用法代码示例。如果您正苦于以下问题:C# MockRepository.SetRouteData方法的具体用法?C# MockRepository.SetRouteData怎么用?C# MockRepository.SetRouteData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MockRepository
的用法示例。
在下文中一共展示了MockRepository.SetRouteData方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: 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"]);
}
示例3: 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);
}
示例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: CreateAccount_4_UserNameIsInvalid
public void CreateAccount_4_UserNameIsInvalid()
{
using (var disposer = new Disposer())
{
AuthenticationController controller;
var hasBeenSaved = false;
CreateAccountViewModel vm;
var hasEmail = false;
try
{
var mr = new MockRepository();
mr.SetRouteData(typeof(AuthenticationController), "CreateAccount");
var mve = mr.SetupViewEngine(disposer);
mve.SetViewContent("ConfirmationEmail", vc => "<html>Test e-mail string.</html>");
controller = mr.CreateController<AuthenticationController>(
setupNewDb: db2 => db2.SavingChanges += (s, e) => { hasBeenSaved = true; });
controller.EmailSender = mm => { hasEmail = true; };
// Creating ViewModel, and setting the ModelState of the controller.
vm = new CreateAccountViewModel
{
UserName = "André#Pena", // char # is invalid
PracticeName = "New Practice Name 4146",
Password = "xpto",
ConfirmPassword = "xpto",
DateOfBirth = new DateTime(1984, 09, 01),
EMail = "[email protected]",
FullName = "André Rodrigues Pena",
Gender = (short)TypeGender.Male,
};
Mvc3TestHelper.SetModelStateErrors(controller, vm);
}
catch (Exception ex)
{
InconclusiveInit(ex);
return;
}
// Creating a new user without an e-mail.
// This must be ok, no exceptions, no validation errors.
ActionResult actionResult;
{
actionResult = controller.CreateAccount(vm);
}
// Assertions.
Assert.IsNotNull(actionResult, "The result of the controller method is null.");
Assert.IsInstanceOfType(actionResult, typeof(ViewResult));
var viewResult = (ViewResult)actionResult;
Assert.AreEqual(viewResult.ViewName, "");
Assert.IsFalse(controller.ModelState.IsValid, "ModelState should not be valid.");
Assert.AreEqual(1, controller.ModelState.GetAllErrors().Count, "ModelState should contain one validation message.");
Assert.IsTrue(
controller.ModelState.ContainsKey("UserName"),
"ModelState must contain validation message for 'PracticeName'.");
Assert.IsFalse(hasBeenSaved, "The database has been changed. This was not supposed to happen.");
Assert.IsFalse(hasEmail, "A confirmation e-mail has been sent. This was not supposed to happen.");
}
}
示例6: 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"]);
}
示例7: 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);
}
示例8: 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));
}