public void PatientAddTest()
        {
            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.Post(patientModel);
            var           contentResult = actionResult as CreatedAtRouteResult;

            Assert.AreEqual(((PatientModel)contentResult.Value).Forenames, patientModel.Forenames);
        }
        public void PatientAddTestValidationFailure()
        {
            var patientModel = new PatientModel()
            {
                Forenames        = "Si",
                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);

            controller.ModelState.AddModelError("Forenames", "Fornames should be minimum 3 characters");
            IActionResult actionResult = controller.Post(patientModel);

            Assert.IsInstanceOfType(actionResult, typeof(BadRequestObjectResult));
        }
Beispiel #3
0
        //This test used to get patients by page number details
        public void GetValidPatient()
        {
            IHttpActionResult actionResult = new PatientsController(_PatientDemographicsRepository).Get(1, 4);
            var contentResult = actionResult as OkNegotiatedContentResult <PatientPagingModel>;

            Assert.IsNotNull(contentResult.Content.PatientDetails);
        }
        public async Task GetAllPatient()
        {
            var controller = new PatientsController(new Mock <IMediator>().Object);
            var result     = await controller.GetPatients();

            Xunit.Assert.NotEmpty(result.Value);
        }
        public void TestGetPatientFound()
        {
            var Controller = new PatientsController();

            Controller.Request       = new HttpRequestMessage();
            Controller.Configuration = new HttpConfiguration();


            var response = Controller.GetPatient(101);

            PatientDetailDto patient;

            Assert.IsTrue(response.TryGetContentValue <PatientDetailDto>(out patient));
            Assert.AreEqual(101, patient.Id);
            Assert.AreEqual("Ramesh Kumar", patient.Name);
            Assert.AreEqual("Male", patient.Gender);
            Assert.AreEqual(43, patient.Weight);
            Assert.AreEqual(103, patient.ConsultingDoctor);
            Assert.AreEqual(new DateTime(1967, 8, 11), patient.DOB);
            Assert.AreEqual("Fever", patient.Disease);
            Assert.AreEqual("8789342567", patient.Contact);
            Assert.AreEqual(400, patient.RegistrationFee);
            Assert.AreEqual("50 years 0 months", patient.Age);
            Assert.AreEqual(new DateTime(2017, 8, 22), patient.LastVisit);
        }
        public async Task PatientControllerShouldReturnListOfPatients()
        {
            var patientService = new Mock <IPatientService>();

            var userManager = UserManagerMock.New;

            patientService
            .Setup(c => c.DisplayRegisteredPatientsAsync(It.IsAny <string>()))
            .ReturnsAsync(new List <CurrentlyRegisteredPatientServiceModel>
            {
                new CurrentlyRegisteredPatientServiceModel
                {
                    Id = 7,
                }
            });

            var controller = new PatientsController(patientService.Object, userManager.Object);

            // Act
            var result = await controller.Index();

            // Assert
            result.Should().BeOfType <ViewResult>();

            var viewModel = result.As <ViewResult>().Model.As <IEnumerable <CurrentlyRegisteredPatientServiceModel> >();

            viewModel.FirstOrDefault(v => v.Id == 7).Should().NotBeNull();
        }
Beispiel #7
0
        public void GetTestPatients()
        {
            var controller = new PatientsController();
            var result     = controller.GetPatients();

            Assert.IsTrue(result.Count() != 0);
        }
        public void CompIndexTest()
        {
            PatientsController patientController = new PatientsController();
            ActionResult       result            = patientController.Index("a", "lobes", "tumor", "3", "M");

            Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsInstanceOfType(result, typeof(ViewResult));
        }
Beispiel #9
0
        public PatientsControllerTests()
        {
            _patientLogic     = Substitute.For <IPatientLogic>();
            _patientValidator = Substitute.For <IValidator <PatientModel> >();

            _patientsController = new PatientsController(_patientLogic, _patientValidator);
        }
        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");
        }
Beispiel #11
0
        public async Task CreateVisitStep2_Returns_View_When_ModelStateInvalid()
        {
            _appService.Setup(m => m.GetDoctorsAppointmentsForDay(It.IsAny <string>(), It.IsAny <DateTime>(), CancellationToken.None))
            .ReturnsAsync(It.IsAny <DoctorsViewModel>());

            var sut = new PatientsController(_appService.Object)
            {
                ControllerContext = new ControllerContext
                {
                    HttpContext = new DefaultHttpContext
                    {
                        User = new ClaimsPrincipal(
                            new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, "tesuser") },
                                               "testAuthType"))
                    }
                }
            };

            sut.ModelState.AddModelError("test", "test");

            var result = await sut.CreateVisitStep2(new CreateVisitViewModel());

            result.Should().BeOfType <ViewResult>();

            sut.Dispose();
        }
 public void SetUp()
 {
     _context = new ExtractsContext(_options);
     _tempPatientExtractRepository = new TempPatientExtractRepository(_context);
     _errorSummaryRepository       = new TempPatientExtractErrorSummaryRepository(_context);
     _patientsController           = new PatientsController(_tempPatientExtractRepository, _errorSummaryRepository);
 }
