public void Doctors_DetailGrid_Empty() { //Arrange var cRepository = new Mock <IClinicRepository>(); var controller = new AdministrationController(cRepository.Object); var clinicId = 222; var clinic = new Clinic { Id = clinicId, Caption = "Clinic111", Doctors = new List <User>() }; cRepository.Setup(r => r.GetByKey(clinicId)).Returns(clinic); //Act var result = controller.ClinicDoctors(clinicId); //Assert Assert.That(result, Is.Not.Null); Assert.That(result is PartialViewResult); var viewResultBase = result as ViewResultBase; Assert.That(viewResultBase.Model, Is.Not.Null); Assert.That(viewResultBase.ViewName, Is.EqualTo("_ClinicDoctorsGrid")); Assert.That(viewResultBase.Model is ClinicDetailsViewModel); var model = viewResultBase.Model as ClinicDetailsViewModel; Assert.That(model.Doctors.Count, Is.EqualTo(0)); Assert.That(model.ClinicId, Is.EqualTo(clinicId)); cRepository.Verify(r => r.GetByKey(clinicId), Times.Once()); }
public void Doctors_DetailGrid_IncorrectClinicId() { //Arrange var cRepository = new Mock <IClinicRepository>(); var controller = new AdministrationController(cRepository.Object); cRepository.Setup(r => r.GetByKey(It.IsAny <int>())).Returns(new Clinic()); //Act var result = controller.ClinicDoctors(null); //Assert Assert.That(result, Is.Not.Null); Assert.That(result is ViewResultBase); var viewResultBase = result as ViewResultBase; Assert.That(viewResultBase.Model, Is.Not.Null); Assert.That(viewResultBase.ViewName, Is.EqualTo("_ErrorInfo")); Assert.That(viewResultBase.Model is ErrorViewModel); var model = viewResultBase.Model as ErrorViewModel; Assert.That(model.Caption, Is.EqualTo("Clinic is not found")); cRepository.Verify(r => r.GetByKey(It.IsAny <int>()), Times.Never()); }
public void Doctors_DetailGrid() { //Arrange var cRepository = new Mock <IClinicRepository>(); var controller = new AdministrationController(cRepository.Object); var clinicId = 111; var doctor1 = new User { Id = 10, FirstName = "First10", LastName = "Last10", Role = "Doctor", Patients = new List <Patient> { new Patient() }, Login = "******", Photo = new byte[] { 1, 2, 3 } }; var doctor2 = new User { Id = 20, FirstName = "First20", LastName = "Last20", Role = "Supervisor", Patients = new List <Patient> { new Patient(), new Patient() }, Login = "******", Photo = new byte[] { 3, 4, 5 } }; var clinic = new Clinic { Id = clinicId, Caption = "Clinic111", Doctors = new List <User> { doctor1, doctor2 } }; cRepository.Setup(r => r.GetByKey(clinicId)).Returns(clinic); //Act var result = controller.ClinicDoctors(clinicId); //Assert Assert.That(result, Is.Not.Null); Assert.That(result is PartialViewResult); var viewResultBase = result as ViewResultBase; Assert.That(viewResultBase.Model, Is.Not.Null); Assert.That(viewResultBase.ViewName, Is.EqualTo("_ClinicDoctorsGrid")); Assert.That(viewResultBase.Model is ClinicDetailsViewModel); var model = viewResultBase.Model as ClinicDetailsViewModel; Assert.That(model.Doctors, Is.Not.Null); Assert.That(model.Doctors.Count, Is.EqualTo(2)); Assert.That(model.ClinicId, Is.EqualTo(111)); Assert.That(model.Doctors[0].ClinicId, Is.EqualTo(111)); Assert.That(model.Doctors[0].DoctorId, Is.EqualTo(10)); Assert.That(model.Doctors[0].FirstName, Is.EqualTo("First10")); Assert.That(model.Doctors[0].LastName, Is.EqualTo("Last10")); Assert.That(model.Doctors[0].Role, Is.EqualTo("Doctor")); Assert.That(model.Doctors[0].PatientsCount, Is.EqualTo(1)); Assert.That(model.Doctors[0].Login, Is.EqualTo("login10")); Assert.That(model.Doctors[0].Photo, Is.EqualTo(new byte[] { 1, 2, 3 })); Assert.That(model.Doctors[1].ClinicId, Is.EqualTo(111)); Assert.That(model.Doctors[1].DoctorId, Is.EqualTo(20)); Assert.That(model.Doctors[1].FirstName, Is.EqualTo("First20")); Assert.That(model.Doctors[1].LastName, Is.EqualTo("Last20")); Assert.That(model.Doctors[1].Role, Is.EqualTo("Supervisor")); Assert.That(model.Doctors[1].PatientsCount, Is.EqualTo(2)); Assert.That(model.Doctors[1].Login, Is.EqualTo("login20")); Assert.That(model.Doctors[1].Photo, Is.EqualTo(new byte[] { 3, 4, 5 })); cRepository.Verify(r => r.GetByKey(clinicId), Times.Once()); }