本文整理汇总了C#中MockRepository.SetRouteData_ConsultorioDrHouse_GregoryHouse方法的典型用法代码示例。如果您正苦于以下问题:C# MockRepository.SetRouteData_ConsultorioDrHouse_GregoryHouse方法的具体用法?C# MockRepository.SetRouteData_ConsultorioDrHouse_GregoryHouse怎么用?C# MockRepository.SetRouteData_ConsultorioDrHouse_GregoryHouse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MockRepository
的用法示例。
在下文中一共展示了MockRepository.SetRouteData_ConsultorioDrHouse_GregoryHouse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EditPost_UserIsOwner_WithInvalidData
public void EditPost_UserIsOwner_WithInvalidData()
{
PracticeHomeController homeController;
var mr = new MockRepository();
try
{
mr.SetCurrentUser_Andre_CorrectPassword();
mr.SetRouteData_ConsultorioDrHouse_GregoryHouse(typeof(PracticeHomeController), "Edit");
homeController = mr.CreateController<PracticeHomeController>(callOnActionExecuting: false);
}
catch (Exception ex)
{
InconclusiveInit(ex);
return;
}
var viewModel = new PracticeHomeControllerViewModel
{
PracticeName = "", // Cannot set practice name to empty
PracticeTimeZone = 3
};
Mvc3TestHelper.SetModelStateErrors(homeController, viewModel);
// Execute test: owner must have access to this view.
var actionResult = Mvc3TestHelper.RunOnAuthorization(homeController, "Edit", "POST")
?? Mvc3TestHelper.RunOnActionExecuting(homeController, "Edit", "POST")
?? homeController.Edit(viewModel);
// Asserts
Assert.IsInstanceOfType(actionResult, typeof(ViewResult));
Assert.AreEqual(null, ((ViewResult)actionResult).View);
}
示例2: EditPost_UserIsAdministrator
public void EditPost_UserIsAdministrator()
{
PracticeHomeController homeController;
var mr = new MockRepository();
try
{
mr.SetCurrentUser_Miguel_CorrectPassword();
mr.SetRouteData_ConsultorioDrHouse_GregoryHouse(typeof(PracticeHomeController), "Edit");
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(RedirectToRouteResult));
var redirectResult = (RedirectToRouteResult)actionResult;
Assert.AreEqual(2, redirectResult.RouteValues.Count);
Assert.AreEqual("practicehome", string.Format("{0}", redirectResult.RouteValues["controller"]), ignoreCase: true);
Assert.AreEqual("Index", string.Format("{0}", redirectResult.RouteValues["action"]), ignoreCase: true);
}
示例3: CreateView_ViewNewAndFindNextAvailableTimeSlot_30DaysAfter_HappyPath
public void CreateView_ViewNewAndFindNextAvailableTimeSlot_30DaysAfter_HappyPath()
{
ScheduleController controller;
bool isDbChanged = false;
// Dates that will be used by this test.
// - utcNow and localNow: used to mock Now values from Utc and User point of view.
// - start and end: start and end time of the appointments that will be created.
var localNow = new DateTime(2012, 07, 25, 12, 00, 00, 000);
try
{
// Creating DB entries.
var docAndre = Firestarter.Create_CrmMg_Psiquiatria_DrHouse_Andre(this.db);
Firestarter.SetupDoctor(docAndre, this.db);
var timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(docAndre.Users.Single().Practice.WindowsTimeZoneId);
DateTime utcNow = TimeZoneInfo.ConvertTimeToUtc(localNow, timeZoneInfo);
var mr = new MockRepository(true);
mr.SetRouteData_ConsultorioDrHouse_GregoryHouse(typeof(ScheduleController), "Create");
controller = mr.CreateController<ScheduleController>(
setupNewDb: db2 => db2.SavingChanges += (s, e) => { isDbChanged = true; });
controller.UtcNowGetter = () => utcNow;
}
catch (Exception ex)
{
InconclusiveInit(ex);
return;
}
// View new appointment.
// This must be ok, no exceptions, no validation errors.
ActionResult actionResult;
{
actionResult = controller.Create(localNow.AddDays(30).Date, "", "", null, true);
}
// Verifying the ActionResult, and the DB.
Assert.IsNotNull(actionResult, "The result of the controller method is null.");
// Verify view-model.
var viewResult = (ViewResult)actionResult;
var viewModel = (AppointmentViewModel)viewResult.Model;
Assert.AreEqual(new DateTime(2012, 08, 24), viewModel.LocalDateTime);
Assert.AreEqual("09:00", viewModel.Start);
Assert.AreEqual("09:30", viewModel.End);
Assert.AreEqual(controller.ViewBag.IsEditingOrCreating, 'C');
Assert.IsTrue(controller.ModelState.IsValid, "ModelState is not valid.");
Assert.IsFalse(isDbChanged, "View actions cannot change DB.");
}
示例4: Create_SaveAppointmentWhenStatusIsSetForTheFuture_NotAccomplished
public void Create_SaveAppointmentWhenStatusIsSetForTheFuture_NotAccomplished()
{
ScheduleController controller;
AppointmentViewModel vm;
try
{
// Creating practice, doctor and patient.
var docAndre = Firestarter.Create_CrmMg_Psiquiatria_DrHouse_Andre(this.db);
Firestarter.SetupDoctor(docAndre, this.db);
var patient = Firestarter.CreateFakePatients(docAndre, this.db, 1)[0];
patient.LastUsedHealthInsuranceId = null;
this.db.SaveChanges();
var timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(docAndre.Users.Single().Practice.WindowsTimeZoneId);
var localNow = new DateTime(2012, 11, 09, 13, 00, 00, 000);
var utcNow = TimeZoneInfo.ConvertTimeToUtc(localNow, timeZoneInfo);
// the next free time from "now"
var db2 = new CerebelloEntitiesAccessFilterWrapper(this.db);
db2.SetCurrentUserById(docAndre.Users.Single().Id);
// the reason for this .AddMinutes(1) is that FindNextFreeTimeInPracticeLocalTime returns now, when now is available
// but now is not considered future, and I need a date in the future so the Status validation will fail
var nextFreeTime = ScheduleController.FindNextFreeTimeInPracticeLocalTime(db2, docAndre, localNow.AddMinutes(1));
// Creating Asp.Net Mvc mocks.
var mr = new MockRepository(true);
mr.SetRouteData_ConsultorioDrHouse_GregoryHouse(typeof(ScheduleController), "Create");
controller = mr.CreateController<ScheduleController>();
// Mocking 'Now' values.
controller.UtcNowGetter = () => utcNow;
// Setting view-model values to create a new appointment.
vm = new AppointmentViewModel
{
PatientId = patient.Id,
PatientNameLookup = patient.Person.FullName,
HealthInsuranceId = docAndre.HealthInsurances.First(hi => hi.IsActive).Id,
LocalDateTime = nextFreeTime.Item1.Date,
DoctorId = docAndre.Id,
Start = nextFreeTime.Item1.ToString("HH:mm"),
End = nextFreeTime.Item2.ToString("HH:mm"),
IsGenericAppointment = false,
// this has to generate an error because the appointment is in the future
Status = (int)TypeAppointmentStatus.NotAccomplished,
};
Mvc3TestHelper.SetModelStateErrors(controller, vm);
}
catch (Exception ex)
{
InconclusiveInit(ex);
return;
}
var result = controller.Create(vm);
Assert.IsFalse(controller.ModelState.IsValid);
Assert.AreEqual(1, controller.ModelState["Status"].Errors.Count);
}
示例5: Create_SaveAppointmentOnLunch_HappyPath
public void Create_SaveAppointmentOnLunch_HappyPath()
{
ScheduleController controller;
bool isDbChanged = false;
AppointmentViewModel vm;
// Dates that will be used by this test.
// - utcNow and localNow: used to mock Now values from Utc and User point of view.
// - start and end: start and end time of the appointments that will be created.
DateTime utcStart, utcEnd;
var localNow = new DateTime(2012, 07, 19, 12, 00, 00, 000);
// Setting Now to be on an thursday, mid day.
// We know that Dr. House lunch time is from 12:00 until 13:00.
var start = localNow.Date.AddDays(7).AddHours(12); // 2012-07-19 13:00
var end = start.AddMinutes(30); // 2012-07-19 13:30
try
{
// Creating practice and doctor.
var docAndre = Firestarter.Create_CrmMg_Psiquiatria_DrHouse_Andre(this.db);
Firestarter.SetupDoctor(docAndre, this.db);
var timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(docAndre.Users.Single().Practice.WindowsTimeZoneId);
DateTime utcNow = TimeZoneInfo.ConvertTimeToUtc(localNow, timeZoneInfo);
utcStart = TimeZoneInfo.ConvertTimeToUtc(start, timeZoneInfo);
utcEnd = TimeZoneInfo.ConvertTimeToUtc(end, timeZoneInfo);
// Creating Asp.Net Mvc mocks.
var mr = new MockRepository(true);
mr.SetRouteData_ConsultorioDrHouse_GregoryHouse(typeof(ScheduleController), "Create");
controller = mr.CreateController<ScheduleController>(
setupNewDb: db2 => db2.SavingChanges += (s, e) => { isDbChanged = true; });
controller.UtcNowGetter = () => utcNow;
// Setting view-model values to create a new appointment.
// - this view-model must be valid for this test... if some day it becomes invalid,
// then it must be made valid again.
vm = new AppointmentViewModel
{
Description = "Generic appointment on lunch time.",
LocalDateTime = start.Date,
DoctorId = docAndre.Id,
Start = start.ToString("HH:mm"),
End = end.ToString("HH:mm"),
IsGenericAppointment = true,
HealthInsuranceId = docAndre.HealthInsurances.First(hi => hi.IsActive).Id,
};
Mvc3TestHelper.SetModelStateErrors(controller, vm);
if (!controller.ModelState.IsValid)
throw new Exception("The given view-model must be valid for this test.");
}
catch (Exception ex)
{
InconclusiveInit(ex);
return;
}
// View new appointment.
// This must be ok, no exceptions, no validation errors.
ActionResult actionResult;
{
actionResult = controller.Create(vm);
}
// Verifying the ActionResult.
Assert.IsNotNull(actionResult, "The result of the controller method is null.");
Assert.IsInstanceOfType(actionResult, typeof(JsonResult));
var jsonResult = (JsonResult)actionResult;
Assert.AreEqual("success", ((dynamic)jsonResult.Data).status);
// Verifying the view-model.
// todo: this should verify a mocked message, but cannot mock messages until languages are implemented.
Assert.AreEqual(
"A data e hora marcada está no horário de almoço do médico.",
vm.TimeValidationMessage);
Assert.AreEqual(DateAndTimeValidationState.Warning, vm.DateAndTimeValidationState);
// Verifying the controller.
Assert.AreEqual(controller.ViewBag.IsEditingOrCreating, null); // when JsonResult there must be no ViewBag
Assert.IsTrue(controller.ModelState.IsValid, "ModelState is not valid.");
// Verifying the DB.
Assert.IsTrue(isDbChanged, "Create actions must change DB.");
using (var db2 = DbTestBase.CreateNewCerebelloEntities())
{
var appointmentsCountAtSameTime = db2.Appointments
.Where(a => a.Start == utcStart).Count(a => a.End == utcEnd);
Assert.AreEqual(1, appointmentsCountAtSameTime);
}
}
示例6: CreateView_ViewNew_SpecificTime_HappyPath
public void CreateView_ViewNew_SpecificTime_HappyPath()
{
ScheduleController controller;
bool isDbChanged = false;
try
{
var docAndre = Firestarter.Create_CrmMg_Psiquiatria_DrHouse_Andre(this.db);
Firestarter.SetupDoctor(docAndre, this.db);
var mr = new MockRepository(true);
mr.SetRouteData_ConsultorioDrHouse_GregoryHouse(typeof(ScheduleController), "Create");
controller = mr.CreateController<ScheduleController>(
setupNewDb: db2 => db2.SavingChanges += (s, e) => { isDbChanged = true; });
}
catch (Exception ex)
{
InconclusiveInit(ex);
return;
}
// View new appointment.
// This must be ok, no exceptions, no validation errors.
ActionResult actionResult;
{
actionResult = controller.Create(null, "10:00", "10:30", null, false);
}
// Verifying the ActionResult, and the DB.
Assert.IsNotNull(actionResult, "The result of the controller method is null.");
Assert.AreEqual(controller.ViewBag.IsEditingOrCreating, 'C');
Assert.IsTrue(controller.ModelState.IsValid, "ModelState is not valid.");
Assert.IsFalse(isDbChanged, "View actions cannot change DB.");
// Asserts related to view-model.
var vm = (AppointmentViewModel)((ViewResult)actionResult).Model;
Assert.AreEqual(null, vm.PatientId);
}
示例7: CreateView_ViewNewPredefinedPatient_HappyPath
public void CreateView_ViewNewPredefinedPatient_HappyPath()
{
ScheduleController controller;
bool isDbChanged = false;
Patient patient;
try
{
// Creating DB entries.
var docAndre = Firestarter.Create_CrmMg_Psiquiatria_DrHouse_Andre(this.db);
Firestarter.SetupDoctor(docAndre, this.db);
patient = Firestarter.CreateFakePatients(docAndre, this.db).First();
patient.LastUsedHealthInsuranceId = docAndre.HealthInsurances.First().Id;
this.db.SaveChanges();
// Creating test objects.
var mr = new MockRepository(true);
mr.SetRouteData_ConsultorioDrHouse_GregoryHouse(typeof(ScheduleController), "Create");
controller = mr.CreateController<ScheduleController>(
setupNewDb: db2 => db2.SavingChanges += (s, e) => { isDbChanged = true; });
}
catch (Exception ex)
{
InconclusiveInit(ex);
return;
}
// View new appointment.
// This must be ok, no exceptions, no validation errors.
ActionResult actionResult;
{
actionResult = controller.Create(null, "10:00", "10:30", patient.Id, false);
}
// Asserts related to ActionResult.
Assert.IsNotNull(actionResult, "The result of the controller method is null.");
Assert.IsInstanceOfType(actionResult, typeof(ViewResult));
var viewResult = (ViewResult)actionResult;
// Asserts related to view-model.
Assert.IsInstanceOfType(viewResult.Model, typeof(AppointmentViewModel));
var resultViewModel = (AppointmentViewModel)viewResult.Model;
Assert.AreEqual(patient.Id, resultViewModel.PatientId);
Assert.AreEqual(patient.Person.FullName, resultViewModel.PatientNameLookup);
Assert.AreEqual(patient.LastUsedHealthInsuranceId, resultViewModel.HealthInsuranceId);
// Asserts related to ViewBag.
Assert.AreEqual(controller.ViewBag.IsEditingOrCreating, 'C');
// Asserts related to ModelState.
Assert.IsTrue(controller.ModelState.IsValid, "ModelState is not valid.");
// Asserts related to data base.
Assert.IsFalse(isDbChanged, "View actions cannot change DB.");
}
示例8: CreateView_ViewNewEmpty
public void CreateView_ViewNewEmpty()
{
ScheduleController controller;
bool isDbChanged = false;
// Dates that will be used by this test.
// - utcNow and localNow: used to mock Now values from Utc and User point of view.
// - start and end: start and end time of the appointments that will be created.
var localNow = new DateTime(2012, 07, 26, 12, 33, 00, 000);
try
{
var docAndre = Firestarter.Create_CrmMg_Psiquiatria_DrHouse_Andre(this.db);
Firestarter.SetupDoctor(docAndre, this.db);
var timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(docAndre.Users.Single().Practice.WindowsTimeZoneId);
DateTime utcNow = TimeZoneInfo.ConvertTimeToUtc(localNow, timeZoneInfo);
var mr = new MockRepository(true);
mr.SetRouteData_ConsultorioDrHouse_GregoryHouse(typeof(ScheduleController), "Create");
controller = mr.CreateController<ScheduleController>(
setupNewDb: db2 => db2.SavingChanges += (s, e) => { isDbChanged = true; });
controller.UtcNowGetter = () => utcNow;
}
catch (Exception ex)
{
InconclusiveInit(ex);
return;
}
// View new appointment.
// This must be ok, no exceptions, no validation errors.
ActionResult actionResult;
{
actionResult = controller.Create(null, null, null, null, null);
}
// Verifying the ActionResult, and the DB.
Assert.IsNotNull(actionResult, "The result of the controller method is null.");
// Verify view-model.
var viewResult = (ViewResult)actionResult;
var viewModel = (AppointmentViewModel)viewResult.Model;
Assert.AreEqual("12:33", viewModel.Start);
Assert.AreEqual("13:03", viewModel.End);
// Asserts related to the view bag.
Assert.AreEqual(controller.ViewBag.IsEditingOrCreating, 'C');
Assert.IsInstanceOfType(controller.ViewBag.HealthInsuranceSelectItems, typeof(List<SelectListItem>));
Assert.AreEqual(3, ((List<SelectListItem>)controller.ViewBag.HealthInsuranceSelectItems).Count);
Assert.IsTrue(controller.ModelState.IsValid, "ModelState is not valid.");
Assert.IsFalse(isDbChanged, "View actions cannot change DB.");
}
示例9: FindNextFreeTime_SkipDoctorVacation_HappyPath
public void FindNextFreeTime_SkipDoctorVacation_HappyPath()
{
ScheduleController controller;
var utcNow = new DateTime(2012, 09, 12, 18, 00, 00, DateTimeKind.Utc);
bool isDbChanged = false;
try
{
var andre = Firestarter.Create_CrmMg_Psiquiatria_DrHouse_Andre(this.db);
Firestarter.SetupDoctor(andre, this.db);
var daysOff = DateTimeHelper.Range(new DateTime(2012, 09, 01), 30, d => d.AddDays(1.0))
.Select(
d => new CFG_DayOff
{
Date = d,
DoctorId = andre.Id,
Description = "Férias",
PracticeId = andre.PracticeId,
})
.ToArray();
foreach (var eachDayOff in daysOff)
this.db.CFG_DayOff.AddObject(eachDayOff);
this.db.SaveChanges();
var mr = new MockRepository();
mr.SetCurrentUser_Andre_CorrectPassword();
mr.SetRouteData_ConsultorioDrHouse_GregoryHouse(typeof(ScheduleController), "FindNextFreeTime");
controller = mr.CreateController<ScheduleController>(
callOnActionExecuting: true,
setupNewDb: db2 => db2.SavingChanges += (s, e) => { isDbChanged = true; });
controller.UtcNowGetter = () => utcNow;
}
catch (Exception ex)
{
InconclusiveInit(ex);
return;
}
JsonResult jsonResult;
{
jsonResult = controller.FindNextFreeTime("", "");
}
Assert.IsFalse(isDbChanged, "Database should not be changed.");
dynamic data = jsonResult.Data;
Assert.AreEqual("01/10/2012", data.date);
Assert.AreEqual("09:00", data.start);
Assert.AreEqual("09:30", data.end);
Assert.AreEqual("segunda-feira, daqui a 19 dias", data.dateSpelled);
}
示例10: FindNextFreeTime_AllSlotsFree_HappyPath
public void FindNextFreeTime_AllSlotsFree_HappyPath()
{
ScheduleController controller;
var utcNow = new DateTime(2012, 09, 12, 18, 00, 00, DateTimeKind.Utc);
bool isDbChanged = false;
try
{
var andre = Firestarter.Create_CrmMg_Psiquiatria_DrHouse_Andre(this.db);
Firestarter.SetupDoctor(andre, this.db);
var mr = new MockRepository();
mr.SetCurrentUser_Andre_CorrectPassword();
mr.SetRouteData_ConsultorioDrHouse_GregoryHouse(typeof(ScheduleController), "FindNextFreeTime");
controller = mr.CreateController<ScheduleController>(
callOnActionExecuting: true,
setupNewDb: db2 => db2.SavingChanges += (s, e) => { isDbChanged = true; });
controller.UtcNowGetter = () => utcNow;
}
catch (Exception ex)
{
InconclusiveInit(ex);
return;
}
JsonResult jsonResult;
{
jsonResult = controller.FindNextFreeTime("", "");
}
Assert.IsFalse(isDbChanged, "Database should not be changed.");
dynamic data = jsonResult.Data;
Assert.AreEqual("12/09/2012", data.date);
Assert.AreEqual("15:00", data.start);
Assert.AreEqual("15:30", data.end);
Assert.AreEqual("quarta-feira, hoje", data.dateSpelled);
}
示例11: Delete_HappyPath
public void Delete_HappyPath()
{
ScheduleController controller;
Appointment appointment;
try
{
// Creating practice and doctor.
var docAndre = Firestarter.Create_CrmMg_Psiquiatria_DrHouse_Andre(this.db);
Firestarter.SetupDoctor(docAndre, this.db);
Firestarter.CreateFakePatients(docAndre, db, 1);
Patient patient = docAndre.Patients.First();
var referenceTime = DateTime.UtcNow;
appointment = new Appointment
{
Doctor = docAndre,
CreatedBy = docAndre.Users.First(),
CreatedOn = referenceTime,
PatientId = patient.Id,
Start = referenceTime,
End = referenceTime + TimeSpan.FromMinutes(30),
PracticeId = docAndre.PracticeId,
HealthInsuranceId = docAndre.HealthInsurances.First(hi => hi.IsActive).Id,
};
this.db.Appointments.AddObject(appointment);
this.db.SaveChanges();
// Creating Asp.Net Mvc mocks.
var mr = new MockRepository(true);
mr.SetRouteData_ConsultorioDrHouse_GregoryHouse(typeof(ScheduleController), "Create");
controller = mr.CreateController<ScheduleController>();
}
catch (Exception ex)
{
InconclusiveInit(ex);
return;
}
controller.Delete(appointment.Id);
var deletedAppointment = this.db.Appointments.FirstOrDefault(a => a.Id == appointment.Id);
Assert.IsNull(deletedAppointment);
}
示例12: Create_SaveWithEmptyFormModel
public void Create_SaveWithEmptyFormModel()
{
ScheduleController controller;
bool isDbChanged = false;
AppointmentViewModel vm;
var localNow = new DateTime(2012, 07, 19, 12, 00, 00, 000);
// Setting Now to be on an thursday, mid day.
// We know that Dr. House lunch time is from 12:00 until 13:00.
try
{
// Creating practice and doctor.
var docAndre = Firestarter.Create_CrmMg_Psiquiatria_DrHouse_Andre(this.db);
Firestarter.SetupDoctor(docAndre, this.db);
var timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(docAndre.Users.First().Practice.WindowsTimeZoneId);
// Dates that will be used by this test.
// - utcNow and localNow: used to mock Now values from Utc and User point of view.
var utcNow = TimeZoneInfo.ConvertTimeToUtc(localNow, timeZoneInfo);
// Creating Asp.Net Mvc mocks.
var mr = new MockRepository(true);
mr.SetRouteData_ConsultorioDrHouse_GregoryHouse(typeof(ScheduleController), "Create");
controller = mr.CreateController<ScheduleController>(
setupNewDb: db2 => db2.SavingChanges += (s, e) => { isDbChanged = true; });
controller.UtcNowGetter = () => utcNow;
// Setting view-model values to create a new appointment.
// - this view-model must be valid for this test... if some day it becomes invalid,
// then it must be made valid again.
vm = new AppointmentViewModel();
Mvc3TestHelper.SetModelStateErrors(controller, vm);
}
catch (Exception ex)
{
InconclusiveInit(ex);
return;
}
// View new appointment.
// This must be ok, no exceptions, no validation errors.
ActionResult actionResult;
{
actionResult = controller.Create(vm);
}
// Verifying the ActionResult.
Assert.IsNotNull(actionResult, "The result of the controller method is null.");
// Verifying the view-model.
Assert.AreEqual(DateAndTimeValidationState.Failed, vm.DateAndTimeValidationState);
// Verifying the controller.
Assert.AreEqual(controller.ViewBag.IsEditingOrCreating, 'C');
Assert.IsInstanceOfType(controller.ViewBag.HealthInsuranceSelectItems, typeof(List<SelectListItem>));
Assert.AreEqual(3, ((List<SelectListItem>)controller.ViewBag.HealthInsuranceSelectItems).Count);
Assert.IsFalse(controller.ModelState.IsValid, "ModelState should be invalid.");
// Verifying the DB.
Assert.IsFalse(isDbChanged, "Create actions must not change DB when there is an error.");
}
示例13: Create_SaveAppointment_HappyPath
public void Create_SaveAppointment_HappyPath()
{
ScheduleController controller;
bool isDbChanged = false;
AppointmentViewModel vm;
// Dates that will be used by this test.
// - utcNow and localNow: used to mock Now values from Utc and User point of view.
// - start and end: start and end time of the appointments that will be created.
DateTime utcStart, utcEnd;
var localNow = new DateTime(2012, 11, 09, 13, 00, 00, 000);
// We know that Dr. House works only after 13:00, so we need to set appointments after that.
var start = localNow.Date.AddDays(+7).AddHours(13);
var end = start.AddMinutes(30);
Patient patient;
try
{
// Creating practice, doctor and patient.
var docAndre = Firestarter.Create_CrmMg_Psiquiatria_DrHouse_Andre(this.db);
Firestarter.SetupDoctor(docAndre, this.db);
patient = Firestarter.CreateFakePatients(docAndre, this.db, 1)[0];
patient.LastUsedHealthInsuranceId = null;
this.db.SaveChanges();
var timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(docAndre.Users.Single().Practice.WindowsTimeZoneId);
DateTime utcNow = TimeZoneInfo.ConvertTimeToUtc(localNow, timeZoneInfo);
utcStart = TimeZoneInfo.ConvertTimeToUtc(start, timeZoneInfo);
utcEnd = TimeZoneInfo.ConvertTimeToUtc(end, timeZoneInfo);
// Creating Asp.Net Mvc mocks.
var mr = new MockRepository(true);
mr.SetRouteData_ConsultorioDrHouse_GregoryHouse(typeof(ScheduleController), "Create");
controller = mr.CreateController<ScheduleController>(
setupNewDb: db2 => db2.SavingChanges += (s, e) => { isDbChanged = true; });
// Mocking 'Now' values.
controller.UtcNowGetter = () => utcNow;
// Setting view-model values to create a new appointment.
// - this view-model must be valid for this test... if some day it becomes invalid,
// then it must be made valid again.
vm = new AppointmentViewModel
{
PatientId = patient.Id,
PatientNameLookup = patient.Person.FullName,
HealthInsuranceId = docAndre.HealthInsurances.First(hi => hi.IsActive).Id,
LocalDateTime = start.Date,
DoctorId = docAndre.Id,
Start = start.ToString("HH:mm"),
End = end.ToString("HH:mm"),
IsGenericAppointment = false,
Status = (int)TypeAppointmentStatus.Undefined,
};
Mvc3TestHelper.SetModelStateErrors(controller, vm);
}
catch (Exception ex)
{
InconclusiveInit(ex);
return;
}
// View new appointment.
// This must be ok, no exceptions, no validation errors.
ActionResult actionResult;
{
actionResult = controller.Create(vm);
}
// Verifying the ActionResult.
Assert.IsNotNull(actionResult, "The result of the controller method is null.");
Assert.IsInstanceOfType(actionResult, typeof(JsonResult));
var jsonResult = (JsonResult)actionResult;
Assert.AreEqual("success", ((dynamic)jsonResult.Data).status);
// Verifying the view-model.
// todo: this should verify a mocked message, but cannot mock messages until languages are implemented.
Assert.AreEqual(
null,
vm.TimeValidationMessage);
Assert.AreEqual(DateAndTimeValidationState.Passed, vm.DateAndTimeValidationState);
// Verifying the controller.
Assert.IsTrue(controller.ModelState.IsValid, "ModelState is not valid, but should be.");
// Verifying the DB.
Assert.IsTrue(isDbChanged, "Create actions must change DB.");
using (var db2 = DbTestBase.CreateNewCerebelloEntities())
{
int appointmentsCountAtSameTime = db2.Appointments
.Count(a => a.Start == utcStart && a.End == utcEnd);
Assert.AreEqual(1, appointmentsCountAtSameTime);
var savedPatient = db2.Patients.Single(p => p.Id == patient.Id);
Assert.AreEqual(vm.HealthInsuranceId, savedPatient.LastUsedHealthInsuranceId);
//.........这里部分代码省略.........
示例14: Create_SaveAppointmentWhenStatusIsSetForThePast_NotAccomplished
public void Create_SaveAppointmentWhenStatusIsSetForThePast_NotAccomplished()
{
ScheduleController controller;
AppointmentViewModel vm;
try
{
// Creating practice, doctor and patient.
var docAndre = Firestarter.Create_CrmMg_Psiquiatria_DrHouse_Andre(this.db);
Firestarter.SetupDoctor(docAndre, this.db);
var patient = Firestarter.CreateFakePatients(docAndre, this.db, 1)[0];
patient.LastUsedHealthInsuranceId = null;
this.db.SaveChanges();
var timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(docAndre.Users.Single().Practice.WindowsTimeZoneId);
var localNow = new DateTime(2012, 11, 09, 13, 00, 00, 000);
var utcNow = TimeZoneInfo.ConvertTimeToUtc(localNow, timeZoneInfo);
// finds a free time in the past week.
var db2 = new CerebelloEntitiesAccessFilterWrapper(this.db);
db2.SetCurrentUserById(docAndre.Users.Single().Id);
var freeTimeInPastWeek = ScheduleController.FindNextFreeTimeInPracticeLocalTime(db2, docAndre, localNow.AddDays(-7));
// Creating Asp.Net Mvc mocks.
var mr = new MockRepository(true);
mr.SetRouteData_ConsultorioDrHouse_GregoryHouse(typeof(ScheduleController), "Create");
controller = mr.CreateController<ScheduleController>();
// Mocking 'Now' values.
controller.UtcNowGetter = () => utcNow;
// Setting view-model values to create a new appointment.
vm = new AppointmentViewModel
{
PatientId = patient.Id,
PatientNameLookup = patient.Person.FullName,
HealthInsuranceId = docAndre.HealthInsurances.First(hi => hi.IsActive).Id,
LocalDateTime = freeTimeInPastWeek.Item1.Date,
DoctorId = docAndre.Id,
Start = freeTimeInPastWeek.Item1.ToString("HH:mm"),
End = freeTimeInPastWeek.Item2.ToString("HH:mm"),
IsGenericAppointment = false,
// this should work because it's in the past
Status = (int)TypeAppointmentStatus.NotAccomplished,
};
Mvc3TestHelper.SetModelStateErrors(controller, vm);
}
catch (Exception ex)
{
InconclusiveInit(ex);
return;
}
controller.Create(vm);
Assert.IsTrue(controller.ModelState.IsValid);
}
示例15: Index_UserIsOwner
public void Index_UserIsOwner()
{
PracticeHomeController homeController;
var mr = new MockRepository();
try
{
mr.SetCurrentUser_Andre_CorrectPassword();
mr.SetRouteData_ConsultorioDrHouse_GregoryHouse(typeof(PracticeHomeController), "Index");
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);
}