Beispiel #13
0
        public async Task PostReturnsPatient()
        {
            // Arrange.
            var config = new HttpConfiguration();

            config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;

            var request   = new HttpRequestMessage(HttpMethod.Post, "http://localhost/api/Patients");
            var route     = config.Routes.MapHttpRoute("GetPatient", "api/{controller}/{id}");
            var routeData = new HttpRouteData(route, new HttpRouteValueDictionary(new { controller = "Patients" }));

            var controller = new PatientsController
            {
                ControllerContext = new HttpControllerContext(config, routeData, request),
                Request           = request,
                Url = new UrlHelper(request)
            };

            controller.Request.Properties[HttpPropertyKeys.HttpConfigurationKey] = config;
            controller.Request.Properties[HttpPropertyKeys.HttpRouteDataKey]     = routeData;

            //Act.
            HttpResponseMessage response = await controller.CreatePatient(m_patient);

            //Assert.
            Patient patient = await response.Content.ReadAsAsync <Patient>();

            Assert.IsTrue(response.StatusCode.Equals(HttpStatusCode.Created));
        }
        public void TestPutPatientError()
        {
            var Controller = new PatientsController();

            Controller.Request       = new HttpRequestMessage();
            Controller.Configuration = new HttpConfiguration();

            PatientDetailDto patientdto = new PatientDetailDto()
            {
                Id               = 201,
                Name             = "Suresh Kumar",
                Age              = "50 years 0 months",
                Gender           = "Male",
                Weight           = 90,
                ConsultingDoctor = 102,
                DOB              = new DateTime(1967, 8, 12),
                Disease          = "Diarrhoea",
                Contact          = "9983464423",
                RegistrationFee  = 1000,
                LastVisit        = new DateTime(),
                StatusFlag       = 0
            };


            var response = Controller.PutPatient(101, patientdto);

            Assert.IsInstanceOfType(response, typeof(HttpResponseMessage));
            Assert.AreEqual(response.StatusCode, HttpStatusCode.InternalServerError);
        }
Beispiel #15
0
        public void Search_ShouldRespectTheSearchTermWhenItsPresent()
        {
            PatientsController controller = null;

            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, 200);
            }
            catch
            {
                Assert.Inconclusive("Test initialization has failed.");
            }

            var searchTerm            = "an";
            var matchingPatientsCount = this.db.Patients.Count(p => p.Person.FullName.Contains(searchTerm));

            // making an empty search
            var result = controller.Search(new Areas.App.Models.SearchModel()
            {
                Term = searchTerm,
                Page = 1
            });

            Assert.IsInstanceOfType(result, typeof(ViewResult));
            var resultAsView = result as ViewResult;

            Assert.IsInstanceOfType(resultAsView.Model, typeof(SearchViewModel <PatientViewModel>));
            var model = resultAsView.Model as SearchViewModel <PatientViewModel>;

            Assert.AreEqual(matchingPatientsCount, model.Count);
            Assert.IsTrue(model.Objects.Count >= Code.Constants.GRID_PAGE_SIZE);
        }
Beispiel #16
0
        private static void WorkWithPatient()
        {
            var service    = _serviceProvider.GetRequiredService <IService <Patient, int> >();
            var controller = new PatientsController(service);

            controller.Start();
        }
Beispiel #17
0
        // This method is used to add a new patient
        public void PostPatientDetailSuccess()
        {
            IHttpActionResult actionResult = new PatientsController(_PatientDemographicsRepository).Post(patientDetail);
            var contentResult = actionResult as OkNegotiatedContentResult <bool>;

            Assert.IsTrue(contentResult.Content);
        }
        public void PatientsController_IndexModelContainsCorrectData_List()
        {
            //Arrange
            Mock <IPatientRepository> mock = new Mock <IPatientRepository>();

            mock.Setup(m => m.Patients).Returns(new Patient[]
            {
                new Patient {
                    Id = 1, Name = "John Paul Jones"
                },
                new Patient {
                    Id = 2, Name = "Robert Plant"
                },
                new Patient {
                    Id = 3, Name = "Jimmy Page"
                }
            }.AsQueryable());
            ViewResult indexView = new PatientsController(mock.Object).Index() as ViewResult;

            //Act
            var result = indexView.ViewData.Model;

            //Assert
            Assert.IsInstanceOfType(result, typeof(List <Patient>));
        }
Beispiel #19
0
        public async Task GetPatientExist()
        {
            var controller   = new PatientsController(new Mock <IMediator>().Object);
            var actionResult = await controller.GetPatient(61);

            Xunit.Assert.IsType <OkObjectResult>(actionResult.Result);
            //Assert.Equals(61, okResult.Value);
        }
        public async Task GetOkPatient()
        {
            var controller = new PatientsController(new Mock <IMediator>().Object);
            var result     = await controller.GetPatient(61);

            Assert.IsType <OkResult>(result.Result);
            //Assert.Equal(61, result.Value.Id);
        }
        public async Task GetPatients_ReturnsCorrectType()
        {
            var controller = new PatientsController(_context, _relationshipMock.Object);

            var result = await controller.GetPatients();          

            Assert.IsAssignableFrom<IEnumerable<Patient>>(result.Value);
        }
        //[TestMethod]
        //[TestCategory("Index")]
        public void ShouldCheckResultFromPatientsControllerIndexIsNotNull()
        {
            _patientsController = new PatientsController(_patientRepository);

            var value = _patientsController.Index() as ViewResult;

            Assert.IsNotNull(value);
        }
        public async Task GetPatient_ReturnsCorrectType()
        {
            var controller = new PatientsController(_context, _relationshipMock.Object);

            var result = await controller.GetPatient(1);

            Assert.IsType<Patient>(result.Value);
        }
