本文整理汇总了C#中MockRepository.CreateController方法的典型用法代码示例。如果您正苦于以下问题:C# MockRepository.CreateController方法的具体用法?C# MockRepository.CreateController怎么用?C# MockRepository.CreateController使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MockRepository
的用法示例。
在下文中一共展示了MockRepository.CreateController方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Delete_HappyPath
public void Delete_HappyPath()
{
// obtains a valid patient
Firestarter.CreateFakePatients(this.db.Doctors.First(), this.db, 1);
this.db.SaveChanges();
var patientId = this.db.Patients.First().Id;
var formModel = new DiagnosisViewModel
{
PatientId = patientId,
Text = "This is my diagnosis",
Cid10Code = "Q878",
Cid10Name = "Doença X"
};
var mr = new MockRepository(true);
var controller = mr.CreateController<DiagnosisController>();
controller.Create(new[] { formModel });
Assert.IsTrue(controller.ModelState.IsValid);
// get's the newly created diagnosis
var newlyCreatedDiagnosis = this.db.Diagnoses.First();
// tries to delete the anamnese
var result = controller.Delete(newlyCreatedDiagnosis.Id);
var deleteMessage = (JsonDeleteMessage)result.Data;
Assert.AreEqual(true, deleteMessage.success);
Assert.AreEqual(0, this.db.Anamnese.Count());
}
示例2: 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);
}
示例3: 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);
}
示例4: Delete_HappyPath
public void Delete_HappyPath()
{
// obtains a valid patient
Firestarter.CreateFakePatients(this.db.Doctors.First(), this.db);
this.db.SaveChanges();
var patientId = this.db.Patients.First().Id;
var formModel = new AnamneseViewModel()
{
PatientId = patientId,
Conclusion = "This is my anamnese",
DiagnosticHypotheses = new List<DiagnosticHypothesisViewModel>() {
new DiagnosticHypothesisViewModel() { Text = "Text", Cid10Code = "Q878" },
new DiagnosticHypothesisViewModel() { Text = "Text2", Cid10Code = "Q879" }
}
};
var mr = new MockRepository(true);
var controller = mr.CreateController<AnamnesesController>();
controller.Create(new[] { formModel });
Assert.IsTrue(controller.ModelState.IsValid);
// get's the newly created anamnese
var newlyCreatedAnamnese = this.db.Anamnese.First();
// tries to delete the anamnese
var result = controller.Delete(newlyCreatedAnamnese.Id);
JsonDeleteMessage deleteMessage = (JsonDeleteMessage)result.Data;
Assert.AreEqual(true, deleteMessage.success);
Assert.AreEqual(0, this.db.Anamnese.Count());
}
示例5: Delete_HappyPath
public void Delete_HappyPath()
{
// obtains a valid patient
Firestarter.CreateFakePatients(this.db.Doctors.First(), this.db);
this.db.SaveChanges();
var patientId = this.db.Patients.First().Id;
// obtains a valid certificate model
ModelMedicalCertificateViewModel certificateModelFormModel = new ModelMedicalCertificateViewModel()
{
Name = "My Model",
Text = "This is a reference: <%FIELD_1%>"
};
var mr = new MockRepository(true);
var certificateModelController = mr.CreateController<ModelMedicalCertificatesController>();
var certificateModelControllerResult = certificateModelController.Edit(certificateModelFormModel);
var certificateModel = this.db.ModelMedicalCertificates.First();
// tries to save a certificate based on that model
MedicalCertificateViewModel formModel = new MedicalCertificateViewModel()
{
ModelId = certificateModel.Id,
PatientId = patientId,
Fields = new List<MedicalCertificateFieldViewModel>()
{
new MedicalCertificateFieldViewModel() { Name = "field_1", Value = "value 1" }
}
};
var certificateController = mr.CreateController<MedicalCertificatesController>();
var certificateControllerResult = certificateController.Edit(new[] { formModel });
var certificate = this.db.MedicalCertificates.First();
// tries to delete the certificate
var result = certificateController.Delete(certificate.Id);
JsonDeleteMessage deleteMessage = (JsonDeleteMessage)result.Data;
Assert.AreEqual(true, deleteMessage.success, "deleteMessage.success must be true");
Assert.AreEqual(0, this.db.MedicalCertificates.Count());
}
示例6: Delete_ShouldReturnProperResultWhenNotExisting
public void Delete_ShouldReturnProperResultWhenNotExisting()
{
var mr = new MockRepository(true);
var controller = mr.CreateController<AnamnesesController>();
// tries to delete the anamnese
var result = controller.Delete(999);
JsonDeleteMessage deleteMessage = (JsonDeleteMessage)result.Data;
Assert.AreEqual(false, deleteMessage.success);
Assert.IsNotNull(deleteMessage.text);
}
示例7: 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.");
}
示例8: Create_1_HappyPath
public void Create_1_HappyPath()
{
ExamsController controller;
Patient patient;
try
{
var doctor = Firestarter.Create_CrmMg_Psiquiatria_DrHouse_Andre(this.db);
patient = Firestarter.CreateFakePatients(doctor, this.db).First();
var mr = new MockRepository(true);
controller = mr.CreateController<ExamsController>();
}
catch (Exception ex)
{
InconclusiveInit(ex);
return;
}
// Creating a new examination request.
ActionResult actionResult;
{
var medicalProc = this.db.SYS_MedicalProcedure.Single(x => x.Code == "4.03.04.36-1");
var viewModel = new ExaminationRequestViewModel
{
PatientId = patient.Id,
Notes = "Any text",
MedicalProcedureId = medicalProc.Id,
MedicalProcedureName = "Hemograma com contagem de plaquetas ou frações (eritrograma, leucograma, plaquetas)",
};
actionResult = controller.Create(new[] { viewModel });
}
// Verifying the ActionResult.
Assert.IsNotNull(actionResult, "The result of the controller method is null.");
// Verifying the controller model-state.
Assert.IsTrue(controller.ModelState.IsValid, "ModelState is not valid.");
// Verifying the database.
Assert.IsTrue(this.db.ExaminationRequests.Any(x => x.PatientId == patient.Id), "Database record was not saved.");
// Verifying the database.
using (var db2 = DbTestBase.CreateNewCerebelloEntities())
{
var obj = db2.ExaminationRequests.FirstOrDefault(x => x.PatientId == patient.Id);
Assert.IsNotNull(obj, "Database record was not saved.");
Assert.AreEqual("Any text", obj.Text);
Assert.AreEqual("4.03.04.36-1", obj.MedicalProcedureCode);
Assert.AreEqual("Hemograma com contagem de plaquetas ou frações (eritrograma, leucograma, plaquetas)", obj.MedicalProcedureName);
}
}
示例9: Search_ShouldRespectTheSearchTermWhenItsPresent
public void Search_ShouldRespectTheSearchTermWhenItsPresent()
{
LaboratoriesController controller;
try
{
var mr = new MockRepository(true);
controller = mr.CreateController<LaboratoriesController>();
controller.Create(
new MedicineLaboratoryViewModel()
{
Name = "Bash"
});
controller.Create(
new MedicineLaboratoryViewModel()
{
Name = "Novartis"
});
}
catch (Exception ex)
{
InconclusiveInit(ex);
return;
}
const string searchTerm = "ba";
// making an empty search
var result = controller.Search(
new SearchModel()
{
Term = searchTerm,
Page = 1
});
Assert.IsInstanceOfType(result, typeof(ViewResult));
var resultAsView = result as ViewResult;
Debug.Assert(resultAsView != null, "resultAsView must not null");
Assert.IsInstanceOfType(resultAsView.Model, typeof(SearchViewModel<MedicineLaboratoryViewModel>));
var model = resultAsView.Model as SearchViewModel<MedicineLaboratoryViewModel>;
Debug.Assert(model != null, "model must not be null");
Assert.AreEqual(1, model.Count);
}
示例10: Delete_WhenTheresADiagnosis
public void Delete_WhenTheresADiagnosis()
{
PatientsController controller;
Patient patient;
try
{
var docAndre = Firestarter.Create_CrmMg_Psiquiatria_DrHouse_Andre(this.db);
var mr = new MockRepository(true);
controller = mr.CreateController<PatientsController>();
Firestarter.CreateFakePatients(docAndre, this.db, 1);
// we now have 1 patient
patient = this.db.Patients.FirstOrDefault();
Assert.IsNotNull(patient);
var referenceTime = DateTime.UtcNow;
var diagnosis = new Diagnosis()
{
CreatedOn = referenceTime,
PatientId = patient.Id,
Cid10Code = "QAA",
Cid10Name = "Doença X", // x-men!
PracticeId = docAndre.PracticeId,
};
this.db.Diagnoses.AddObject(diagnosis);
this.db.SaveChanges();
}
catch
{
Assert.Inconclusive("Test initialization has failed.");
return;
}
controller.Delete(patient.Id);
// this patient must have been deleted
patient = this.db.Patients.FirstOrDefault(p => p.Id == patient.Id);
Assert.IsNull(patient);
}
示例11: AnvisaImport_HappyPath
public void AnvisaImport_HappyPath()
{
MedicinesController controller;
SYS_Medicine sysMedicine;
try
{
var mr = new MockRepository(true);
controller = mr.CreateController<MedicinesController>();
sysMedicine = this.db.SYS_Medicine.FirstOrDefault();
if (sysMedicine == null)
throw new Exception("SYS_Medicines are not populated");
}
catch
{
Assert.Inconclusive("Test initialization has failed.");
return;
}
// todo: commented code - old test code, must remake this test
//controller.AnvisaImport(
// new AnvisaImportViewModel()
// {
// AnvisaId = sysMedicine.Id,
// AnvisaText = sysMedicine.Name
// });
var medicine = this.db.Medicines.FirstOrDefault(m => m.Name == sysMedicine.Name);
Assert.IsNotNull(medicine);
foreach (var activeIngredient in medicine.ActiveIngredients)
Assert.IsTrue(sysMedicine.ActiveIngredients.Any(ai => ai.Name == activeIngredient.Name));
foreach (var leaflet in medicine.Leaflets)
Assert.IsTrue(sysMedicine.Leaflets.Any(l => l.Url == leaflet.Url));
Assert.IsTrue(sysMedicine.Laboratory.Name == medicine.Laboratory.Name);
}
示例12: Delete_WhenTheresAnExamResult
public void Delete_WhenTheresAnExamResult()
{
PatientsController controller;
int patientId;
Patient patient;
try
{
var doctor = Firestarter.Create_CrmMg_Psiquiatria_DrHouse_Andre(this.db);
var mr = new MockRepository(true);
controller = mr.CreateController<PatientsController>();
Firestarter.CreateFakePatients(doctor, this.db, 1);
// we now have 1 patient
patient = this.db.Patients.FirstOrDefault();
Assert.IsNotNull(patient);
patientId = patient.Id;
var examResult = new ExaminationResult()
{
MedicalProcedureCode = "mcode",
MedicalProcedureName = "mname",
PatientId = patientId,
CreatedOn = DateTime.UtcNow,
Text = "tudo deu certo",
PracticeId = doctor.PracticeId,
};
this.db.SYS_MedicalProcedure.AddObject(
new SYS_MedicalProcedure()
{
Code = "mcode",
Name = "mname"
});
this.db.ExaminationResults.AddObject(examResult);
this.db.SaveChanges();
}
catch
{
Assert.Inconclusive("Test initialization has failed.");
return;
}
controller.Delete(patientId);
// this patient must have been deleted
patient = this.db.Patients.FirstOrDefault(p => p.Id == patientId);
Assert.IsNull(patient);
}
示例13: Delete_WhenTheresAnAppointment
public void Delete_WhenTheresAnAppointment()
{
PatientsController controller;
Patient patient;
try
{
var docAndre = Firestarter.Create_CrmMg_Psiquiatria_DrHouse_Andre(this.db);
var mr = new MockRepository(true);
controller = mr.CreateController<PatientsController>();
Firestarter.CreateFakePatients(docAndre, this.db, 1);
// we now have 1 patient
patient = this.db.Patients.FirstOrDefault();
Assert.IsNotNull(patient);
var referenceTime = DateTime.UtcNow;
var appointment = new Appointment()
{
Doctor = docAndre,
CreatedBy = docAndre.Users.First(),
CreatedOn = referenceTime,
PatientId = patient.Id,
Start = referenceTime,
End = referenceTime + TimeSpan.FromMinutes(30),
PracticeId = docAndre.PracticeId,
};
this.db.Appointments.AddObject(appointment);
this.db.SaveChanges();
}
catch
{
Assert.Inconclusive("Test initialization has failed.");
return;
}
controller.Delete(patient.Id);
// this patient must have been deleted
patient = this.db.Patients.FirstOrDefault(p => p.Id == patient.Id);
Assert.IsNull(patient);
}
示例14: Delete_WhenTheresAnAnamnese
public void Delete_WhenTheresAnAnamnese()
{
PatientsController controller;
int patientId;
Patient patient;
try
{
var doctor = Firestarter.Create_CrmMg_Psiquiatria_DrHouse_Andre(this.db);
var mr = new MockRepository(true);
controller = mr.CreateController<PatientsController>();
Firestarter.CreateFakePatients(doctor, this.db, 1);
// we now have 1 patient
patient = this.db.Patients.FirstOrDefault();
Assert.IsNotNull(patient);
patientId = patient.Id;
// now, let's add an anamnese
var anamnese = new Anamnese()
{
PatientId = patientId,
CreatedOn = DateTime.UtcNow,
Conclusion = "This is my anamnese",
PracticeId = doctor.PracticeId,
};
patient.Anamneses.Add(anamnese);
this.db.SaveChanges();
}
catch
{
Assert.Inconclusive("Test initialization has failed.");
return;
}
controller.Delete(patientId);
// this patient must have been deleted
patient = this.db.Patients.FirstOrDefault(p => p.Id == patientId);
Assert.IsNull(patient);
}
示例15: LookupEverything_1_ShouldSearchPatients
public void LookupEverything_1_ShouldSearchPatients()
{
var doctor = this.db.Doctors.First();
// create some fake patients
// patient 1
Patient patient1 = new Patient()
{
Person = new Person()
{
FullName = "Joao Manuel da Silva",
Gender = (int)TypeGender.Male,
DateOfBirth = Firestarter.ConvertFromDefaultToUtc(new DateTime(1982, 10, 12)),
MaritalStatus = (int)TypeMaritalStatus.Casado,
BirthPlace = "Brasileiro",
CPF = "87324128910",
CPFOwner = (int)TypeCpfOwner.PatientItself,
Profession = "Encarregado de Obras",
CreatedOn = DateTime.UtcNow,
PracticeId = doctor.PracticeId,
},
Doctor = doctor,
PracticeId = doctor.PracticeId,
};
patient1.Person.Email = "[email protected]";
patient1.Person.Addresses.Add(
new Address
{
CEP = "602500330",
StateProvince = "RJ",
City = "Rio de Janeiro",
Neighborhood = "Jacarepaguá",
Street = "Rua Estrada do Pau Ferro 329",
Complement = "",
PracticeId = doctor.PracticeId,
});
db.Patients.AddObject(patient1);
Patient patient2 = new Patient()
{
Person = new Person()
{
FullName = "Manuela Moreira da Silva",
Gender = (int)TypeGender.Female,
DateOfBirth = Firestarter.ConvertFromDefaultToUtc(new DateTime(1982, 10, 12)),
MaritalStatus = (int)TypeMaritalStatus.Casado,
BirthPlace = "Brasileiro",
CPF = "87324128910",
CPFOwner = (int)TypeCpfOwner.PatientItself,
Profession = "Encarregado de Obras",
CreatedOn = DateTime.UtcNow,
PracticeId = doctor.PracticeId,
},
Doctor = doctor
};
patient1.Person.Email = "[email protected]";
patient1.Person.Addresses.Add(
new Address
{
CEP = "602500330",
StateProvince = "RJ",
City = "Rio de Janeiro",
Neighborhood = "Jacarepaguá",
Street = "Rua Estrada do Pau Ferro 329",
Complement = "",
PracticeId = doctor.PracticeId,
});
db.Patients.AddObject(patient2);
this.db.SaveChanges();
var mr = new MockRepository(true);
var controller = mr.CreateController<AppController>();
var controllerResult = controller.LookupEverything("Joao", 20, 1, this.db.Doctors.First().Id);
var controllerResultAsLookupResult = (AutocompleteJsonResult)controllerResult.Data;
Assert.AreEqual(1, controllerResultAsLookupResult.Rows.Count);
Assert.IsInstanceOfType(controllerResultAsLookupResult.Rows[0], typeof(GlobalSearchViewModel));
Assert.AreEqual(patient1.Person.FullName, ((GlobalSearchViewModel)controllerResultAsLookupResult.Rows[0]).Value);
Assert.AreEqual(patient1.Id, ((GlobalSearchViewModel)controllerResultAsLookupResult.Rows[0]).Id);
}