本文整理汇总了C#中MockRepository.SetRouteData_ControllerAndActionOnly方法的典型用法代码示例。如果您正苦于以下问题:C# MockRepository.SetRouteData_ControllerAndActionOnly方法的具体用法?C# MockRepository.SetRouteData_ControllerAndActionOnly怎么用?C# MockRepository.SetRouteData_ControllerAndActionOnly使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MockRepository
的用法示例。
在下文中一共展示了MockRepository.SetRouteData_ControllerAndActionOnly方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateAccount_HappyPath
public void CreateAccount_HappyPath()
{
using (var disposer = new Disposer())
{
AuthenticationController controller;
var hasBeenSaved = false;
CreateAccountViewModel vm;
var wasEmailSent = false;
string emailBody = null, emailSubject = null, emailToAddress = null;
var utcNow = new DateTime(2012, 08, 31, 0, 0, 0, DateTimeKind.Utc);
try
{
var mr = new MockRepository();
var mve = mr.SetupViewEngine(disposer);
mve.SetViewContent(
"ConfirmationEmail",
vc => vc.ViewData.Model.ConvertObjectToString("<div>{0}={1}</div>"));
mr.SetRouteData_ControllerAndActionOnly("Home", "Index");
mr.SetupHttpContext(disposer);
controller = mr.CreateController<AuthenticationController>(
setupNewDb: db2 => db2.SavingChanges += (s, e) => { hasBeenSaved = true; });
controller.UtcNowGetter = () => utcNow;
controller.EmailSender = mm =>
{
wasEmailSent = true;
emailBody = mm.Body;
emailSubject = mm.Subject;
emailToAddress = mm.To.Single().Address;
};
// Creating ViewModel, and setting the ModelState of the controller.
vm = new CreateAccountViewModel
{
UserName = "andré-01",
PracticeName = "consultoriodrhouse_08sd986",
Password = "xpto",
ConfirmPassword = "xpto",
DateOfBirth = new DateTime(1984, 05, 04),
EMail = "[email protected]",
FullName = "André",
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);
}
// Getting the user that was saved.
var savedUser = this.db.Users.Single(u => u.UserName == "andré-01");
var savedToken = this.db.GLB_Token.Single();
// Assertions.
Assert.IsNotNull(actionResult, "The result of the controller method is null.");
Assert.IsInstanceOfType(actionResult, typeof(RedirectToRouteResult));
var redirectResult = (RedirectToRouteResult)actionResult;
Assert.AreEqual(redirectResult.RouteValues["action"], "CreateAccountCompleted");
Assert.IsTrue(controller.ModelState.IsValid, "ModelState should be valid.");
Assert.IsTrue(hasBeenSaved, "The database should be changed, but it was not.");
// Assert DB values.
Assert.AreEqual(savedUser.UserNameNormalized, "andre01");
Assert.AreEqual(32, savedToken.Value.Length);
Assert.AreEqual(savedUser.Practice.VerificationDate, null);
Assert.AreEqual(utcNow.AddDays(30), savedToken.ExpirationDate);
Assert.IsTrue(savedUser.IsOwner, "Saved user should be the owner of the practice.");
Assert.AreEqual(savedUser.Id, savedUser.Practice.OwnerId, "Saved user should be the owner of the practice.");
Assert.IsNotNull(savedUser.Administrator, "Practice owner must be administrator.");
// Assert user is logged-in.
Assert.IsTrue(
controller.HttpContext.Response.Cookies.Keys.Cast<string>().Contains(".ASPXAUTH"),
"Authentication cookie should be present in the Response.");
var authCookie = controller.HttpContext.Response.Cookies[".ASPXAUTH"];
Assert.IsNotNull(authCookie, @"Response.Cookies["".ASPXAUTH""] must not be null.");
var ticket = System.Web.Security.FormsAuthentication.Decrypt(authCookie.Value);
Assert.AreEqual("andré-01", ticket.Name);
var token = SecurityTokenHelper.FromString(ticket.UserData);
Assert.AreEqual(savedUser.Id, token.UserData.Id);
Assert.AreEqual("André", token.UserData.FullName);
Assert.AreEqual("[email protected]", token.UserData.Email);
Assert.AreEqual(false, token.UserData.IsUsingDefaultPassword);
//.........这里部分代码省略.........
示例2: CreateAccount_WithDoctor_HappyPath
public void CreateAccount_WithDoctor_HappyPath()
{
using (var disposer = new Disposer())
{
AuthenticationController controller;
var hasBeenSaved = false;
CreateAccountViewModel vm;
try
{
var mr = new MockRepository();
var mve = mr.SetupViewEngine(disposer);
mve.SetViewContent(
"ConfirmationEmail",
vc => vc.ViewData.Model.ConvertObjectToString("<div>{0}={1}</div>"));
mr.SetRouteData_ControllerAndActionOnly("Home", "Index");
mr.SetupHttpContext(disposer);
controller = mr.CreateController<AuthenticationController>(
setupNewDb: db2 => db2.SavingChanges += (s, e) => { hasBeenSaved = true; });
mr.SetupUrlHelper(controller);
controller.EmailSender = mm =>
{
// Do nothing, instead of sending a REAL e-mail.
// Don't need to test if this has been called... another test already does this.
};
// Creating ViewModel, and setting the ModelState of the controller.
var me = Firestarter.GetMedicalEntity_Psicologia(this.db);
var ms = Firestarter.GetMedicalSpecialty_Psiquiatra(this.db);
vm = new CreateAccountViewModel
{
UserName = "andré-01",
PracticeName = "consultoriodrhouse_08sd986",
Password = "xpto",
ConfirmPassword = "xpto",
DateOfBirth = new DateTime(1984, 05, 04),
EMail = "[email protected]",
FullName = "André",
Gender = (short)TypeGender.Male,
IsDoctor = true,
MedicCRM = "98237",
MedicalEntityId = me.Id,
MedicalSpecialtyId = ms.Id,
MedicalSpecialtyName = ms.Name,
MedicalEntityJurisdiction = (int)TypeEstadoBrasileiro.RJ,
};
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);
}
// Getting the user that was saved.
var savedUser = this.db.Users.Single(u => u.UserName == "andré-01");
// Assertions.
Assert.IsNotNull(actionResult, "The result of the controller method is null.");
Assert.IsInstanceOfType(actionResult, typeof(RedirectToRouteResult));
var redirectResult = (RedirectToRouteResult)actionResult;
Assert.AreEqual(redirectResult.RouteValues["action"], "CreateAccountCompleted");
Assert.IsTrue(controller.ModelState.IsValid, "ModelState should be valid.");
Assert.IsTrue(hasBeenSaved, "The database should be changed, but it was not.");
Assert.AreEqual(savedUser.UserNameNormalized, "andre01");
// Assert user is logged-in: this is already done in CreateAccount_HappyPath.
// Assertion for email: this is already done in CreateAccount_HappyPath.
}
}
示例3: CreateAccount_3_UserNameExistsInAnotherPractice_HappyPath
public void CreateAccount_3_UserNameExistsInAnotherPractice_HappyPath()
{
using (var disposer = new Disposer())
{
AuthenticationController controller;
var hasBeenSaved = false;
CreateAccountViewModel vm;
try
{
var mr = new MockRepository();
var mve = mr.SetupViewEngine(disposer);
mve.SetViewContent(
"ConfirmationEmail",
vc => vc.ViewData.Model.ConvertObjectToString("<div>{0}={1}</div>"));
mr.SetRouteData_ControllerAndActionOnly("Home", "Index");
mr.SetupHttpContext(disposer);
controller = mr.CreateController<AuthenticationController>(
setupNewDb: db2 => db2.SavingChanges += (s, e) => { hasBeenSaved = true; });
var userFullName = this.db.Users.Single().Person.FullName;
var userName = this.db.Users.Single().UserName;
controller.EmailSender = mm =>
{
// Do nothing, instead of sending a REAL e-mail.
// Don't need to test if this has been called... another test already does this.
};
vm = new CreateAccountViewModel
{
UserName = userName,
PracticeName = "consultoriodrhouse_0832986",
Password = "xpto",
ConfirmPassword = "xpto",
DateOfBirth = new DateTime(1984, 05, 04),
EMail = "[email protected]",
FullName = userFullName,
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(RedirectToRouteResult));
var redirectResult = (RedirectToRouteResult)actionResult;
Assert.AreEqual(redirectResult.RouteValues["action"], "CreateAccountCompleted");
Assert.IsTrue(controller.ModelState.IsValid, "ModelState should be valid.");
Assert.IsTrue(hasBeenSaved, "The database should be changed, but it was not.");
}
}