Beispiel #24
0
        public void Delete_Valid_Detail()
        {
            var loandata           = new Mock <PatientRep>(db);
            PatientsController obj = new PatientsController(loandata.Object);
            var data     = obj.Delete(1);
            var okResult = data as OkObjectResult;

            Assert.AreEqual(200, okResult.StatusCode);
        }
Beispiel #25
0
        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 async void GetAll_NotNull_OkAndPagedList()
        {
            var service    = new MockPatientService().GetAll(new List <GetPatientDto>());
            var controller = new PatientsController(service.Object, null);

            var result = await controller.GetAll();

            Assert.IsType <OkObjectResult>(result);
        }
        public void ShouldCheckTypeOfInstanceResultAfterCreateFromPatientsController_WithFakeRepository()
        {
            _patientsController = new PatientsController(_fakePatientRepository);

            var expectedType = typeof(ActionResult);
            var value        = _patientsController.Create(new Patient());

            Assert.IsInstanceOfType(value, expectedType);
        }
Beispiel #28
0
        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 ShouldCheckTypeOfInstanceResultAfterCreateFromPatientsController()
        {
            _patientsController = new PatientsController(_patientRepository);

            var expectedType = typeof(ViewResult);
            var value        = _patientsController.Create();

            Assert.IsInstanceOfType(value, expectedType);
        }
        public async Task GetPatients_ReturnsAllPatients()
        {
            var controller = new PatientsController(_context, _relationshipMock.Object);

            var result = await controller.GetPatients();

            var patients = Assert.IsAssignableFrom<IEnumerable<Patient>>(result.Value);

            Assert.Equal(4, patients.Count());
        }
        public void PutEmergencyContactUpdateEmergencyContact()
        {
            //Test Properties
            IHttpActionResult result;
            CreatedAtRouteNegotiatedContentResult<EmergencyContactModel> contentResult;
            OkNegotiatedContentResult<EmergencyContactModel> emergencyContactResult;
            OkNegotiatedContentResult<EmergencyContactModel> readContentResult;

            int createdPatientID;

            // Create test patient
            using (var patientController = new PatientsController())
            {
                var patient = new PatientModel
                {
                    FirstName = "Testpatient",
                    LastName = "Testerson",
                    Birthdate = new DateTime(1968, 12, 27),
                    Email = "*****@*****.**",
                    BloodType = "A+",
                    CreatedDate = new DateTime(2015, 11, 10),
                    Archived = false
                };
                result = patientController.PostPatient(patient);
                CreatedAtRouteNegotiatedContentResult<PatientModel> createdContentResult =
                    (CreatedAtRouteNegotiatedContentResult<PatientModel>)result;
                createdPatientID = createdContentResult.Content.PatientID;
            }

            using (var EmergencyContactController = new EmergencyContactsController())
            {
                //Create EmergencyContact
                var newEmergencyContact = new EmergencyContactModel
                {
                    PatientID = createdPatientID,
                    FirstName = "Ronnie",
                    LastName = "Dio",
                    Telephone = "666-666-6666",
                    Email = "*****@*****.**",
                    Relationship = "Celestial Being"
                };
                //Insert EmergencyContactModelObject into Database so
                //that I can take it out and test for update.
                result = EmergencyContactController.PostEmergencyContact(newEmergencyContact);

                //Cast result as Content Result so that I can gather information from ContentResult
                contentResult = (CreatedAtRouteNegotiatedContentResult<EmergencyContactModel>)result;
            }

            using (var SecondEmergencyContactController = new EmergencyContactsController())
            {
                //Result contains the new EmergencyContact
                result = SecondEmergencyContactController.GetEmergencyContact(contentResult.Content.EmergencyContactID);

                Assert.IsInstanceOfType(result, typeof(OkNegotiatedContentResult<EmergencyContactModel>));

                //Get EmergencyContactModel from 'result'
                emergencyContactResult = (OkNegotiatedContentResult<EmergencyContactModel>)result;

            }

            using (var ThirdEmergencyContactController = new EmergencyContactsController())
            {
                var modifiedEmergencyContact = emergencyContactResult.Content;

                modifiedEmergencyContact.FirstName = "Whip";

                //Act
                //The result of the Put Request
                result = ThirdEmergencyContactController.PutEmergencyContact(emergencyContactResult.Content.EmergencyContactID, modifiedEmergencyContact);

                //Assert
                Assert.IsInstanceOfType(result, typeof(StatusCodeResult));
            }

            using (var FourthEmergencyContactController = new EmergencyContactsController())
            {
                //Act
                IHttpActionResult resultAlteredEmergencyContact = FourthEmergencyContactController.GetEmergencyContact(emergencyContactResult.Content.EmergencyContactID);

                OkNegotiatedContentResult<EmergencyContactModel> alteredResult = (OkNegotiatedContentResult<EmergencyContactModel>)resultAlteredEmergencyContact;
                EmergencyContactModel updatedEmergencyContact = (EmergencyContactModel)alteredResult.Content;

                //Assert
                Assert.IsInstanceOfType(resultAlteredEmergencyContact, typeof(OkNegotiatedContentResult<EmergencyContactModel>));

                readContentResult =
                    (OkNegotiatedContentResult<EmergencyContactModel>)resultAlteredEmergencyContact;

                Assert.IsTrue(readContentResult.Content.FirstName == "Whip");
            }

            using (var FifthEmergencyContactController = new EmergencyContactsController())
            {
                //Delete the Test EmergencyContact
                result = FifthEmergencyContactController.DeleteEmergencyContact(readContentResult.Content.EmergencyContactID);
            }

            // Remove the test patient from the database with actual deletion, not archiving
            using (MedAgendaDbContext db = new MedAgendaDbContext())
            {
                Patient dbPatient = db.Patients.Find(createdPatientID);
                db.Patients.Remove(dbPatient);
                db.SaveChanges();
            }
        }
        public void DeleteEmergencyContact()
        {
            CreatedAtRouteNegotiatedContentResult<EmergencyContactModel> contentResult;
            int createdPatientID;

            // Create test patient
            using (var patientController = new PatientsController())
            {
                var patient = new PatientModel
                {
                    FirstName = "Testpatient",
                    LastName = "Testerson",
                    Birthdate = new DateTime(1968, 12, 27),
                    Email = "*****@*****.**",
                    BloodType = "A+",
                    CreatedDate = new DateTime(2015, 11, 10),
                    Archived = false
                };
                IHttpActionResult result = patientController.PostPatient(patient);
                CreatedAtRouteNegotiatedContentResult<PatientModel> createdContentResult =
                    (CreatedAtRouteNegotiatedContentResult<PatientModel>)result;
                createdPatientID = createdContentResult.Content.PatientID;
            }

            using (var EmergencyContactController = new EmergencyContactsController())
            {
                //Create EmergencyContact
                var newEmergencyContact = new EmergencyContactModel
                {
                    PatientID = createdPatientID,
                    FirstName = "Ronnie",
                    LastName = "Dio",
                    Telephone = "666-666-6666",
                    Email = "*****@*****.**",
                    Relationship = "Celestial Being"
                };

                //Insert object to be removed by test
                var result = EmergencyContactController.PostEmergencyContact(newEmergencyContact);

                //Cast result as Content Result so that I can gather information from ContentResult
                contentResult = (CreatedAtRouteNegotiatedContentResult<EmergencyContactModel>)result;
            }

            using (var secondDocController = new EmergencyContactsController())
            {
                //Delete the Test EmergencyContact
                var result = secondDocController.DeleteEmergencyContact(contentResult.Content.EmergencyContactID);

                //Assert
                Assert.IsInstanceOfType(result, typeof(OkNegotiatedContentResult<EmergencyContactModel>));
            }
            using (var thirdDocController = new EmergencyContactsController())
            {
                var result = thirdDocController.GetEmergencyContact(contentResult.Content.EmergencyContactID);
                //Assert
                Assert.IsInstanceOfType(result, typeof(NotFoundResult));
            }

            // Remove the test patient from the database with actual deletion, not archiving
            using (MedAgendaDbContext db = new MedAgendaDbContext())
            {
                Patient dbPatient = db.Patients.Find(createdPatientID);
                db.Patients.Remove(dbPatient);
                db.SaveChanges();
            }
        }
        public void GetEmergencyContactReturnEmergencyContact()
        {
            int createdPatientID;
            int emergencyContactIDForTest;

            // Create test patient and emergency contact
            using (var patientController = new PatientsController())
            {
                var patient = new PatientModel
                {
                    FirstName = "Testpatient",
                    LastName = "Testerson",
                    Birthdate = new DateTime(1968, 12, 27),
                    Email = "*****@*****.**",
                    BloodType = "A+",
                    CreatedDate = new DateTime(2015, 11, 10),
                    Archived = false
                };
                IHttpActionResult result = patientController.PostPatient(patient);
                CreatedAtRouteNegotiatedContentResult<PatientModel> createdContentResult =
                    (CreatedAtRouteNegotiatedContentResult<PatientModel>)result;
                createdPatientID = createdContentResult.Content.PatientID;
            }

            using (var EmergencyContactController = new EmergencyContactsController())
            {
                //Create EmergencyContact
                var newEmergencyContact = new EmergencyContactModel
                {
                    PatientID = createdPatientID,
                    FirstName = "Ronnie",
                    LastName = "Dio",
                    Telephone = "666-666-6666",
                    Email = "*****@*****.**",
                    Relationship = "Celestial Being"
                };

                //Act
                IHttpActionResult result = EmergencyContactController.PostEmergencyContact(newEmergencyContact);

                CreatedAtRouteNegotiatedContentResult<EmergencyContactModel> contentResult =
                    (CreatedAtRouteNegotiatedContentResult<EmergencyContactModel>)result;
                emergencyContactIDForTest = contentResult.Content.EmergencyContactID;
            }

            // Assert: Get the test emergency contact and verify the ID
            using (var EmergencyContactController = new EmergencyContactsController())
            {

                IHttpActionResult result = EmergencyContactController.GetEmergencyContact(emergencyContactIDForTest);

                Assert.IsInstanceOfType(result, typeof(OkNegotiatedContentResult<EmergencyContactModel>));

                OkNegotiatedContentResult<EmergencyContactModel> contentResult =
                    (OkNegotiatedContentResult<EmergencyContactModel>)result;
                Assert.IsTrue(contentResult.Content.EmergencyContactID == emergencyContactIDForTest);
            }

            //Delete the Test EmergencyContact
            using (var emergencyContactController = new EmergencyContactsController())
            {
                IHttpActionResult result =
                    emergencyContactController.DeleteEmergencyContact(emergencyContactIDForTest);
            }

            // Remove the test patient from the database with actual deletion, not archiving
            using (MedAgendaDbContext db = new MedAgendaDbContext())
            {
                Patient dbPatient = db.Patients.Find(createdPatientID);
                db.Patients.Remove(dbPatient);
                db.SaveChanges();
            }
        }
        public void PostAppointmentCreateAppointment()
        {
            int createdPatientID;
            int appointmentIDForTest;
            int createdDoctorID;
            int createdExamRoomID;
            int createdSpecialtyID;
            CreatedAtRouteNegotiatedContentResult<AppointmentModel> contentResult;

            //Create test patient, specialty, doctor, and exam room for appointment
            // Create a new test patient, and get its patient ID
            using (var patientController = new PatientsController())
            {
                var patient = new PatientModel
                {
                    FirstName = "Impatient",
                    LastName = "Patience",
                    Birthdate = new DateTime(1968, 12, 27),
                    Email = "*****@*****.**",
                    BloodType = "A+",
                    CreatedDate = DateTime.Now,
                    Archived = false
                };
                IHttpActionResult result = patientController.PostPatient(patient);
                CreatedAtRouteNegotiatedContentResult<PatientModel> patientContentResult =
                    (CreatedAtRouteNegotiatedContentResult<PatientModel>)result;
                createdPatientID = patientContentResult.Content.PatientID;
            }

            // Create a new test specialty, and get its specialty ID
            using (var specialtyController = new SpecialtiesController())
            {
                var specialty = new SpecialtyModel
                {
                    SpecialtyName = "Very Special Doctor"
                };
                IHttpActionResult result = specialtyController.PostSpecialty(specialty);
                CreatedAtRouteNegotiatedContentResult<SpecialtyModel> specialtyContentResult =
                    (CreatedAtRouteNegotiatedContentResult<SpecialtyModel>)result;
                createdSpecialtyID = specialtyContentResult.Content.SpecialtyID;
            }

            // Create a new test doctor, and get its doctor ID
            using (var doctorController = new DoctorsController())
            {
                var doctor = new DoctorModel
                {
                    FirstName = "Imdoctor",
                    LastName = "Hippocrates",
                    Email = "*****@*****.**",
                    Telephone = "555-1212",
                    CreatedDate = DateTime.Now,
                    SpecialtyID = createdSpecialtyID,
                    Archived = false
                };
                IHttpActionResult result = doctorController.PostDoctor(doctor);
                CreatedAtRouteNegotiatedContentResult<DoctorModel> doctorContentResult =
                    (CreatedAtRouteNegotiatedContentResult<DoctorModel>)result;
                createdDoctorID = doctorContentResult.Content.DoctorID;
            }

            // Create a new test exam room, and get its exam room ID
            using (var examRoomController = new ExamRoomsController())
            {
                var examRoom = new ExamRoomModel
                {
                    ExamRoomName = "ImexamRoom"
                };
                IHttpActionResult result = examRoomController.PostExamRoom(examRoom);
                CreatedAtRouteNegotiatedContentResult<ExamRoomModel> examRoomContentResult =
                    (CreatedAtRouteNegotiatedContentResult<ExamRoomModel>)result;
                createdExamRoomID = examRoomContentResult.Content.ExamRoomID;
            }

            //Arrange:
            using (var apptController = new AppointmentsController())
            {
                var newAppt = new AppointmentModel
                {
                    DoctorID = createdDoctorID,
                    CheckinDateTime = DateTime.Now,
                    CheckoutDateTime = DateTime.Now.AddHours(2),
                    ExamRoomID = createdExamRoomID,
                    PatientID = createdPatientID
                };

                //Act
                IHttpActionResult result = apptController.PostAppointment(newAppt);

                //Assert
                Assert.IsInstanceOfType(result, typeof(CreatedAtRouteNegotiatedContentResult<AppointmentModel>));

                contentResult = (CreatedAtRouteNegotiatedContentResult<AppointmentModel>)result;

                Assert.IsTrue(contentResult.Content.AppointmentID != 0);
                appointmentIDForTest = contentResult.Content.AppointmentID;
            }

            //Delete the Appointment
            using (var SecondapptController = new AppointmentsController())
            {
              IHttpActionResult result = SecondapptController.DeleteAppointment(appointmentIDForTest);
            }

            // Remove the test doctor and patient from the database with actual deletion, not archiving
            using (MedAgendaDbContext db = new MedAgendaDbContext())
            {
                Doctor dbDoctor = db.Doctors.Find(createdDoctorID);
                db.Doctors.Remove(dbDoctor);
                Patient dbPatient = db.Patients.Find(createdPatientID);
                db.Patients.Remove(dbPatient);
                db.SaveChanges();
            }

            // Delete the test exam room
            using (var SecondExamRoomController = new ExamRoomsController())
            {
                IHttpActionResult result = SecondExamRoomController.DeleteExamRoom(createdExamRoomID);
            }

            // Delete the test specialty
            using (var specialtyController = new SpecialtiesController())
            {
                IHttpActionResult result = specialtyController.DeleteSpecialty(createdSpecialtyID);
            }
        }
        public void PutAppointmentReturnAppointment()
        {
            //Test Properties
            IHttpActionResult result;
            CreatedAtRouteNegotiatedContentResult<AppointmentModel> contentResult;
            OkNegotiatedContentResult<AppointmentModel> appointmentResult;
            OkNegotiatedContentResult<AppointmentModel> readContentResult;

            int createdPatientID;
            int createdDoctorID;
            int createdExamRoomID;
            int changedExamRoomID;
            int createdSpecialtyID;

            //Arrange: create test patient, specialty, doctor, exam rooms, and appointment
            // Create a new test patient, and get its patient ID
            using (var patientController = new PatientsController())
            {
                var patient = new PatientModel
                {
                    FirstName = "Impatient",
                    LastName = "Patience",
                    Birthdate = new DateTime(1968, 12, 27),
                    Email = "*****@*****.**",
                    BloodType = "A+",
                    CreatedDate = DateTime.Now,
                    Archived = false
                };
                result = patientController.PostPatient(patient);
                CreatedAtRouteNegotiatedContentResult<PatientModel> patientContentResult =
                    (CreatedAtRouteNegotiatedContentResult<PatientModel>)result;
                createdPatientID = patientContentResult.Content.PatientID;
            }

            // Create a new test specialty, and get its specialty ID
            using (var specialtyController = new SpecialtiesController())
            {
                var specialty = new SpecialtyModel
                {
                    SpecialtyName = "Very Special Doctor"
                };
                result = specialtyController.PostSpecialty(specialty);
                CreatedAtRouteNegotiatedContentResult<SpecialtyModel> specialtyContentResult =
                    (CreatedAtRouteNegotiatedContentResult<SpecialtyModel>)result;
                createdSpecialtyID = specialtyContentResult.Content.SpecialtyID;
            }

            // Create a new test doctor, and get its doctor ID
            using (var doctorController = new DoctorsController())
            {
                var doctor = new DoctorModel
                {
                    FirstName = "Imdoctor",
                    LastName = "Hippocrates",
                    Email = "*****@*****.**",
                    Telephone = "555-1212",
                    CreatedDate = DateTime.Now,
                    SpecialtyID = createdSpecialtyID,
                    Archived = false
                };
                result = doctorController.PostDoctor(doctor);
                CreatedAtRouteNegotiatedContentResult<DoctorModel> doctorContentResult =
                    (CreatedAtRouteNegotiatedContentResult<DoctorModel>)result;
                createdDoctorID = doctorContentResult.Content.DoctorID;
            }

            // Create new test exam rooms, and get the exam room IDs
            using (var examRoomController = new ExamRoomsController())
            {
                var examRoom = new ExamRoomModel
                {
                    ExamRoomName = "ImexamRoom"
                };
                result = examRoomController.PostExamRoom(examRoom);
                CreatedAtRouteNegotiatedContentResult<ExamRoomModel> examRoomContentResult =
                    (CreatedAtRouteNegotiatedContentResult<ExamRoomModel>)result;
                createdExamRoomID = examRoomContentResult.Content.ExamRoomID;
            }

            using (var examRoomController = new ExamRoomsController())
            {
                var examRoom = new ExamRoomModel
                {
                    ExamRoomName = "AnotherexamRoom"
                };
                result = examRoomController.PostExamRoom(examRoom);
                CreatedAtRouteNegotiatedContentResult<ExamRoomModel> examRoomContentResult =
                    (CreatedAtRouteNegotiatedContentResult<ExamRoomModel>)result;
                changedExamRoomID = examRoomContentResult.Content.ExamRoomID;
            }

            using (var apptController = new AppointmentsController())
            {
                //Create Appointment
                var newAppt = new AppointmentModel
                {
                    DoctorID = createdDoctorID,
                    CheckinDateTime = DateTime.Now,
                    CheckoutDateTime = DateTime.Now.AddHours(2),
                    ExamRoomID = createdExamRoomID,
                    PatientID = createdPatientID
                };

                //Insert Appointment Model Object into Database
                //So that I can take it out and test for update
                result = apptController.PostAppointment(newAppt);

                //Cast result as Content Result so that I can gather information from Content Result
                contentResult = (CreatedAtRouteNegotiatedContentResult<AppointmentModel>)result;
            }

            using (var SecondAppointmentController = new AppointmentsController())
            {
                //Result contains the Appoint I have JUST creatd
                result = SecondAppointmentController.GetAppointment(contentResult.Content.AppointmentID);

                Assert.IsInstanceOfType(result, typeof(OkNegotiatedContentResult<AppointmentModel>));

                //Get AppointmentModel from 'result'
                appointmentResult = (OkNegotiatedContentResult<AppointmentModel>)result;
            }

            using (var ThirdAppointmentController = new AppointmentsController())
            {
                var modifiedAppointment = appointmentResult.Content;

                modifiedAppointment.ExamRoomID = changedExamRoomID;

                //Act
                //The result of the PUT request
                result = ThirdAppointmentController.PutAppointment(appointmentResult.Content.AppointmentID, modifiedAppointment);

                //Assert
                Assert.IsInstanceOfType(result, typeof(StatusCodeResult));
            }

            //Modify Appointment
            using (var FourthAppointmentController = new AppointmentsController())
            {
                IHttpActionResult resultAlteredAppointment = FourthAppointmentController.GetAppointment(appointmentResult.Content.AppointmentID);

                OkNegotiatedContentResult<AppointmentModel> alteredResult = (OkNegotiatedContentResult<AppointmentModel>)resultAlteredAppointment;
                AppointmentModel updatedAppointment = (AppointmentModel)alteredResult.Content;

                //Assert
                Assert.IsInstanceOfType(resultAlteredAppointment, typeof(OkNegotiatedContentResult<AppointmentModel>));

                readContentResult = (OkNegotiatedContentResult<AppointmentModel>)resultAlteredAppointment;

                Assert.IsTrue(readContentResult.Content.ExamRoomID == changedExamRoomID);
            }

            using (var fifthAppointmentController = new AppointmentsController())
            {
                //Delete test Appointment
                result = fifthAppointmentController.DeleteAppointment(readContentResult.Content.AppointmentID);
            }

            // Remove the test doctor and patient from the database with actual deletion, not archiving
            using (MedAgendaDbContext db = new MedAgendaDbContext())
            {
                Doctor dbDoctor = db.Doctors.Find(createdDoctorID);
                db.Doctors.Remove(dbDoctor);
                Patient dbPatient = db.Patients.Find(createdPatientID);
                db.Patients.Remove(dbPatient);
                db.SaveChanges();
            }

            // Delete the test exam rooms
            using (var SecondExamRoomController = new ExamRoomsController())
            {
                result = SecondExamRoomController.DeleteExamRoom(createdExamRoomID);
            }
            using (var SecondExamRoomController = new ExamRoomsController())
            {
                result = SecondExamRoomController.DeleteExamRoom(changedExamRoomID);
            }

            // Delete the test specialty
            using (var specialtyController = new SpecialtiesController())
            {
                result = specialtyController.DeleteSpecialty(createdSpecialtyID);
            }
        }
        public void PutPatientCheckReturnPatientCheck()
        {
            IHttpActionResult result;
            CreatedAtRouteNegotiatedContentResult<PatientCheckModel> contentResult;
            OkNegotiatedContentResult<PatientCheckModel> patientCheckResult;
            OkNegotiatedContentResult<PatientCheckModel> readContentResult;
            DateTime now = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day,
                                        DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second);
            int createdPatientID;
            int createdSpecialtyID;

            // Create a new test patient, and get its patient ID
            using (var patientController = new PatientsController())
            {
                var patient = new PatientModel
                {
                    FirstName = "Testpatient",
                    LastName = "Testerson",
                    Birthdate = new DateTime(1968, 12, 27),
                    Email = "*****@*****.**",
                    BloodType = "A+",
                    CreatedDate = new DateTime(2015, 11, 10),
                    Archived = false
                };
                result = patientController.PostPatient(patient);
                CreatedAtRouteNegotiatedContentResult<PatientModel> createdContentResult =
                    (CreatedAtRouteNegotiatedContentResult<PatientModel>)result;
                createdPatientID = createdContentResult.Content.PatientID;
            }

            // Create a new test specialty, and get its specialty ID
            using (var specialtyController = new SpecialtiesController())
            {
                var specialty = new SpecialtyModel
                {
                    SpecialtyName = "Very Special Doctor"
                };
                result = specialtyController.PostSpecialty(specialty);
                CreatedAtRouteNegotiatedContentResult<SpecialtyModel> specialtyContentResult =
                    (CreatedAtRouteNegotiatedContentResult<SpecialtyModel>)result;
                createdSpecialtyID = specialtyContentResult.Content.SpecialtyID;
            }

            using (var patientCheckController = new PatientChecksController())
            {
                var newPatientCheck = new PatientCheckModel
                {
                    PatientID = createdPatientID,
                    SpecialtyID = createdSpecialtyID,
                    CheckinDateTime = now,
                    CheckoutDateTime = now.AddHours(2)
                };

                result = patientCheckController.PostPatientCheck(newPatientCheck);

                contentResult = (CreatedAtRouteNegotiatedContentResult<PatientCheckModel>)result;

            }
            using (var SecondPatientCheckController = new PatientChecksController())
            {
                result = SecondPatientCheckController.GetPatientCheck(contentResult.Content.PatientCheckID);

                Assert.IsInstanceOfType(result, typeof(OkNegotiatedContentResult<PatientCheckModel>));

                patientCheckResult = (OkNegotiatedContentResult<PatientCheckModel>)result;
            }
            using (var ThirdPatientCheckController = new PatientChecksController())
            {
                var modifiedPatientCheck = patientCheckResult.Content;

                modifiedPatientCheck.CheckoutDateTime = now;

                result = ThirdPatientCheckController.PutPatientCheck(patientCheckResult.Content.PatientCheckID, modifiedPatientCheck);

                Assert.IsInstanceOfType(result, typeof(StatusCodeResult));
            }

            using (var FourthPatientCheckController = new PatientChecksController())
            {
                IHttpActionResult resultAlteredPatientCheck = FourthPatientCheckController.GetPatientCheck(patientCheckResult.Content.PatientCheckID);

                OkNegotiatedContentResult<PatientCheckModel> alteredResult = (OkNegotiatedContentResult<PatientCheckModel>)resultAlteredPatientCheck;

                PatientCheckModel updatedPatientCheck = (PatientCheckModel)alteredResult.Content;

                Assert.IsInstanceOfType(resultAlteredPatientCheck, typeof(OkNegotiatedContentResult<PatientCheckModel>));

                readContentResult = (OkNegotiatedContentResult<PatientCheckModel>)resultAlteredPatientCheck;

                Assert.IsTrue(readContentResult.Content.CheckoutDateTime == now);
            }

            // Delete the test patient check
            using (var FifthPatientCheckController = new PatientChecksController())
            {
                result = FifthPatientCheckController.DeletePatientCheck(readContentResult.Content.PatientCheckID);
            }

            // Delete the test patient (actual deletion, not archiving)
            using (MedAgendaDbContext db = new MedAgendaDbContext())
            {
                Patient dbPatient = db.Patients.Find(createdPatientID);
                db.Patients.Remove(dbPatient);
                db.SaveChanges();
            }

            // Delete the test specialty
            using (var specialtyController = new SpecialtiesController())
            {
                result = specialtyController.DeleteSpecialty(createdSpecialtyID);
            }
        }
        public void DeletePatientCheck()
        {
            int createdPatientID;
            int createdSpecialtyID;
            IHttpActionResult result;
            CreatedAtRouteNegotiatedContentResult<PatientCheckModel> contentResult;

            // Create a new test patient, and get its patient ID
            using (var patientController = new PatientsController())
            {
                var patient = new PatientModel
                {
                    FirstName = "Testpatient",
                    LastName = "Testerson",
                    Birthdate = new DateTime(1968, 12, 27),
                    Email = "*****@*****.**",
                    BloodType = "A+",
                    CreatedDate = new DateTime(2015, 11, 10),
                    Archived = false
                };
                result = patientController.PostPatient(patient);
                CreatedAtRouteNegotiatedContentResult<PatientModel> createdContentResult =
                    (CreatedAtRouteNegotiatedContentResult<PatientModel>)result;
                createdPatientID = createdContentResult.Content.PatientID;
            }

            // Create a new test specialty, and get its specialty ID
            using (var specialtyController = new SpecialtiesController())
            {
                var specialty = new SpecialtyModel
                {
                    SpecialtyName = "Very Special Doctor"
                };
                result = specialtyController.PostSpecialty(specialty);
                CreatedAtRouteNegotiatedContentResult<SpecialtyModel> specialtyContentResult =
                    (CreatedAtRouteNegotiatedContentResult<SpecialtyModel>)result;
                createdSpecialtyID = specialtyContentResult.Content.SpecialtyID;
            }

            using (var patientCheckController = new PatientChecksController())
            {
                var newPatientCheck = new PatientCheckModel
                {
                    PatientID = createdPatientID,
                    SpecialtyID = createdSpecialtyID,
                    CheckinDateTime = DateTime.Now,
                    CheckoutDateTime = DateTime.Now.AddHours(2)
                };
                result = patientCheckController.PostPatientCheck(newPatientCheck);

                contentResult = (CreatedAtRouteNegotiatedContentResult<PatientCheckModel>)result;
            }
            using (var SecondPatientCheckController = new PatientChecksController())
            {
                result = SecondPatientCheckController.DeletePatientCheck(contentResult.Content.PatientCheckID);

                Assert.IsInstanceOfType(result, typeof(OkNegotiatedContentResult<PatientCheckModel>));
            }
            using (var ThirdPatientCheckController = new PatientChecksController())
            {
                result = ThirdPatientCheckController.GetPatientCheck(contentResult.Content.PatientCheckID);

                Assert.IsInstanceOfType(result, typeof(NotFoundResult));

            }

            // Delete the test patient (actual deletion, not archiving)
            using (MedAgendaDbContext db = new MedAgendaDbContext())
            {
                Patient dbPatient = db.Patients.Find(createdPatientID);
                db.Patients.Remove(dbPatient);
                db.SaveChanges();
            }

            // Delete the test specialty
            using (var specialtyController = new SpecialtiesController())
            {
                result = specialtyController.DeleteSpecialty(createdSpecialtyID);
            }
        }