public void PatientValidResult() { IActionResult result = controller.Get(1); Assert.IsNotNull(result); Assert.AreEqual(result.GetType(), typeof(ActionResult)); Assert.Pass(); }
public void ControllerGet_Returns_PatientWithEpisodes_WhenPatientIdPresent() { var patientResult = patientsController.Get(1) as OkNegotiatedContentResult <Patient>; var patient = patientResult.Content; Assert.AreEqual(patient.PatientId, 1, "PatientId mismatch"); Assert.IsTrue(!string.IsNullOrEmpty(patient.NhsNumber), "Nhs number not present."); Assert.IsTrue(patient.Episodes.Any(), "No episodes found."); }
public void GetReturnsListOfPatients() { //Arrange repository.Setup(m => m.Get()).Returns(Task.FromResult(new List <Patient>() as IEnumerable <Patient>)); //Act var result = controller.Get().Result; //Assert Assert.IsInstanceOfType(result, typeof(IEnumerable <Patient>)); }
public void PatientGetTest() { var patientModel = new PatientModel() { Forenames = "Siva", Surname = "Nomula", Gender = "M", DateofBirth = DateTime.Parse("20-12-1982"), Id = 1, Telephonenumbers = new List <PhoneNumber>() { new PhoneNumber { PhoneType = PhoneType.Home, Number = "123456789" }, new PhoneNumber { PhoneType = PhoneType.Mobile, Number = "987654321" }, new PhoneNumber { PhoneType = PhoneType.Work, Number = "678912345" }, } }; var controller = new PatientsController(manager.Object); IActionResult actionResult = controller.Get(1); var contentResult = actionResult as OkObjectResult; Assert.IsTrue(((PatientModel)contentResult.Value).Id.Equals(1)); Assert.AreEqual("Siva", patientModel.Forenames); }
public void GetPatientControllerWithMoqTest() { //Setup patient mock var patientMockList = SetupMockPatientData(); //Constructing mock IDbSet<Patient> ,so that we can return mock Patient DBSet from PatientContext var mockPatient = new Mock <IDbSet <Patient> >(); var patientMockListQ = patientMockList.AsQueryable(); mockPatient.As <IQueryable <Patient> >().Setup(m => m.Provider).Returns(patientMockListQ.Provider); mockPatient.As <IQueryable <Patient> >().Setup(m => m.Expression).Returns(patientMockListQ.Expression); mockPatient.As <IQueryable <Patient> >().Setup(m => m.ElementType).Returns(patientMockListQ.ElementType); mockPatient.As <IQueryable <Patient> >().Setup(m => m.GetEnumerator()).Returns(patientMockListQ.GetEnumerator()); //setting up PatientContext to return Mocked IDbSet<Patient> var patientContext = new Mock <IDatabaseContext>(); patientContext.Setup(p => p.Patients).Returns(mockPatient.Object); //Passing the PatientContext which has the mocked Patient DBset(not from Database) to PatientsController layer ,to test Get method PatientsController patientsController = new PatientsController(patientContext.Object); var httpPatientResponse = patientsController.Get(101); var expectedPatientList = JsonConvert.DeserializeObject <List <Patient> >(httpPatientResponse.Content.ReadAsStringAsync().Result); //check if the list is not empty and has actual number of episodes as exist in the mock data Assert.IsNotNull(expectedPatientList, "Patient mock obbject is not null"); Assert.IsTrue(expectedPatientList.Any(p => p.Episodes.Count() == 4), "Patient and Episodes visit equal test passed"); }
public void GetDetailsTest() { var res = new Mock <PatientRep>(db); PatientsController obj = new PatientsController(res.Object); var data = obj.Get(); var okResult = data as OkObjectResult; Assert.AreEqual(200, okResult.StatusCode); }
public void GetAllPatient_ShouldReturnAllPatient() { var testPatients = GetTestPatient(); var controller = new PatientsController(); var result = controller.Get() as List <PatientVM>; Assert.AreEqual(testPatients.Count, result.Count); }
public void GetPatient_CheckingNullTest_ReturnNull() { //ARRANGE int patientId = 5; var patientsController = new PatientsController(patientRepository); //ACT var actualPatient = patientsController.Get(patientId); //ASSERT Assert.That(actualPatient, Is.Null); }
public void PatientsControllerGet_InvalidPatientId_ThrowsValidationException() { int patientId = 0; var mediatorMock = Substitute.For <IMediator>(); var loggerMock = Substitute.For <ILogger <PatientsController> >(); var patient = new Fixture().Create <PatientDto>(); mediatorMock.Send(Arg.Any <GetPatientQuery>()).Returns(patient); var sut = new PatientsController(mediatorMock, loggerMock); Assert.ThrowsAsync <ValidationException>(async() => await sut.Get(patientId)); loggerMock.Received(1); }
public void GetPatientById_NotNullResponse_Test() { //Arrage IDbContext dbContext = new MedicalAppointmentContext(); IRepository repository = new PatientRepository(dbContext); var sut = new PatientsController(repository); //Act var result = sut.Get(1) as OkNegotiatedContentResult <IPatient>; var patientResult = result.Content as Patient; //Assert Assert.IsNotNull(result); Assert.IsNotNull(patientResult); }
public void PatientNotFound() { // Get Controller var controller = new PatientsController(_dbContext); var configuration = new HttpConfiguration(); var request = new System.Net.Http.HttpRequestMessage(); request.Properties[System.Web.Http.Hosting.HttpPropertyKeys.HttpConfigurationKey] = configuration; controller.Request = request; controller.Configuration = configuration; // Act on Test var response = controller.Get(10); // Assert the result Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode); }
public void GetPatient_NotFound(int patientId) { // Arrange var context = new TestPatientAppContext(); context.Patients.Add(GetDemoPatient()); var controller = new PatientsController(context); controller.Request = new HttpRequestMessage(); controller.Request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration()); // Act var actionResult = controller.Get(patientId) as HttpResponseMessage; // Assert Assert.AreEqual(actionResult.StatusCode, HttpStatusCode.NotFound); }
public void GetPatientById_InvalidID_Returns_HttpStatusCode_NotFound() { // Arrange var businessServiceMock = new Mock <IBusinessService>(); businessServiceMock.Setup(service => service.GetPatientById(10)).Returns((PatientEntity)null); var controller = new PatientsController(businessServiceMock.Object); // Act var actionResult = controller.Get(10); // Assert var negResult = actionResult as NotFoundResult; Assert.IsNotNull(negResult); }
public void GetPatientControllerWithInMemoryTest() { //Setup patient mock InMemoryPatientContext inMemoryPatientContext = new InMemoryPatientContext(); foreach (var item in SetupMockPatientData()) { inMemoryPatientContext.Patients.Add(item); } PatientsController patientsController = new PatientsController(inMemoryPatientContext); var httpPatientResponse = patientsController.Get(102); var expectedPatientList = JsonConvert.DeserializeObject <List <Patient> >(httpPatientResponse.Content.ReadAsStringAsync().Result); //check if the list is not empty and has actual number of episodes as exist in the mock data Assert.IsNotNull(expectedPatientList, "Patient mock obbject is not null"); Assert.IsTrue(expectedPatientList.Any(p => p.Episodes.Count() == 3), "Patient and Episodes visit equal test passed"); }
public void EmpolyeeNotExistForPatient() { // Get Controller var controller = new PatientsController(_dbContext); var configuration = new HttpConfiguration(); var request = new System.Net.Http.HttpRequestMessage(); request.Properties[System.Web.Http.Hosting.HttpPropertyKeys.HttpConfigurationKey] = configuration; controller.Request = request; controller.Configuration = configuration; // Act on Test var response = controller.Get(2); Patient patient; Assert.IsTrue(response.TryGetContentValue <Patient>(out patient)); // Assert the result Assert.IsNull(patient.Episodes); }
public async Task PatientsControllerGet_ValidGetPatientQuery_GetsPatient() { int patientId = 1; var mediatorMock = Substitute.For <IMediator>(); var loggerMock = Substitute.For <ILogger <PatientsController> >(); var patient = new Fixture().Create <PatientDto>(); mediatorMock.Send(Arg.Any <GetPatientQuery>()).Returns(patient); var sut = new PatientsController(mediatorMock, loggerMock); var result = await sut.Get(patientId); var okResult = result as OkObjectResult; Assert.IsNotNull(okResult); Assert.That(okResult.StatusCode, Is.EqualTo(200)); Assert.That((okResult.Value as PatientDto), Is.EqualTo(patient)); await mediatorMock.Received(1).Send(Arg.Is <GetPatientQuery>(x => x.PatientId == patientId)); loggerMock.Received(1); }
public async Task PatientsControllerGet_ValidGetAllPatientsQuery_GetsAllPatients() { var mediatorMock = Substitute.For <IMediator>(); var loggerMock = Substitute.For <ILogger <PatientsController> >(); var patients = new Fixture().CreateMany <PatientDto>(3).ToList(); mediatorMock.Send(Arg.Any <GetAllPatientsQuery>()).Returns(patients); GetAllPatientsQuery getAllPatientsQuery = new GetAllPatientsQuery(); var sut = new PatientsController(mediatorMock, loggerMock); var result = await sut.Get(getAllPatientsQuery); var okResult = result as OkObjectResult; Assert.IsNotNull(okResult); Assert.That(okResult.StatusCode, Is.EqualTo(200)); Assert.That((okResult.Value as List <PatientDto>), Is.EquivalentTo(patients)); await mediatorMock.Received(1).Send(Arg.Any <GetAllPatientsQuery>()); loggerMock.Received(1); }
public void PatientFoundWithId() { // Get Controller var controller = new PatientsController(_dbContext); var configuration = new HttpConfiguration(); var request = new System.Net.Http.HttpRequestMessage(); request.Properties[System.Web.Http.Hosting.HttpPropertyKeys.HttpConfigurationKey] = configuration; controller.Request = request; controller.Configuration = configuration; // Act on Test var response = controller.Get(1); // Assert the result Patient patient; Assert.IsTrue(response.TryGetContentValue <Patient>(out patient)); Assert.AreEqual("Millicent", patient.FirstName); }
public void GetAllPatients_Returns_AllPatients() { // Arrange var businessServiceMock = new Mock <IBusinessService>(); businessServiceMock.Setup(service => service.GetAllPatients()).Returns(PatientTestData()); var controller = new PatientsController(businessServiceMock.Object); // Act var actionResult = controller.Get(); // Assert var negResult = actionResult as OkNegotiatedContentResult <List <PatientEntity> >; Assert.IsNotNull(negResult); Assert.AreEqual(3, negResult.Content.Count); Assert.AreEqual(1, negResult.Content[0].Id); Assert.AreEqual("FirstName1", negResult.Content[0].FirstName); Assert.AreEqual("LastName1", negResult.Content[0].LastName); }
public void GetPatientById_ValidDataResponse_Test() { //Arrage IDbContext dbContext = new MedicalAppointmentContext(); IRepository repository = new PatientRepository(dbContext); var sut = new PatientsController(repository); var expectedResult = new Patient() { Id = 1, IdCard = "206680338", Name = "Huber", Lastname = "Espinoza", DateOfBirth = new DateTime(1989, 11, 8) }; //Act var result = sut.Get(1) as OkNegotiatedContentResult <IPatient>; var patientResult = result.Content as Patient; //Assert Assert.AreEqual(expectedResult.Id, patientResult.Id); Assert.AreEqual(expectedResult.IdCard, patientResult.IdCard); Assert.AreEqual(expectedResult.Name, patientResult.Name); Assert.AreEqual(expectedResult.Lastname, patientResult.Lastname); Assert.AreEqual(expectedResult.DateOfBirth, patientResult.DateOfBirth); }
public void GetPatientById_ValidID_Returns_Patient() { // Arrange int id = 2; var businessServiceMock = new Mock <IBusinessService>(); businessServiceMock.Setup(service => service.GetPatientById(id)).Returns(PatientTestData()[1]); var controller = new PatientsController(businessServiceMock.Object); // Act var actionResult = controller.Get(id); // Assert var negResult = actionResult as OkNegotiatedContentResult <PatientEntity>; Assert.IsNotNull(negResult); Assert.IsNotNull(negResult.Content); Assert.AreEqual(id, negResult.Content.Id); Assert.AreEqual("FirstName2", negResult.Content.FirstName); Assert.AreEqual("LastName2", negResult.Content.LastName); }
public void GetPatient_GettingPatientBasedOnPatientIdTest_ReturnPatientRecord() { //ARRANGE int patientId = 1; var patientsController = new PatientsController(patientRepository); var expectedPatient = new Patient() { DateOfBirth = new DateTime(1972, 10, 27), FirstName = "Millicent", PatientId = 1, LastName = "Hammond", NhsNumber = "1111111111" }; //ACT var actualPatient = patientsController.Get(patientId); //ASSERT Assert.That(expectedPatient.DateOfBirth, Is.EqualTo(actualPatient.DateOfBirth)); Assert.That(expectedPatient.FirstName, Is.EqualTo(actualPatient.FirstName)); Assert.That(expectedPatient.LastName, Is.EqualTo(actualPatient.LastName)); Assert.That(expectedPatient.PatientId, Is.EqualTo(actualPatient.PatientId)); Assert.That(expectedPatient.NhsNumber, Is.EqualTo(actualPatient.NhsNumber)); }
public void GetPatientsTest() { var patientId = 0; var result = patientsController.Get(patientId); Assert.NotNull(result.StatusCode); Assert.AreEqual(result.StatusCode, HttpStatusCode.NotFound); Assert.AreEqual(((System.Net.Http.ObjectContent)result.Content).Value, $"Patient not found with patientId :{patientId}."); patientId = 1; result = patientsController.Get(patientId); Assert.NotNull(result.StatusCode); Assert.AreEqual(result.StatusCode, HttpStatusCode.OK); Assert.AreEqual((((System.Net.Http.ObjectContent)result.Content).Value as Patient).PatientId, patientId); patientId = 2; result = patientsController.Get(patientId); Assert.NotNull(result.StatusCode); Assert.AreEqual(result.StatusCode, HttpStatusCode.OK); Assert.AreEqual((((System.Net.Http.ObjectContent)result.Content).Value as Patient).PatientId, patientId); patientId = 3; result = patientsController.Get(patientId); Assert.NotNull(result.StatusCode); Assert.AreEqual(result.StatusCode, HttpStatusCode.OK); Assert.AreEqual((((System.Net.Http.ObjectContent)result.Content).Value as Patient).PatientId, patientId); patientId = 4; result = patientsController.Get(patientId); Assert.NotNull(result.StatusCode); Assert.AreEqual(result.StatusCode, HttpStatusCode.NotFound); Assert.AreEqual(((System.Net.Http.ObjectContent)result.Content).Value, $"Patient not found with patientId :{patientId}."); patientId = int.MinValue; result = patientsController.Get(patientId); Assert.NotNull(result.StatusCode); Assert.AreEqual(result.StatusCode, HttpStatusCode.BadRequest); }
public void GetPatientsTest() { episodesService = new Mock <IEpisodesService>(); episodesService.Setup(service => service.GetEpisodes()).Returns(new List <Episode>() { new Episode { AdmissionDate = new DateTime(2014, 11, 12), Diagnosis = "Irritation of inner ear", DischargeDate = new DateTime(2014, 11, 27), EpisodeId = 1, PatientId = 1 }, new Episode { AdmissionDate = new DateTime(2015, 3, 20), Diagnosis = "Sprained wrist", DischargeDate = new DateTime(2015, 4, 2), EpisodeId = 2, PatientId = 1 }, new Episode { AdmissionDate = new DateTime(2015, 11, 12), Diagnosis = "Stomach cramps", DischargeDate = new DateTime(2015, 11, 14), EpisodeId = 3, PatientId = 1 }, new Episode { AdmissionDate = new DateTime(2015, 4, 18), Diagnosis = "Laryngitis", DischargeDate = new DateTime(2015, 5, 26), EpisodeId = 4, PatientId = 2 }, new Episode { AdmissionDate = new DateTime(2015, 6, 2), Diagnosis = "Athlete's foot", DischargeDate = new DateTime(2015, 6, 13), EpisodeId = 5, PatientId = 2 } }); patientsService = new Mock <IPatientsService>(); patientsService.Setup(service => service.GetPatients()).Returns(new List <Patient>() { new Patient { DateOfBirth = new DateTime(1972, 10, 27), FirstName = "Millicent", PatientId = 1, LastName = "Hammond", NhsNumber = "1111111111" }, new Patient { DateOfBirth = new DateTime(1987, 2, 14), FirstName = "Bobby", PatientId = 2, LastName = "Atkins", NhsNumber = "2222222222" }, new Patient { DateOfBirth = new DateTime(1991, 12, 4), FirstName = "Xanthe", PatientId = 3, LastName = "Camembert", NhsNumber = "3333333333" } }); var config = new HttpConfiguration(); var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost:65534/patients/0/episodes"); var route = config.Routes.MapHttpRoute("Default", "patients/{patientId}/episodes"); patientsController = new PatientsController(patientsService.Object, episodesService.Object) { Request = request }; patientsController.Request.Properties[HttpPropertyKeys.HttpConfigurationKey] = config; var patientId = 0; var result = patientsController.Get(patientId); Assert.IsNotNull(result.StatusCode); Assert.AreEqual(result.StatusCode, HttpStatusCode.NotFound); Assert.AreEqual(((System.Net.Http.ObjectContent)result.Content).Value, $"Patient not found with patientId :{patientId}."); patientId = 1; result = patientsController.Get(patientId); Assert.IsNotNull(result.StatusCode); Assert.AreEqual(result.StatusCode, HttpStatusCode.OK); Assert.AreEqual((((System.Net.Http.ObjectContent)result.Content).Value as Patient).PatientId, patientId); patientId = 2; result = patientsController.Get(patientId); Assert.IsNotNull(result.StatusCode); Assert.AreEqual(result.StatusCode, HttpStatusCode.OK); Assert.AreEqual((((System.Net.Http.ObjectContent)result.Content).Value as Patient).PatientId, patientId); patientId = int.MinValue; result = patientsController.Get(patientId); Assert.IsNotNull(result.StatusCode); Assert.AreEqual(result.StatusCode, HttpStatusCode.BadRequest); }
public void Values_Initial_Get() { //Arrange List <Patient> patients = new List <Patient>() { new Patient() { Forename = "Patient1", Surname = "Surname1", Gender = "Male" }, new Patient() { Forename = "Patient2", Surname = "Surname2", Gender = "Female", DateOfBirth = Convert.ToDateTime("2003-11-16") }, new Patient() { Forename = "Patient3", Surname = "Surname3", Gender = "Female", DateOfBirth = Convert.ToDateTime("1983-11-16"), Phones = new List <Phone>() { new Phone() { PhoneType = PhoneNumberType.Work, PhoneNumber = "001-003-324-2345" }, new Phone() { PhoneType = PhoneNumberType.Mobile, PhoneNumber = "001-234-224-2344" } } } }; List <PatientRecord> patientRecords = new List <PatientRecord>(); foreach (var patient in patients) { XmlSerializer xmlSerializer = new XmlSerializer(typeof(Patient)); using (StringWriter textWriter = new StringWriter()) { xmlSerializer.Serialize(textWriter, patient); var patientDetails = textWriter.ToString(); var patientRecord = new PatientRecord() { Record = patientDetails }; patientRecords.Add(patientRecord); } } var mockRepo = new Mock <IPatientRepository>(); mockRepo.Setup(x => x.GetAllPatientRecords()).Returns(patientRecords); var repository = mockRepo.Object; var mapper = new Mock <IMapper>().Object; Mapper.Reset(); Mapper.Initialize(m => m.CreateMap <Patient, PatientViewModel>().ReverseMap()); var mock = new Mock <ILogger <PatientsController> >(); var logger = mock.Object; var controller = new PatientsController(repository, logger, mapper); //Act IActionResult results = controller.Get(); //Assert var okResult = results as OkObjectResult; // assert Assert.NotNull(okResult); Assert.Equal(200, okResult.StatusCode); }