public void TestCreatePatient() { // Act IActionResult result = _patientController.CreatePatient(new Patient() { FirstName = "Adam", LastName = "Johnson", LastFourOfSSN = "5678", DateOfBirth = DateTime.Now }); // Assert Assert.IsType <NoContentResult>(result); Assert.Contains(_mockPatientDbService.PatientList, patient => patient == _patient); }
public async Task CreatePatient_Should_Create_A_New_Patient() { PatientViewModel patient = new PatientViewModel(); PatientController sut = null; AllureLifecycle.Instance.WrapInStep(() => { sut = this.sutBuilder.WithRepository(this.mockRepositories.Object); patient = new PatientViewModel { Name = "Carlos", Surname = "Carmona", Email = "*****@*****.**" }; }, $"Action: Create a new Patient with values: Name: {patient.Name}, Surname: {patient.Surname} and email: {patient.Email}"); // Arrange await AllureLifecycle.Instance.WrapInStep(async() => { IActionResult result = await sut.CreatePatient(patient); // Assert PatientViewModel model = AssertAndGetModel <PatientViewModel>(result); this.mockPatientRepository.Verify(repo => repo.Add(It.IsAny <Patient>())); Assert.AreEqual(patient.Email, model.Email); Assert.AreEqual(patient.Name, model.Name); Assert.AreEqual(patient.Surname, model.Surname); Assert.AreEqual(MockedMedicalRecordNumber, model.MedicalNumber); }, " The emal, name, surname and medical numer are the injected values."); }
public async Task AddPatient() { PatientRepository patientRepository = new PatientRepository(_context); PatientController ctrl = new PatientController(patientRepository); var actionResult = await ctrl.CreatePatient(new PatientWriteDtoModel { PatientName = "Alireza Modrek", EmailAddress = "*****@*****.**", OfficialID = 1286015930, DateOfBirth = DateTime.Now, MetaData = new List <MetaDataDto> { new MetaDataDto { Key = "Diabet", Value = "No" }, new MetaDataDto { Key = "Blood", Value = "B+" } } }); var okResult = actionResult as OkObjectResult; Assert.Equal(okResult.StatusCode, 200); }
public async Task CreatePatient_ReturnsBadRequest_GivenInvalidPatient() { string testId = string.Empty; try { testId = Test.AddTest( new testDefinition { name = "Create Patient Return Bad Request Given Invalid Patient", description = "Return a bad request if you provide a invalid Patient", storyName = "Patient Creation", featureName = "Negative Tests", epicName = "Unit Tests" }); Test.AddStep(new step { description = "Arrange", name = "Step 1: Arrange" }); // Arrange PatientController sut = this.sutBuilder.WithRepository(this.mockRepositories.Object); sut.ModelState.AddModelError("error", "some error"); Test.StopStep(Status.passed); Test.AddStep( new step { description = "Act", name = "Step 2: Act", listParamenters = new List <Parameter> { new Parameter { name = "Patient", value = null } } }); // Act var result = await sut.CreatePatient(null); Test.StopStep(Status.passed); Test.AddStep(new step { description = "Assert", name = "Step 3: Assert" }); // Assert Assert.IsType <BadRequestObjectResult>(result); Test.StopStep(Status.passed); Test.StopTest(testId, Status.passed, "Test success", "Passed"); } catch (Exception ex) { Test.StopStep(Status.failed); Test.StopTest(testId, Status.passed, "Test failed", ex.ToString()); Assert.True(false); } }
public void CreatePatientTest() { //Arrange base.EmulateControllerContext(controller, false); repository.Setup(r => r.GetMaxPatientNumber()).Returns(27); //Act var result = controller.CreatePatient(); //Assert Assert.That(result, Is.Not.Null); Assert.That(result is ViewResultBase); var partialResult = result as ViewResultBase; Assert.That(partialResult.Model, Is.Not.Null); Assert.That(partialResult.Model is PatientViewModel); var model = partialResult.Model as PatientViewModel; Assert.That(model.Id, Is.EqualTo(0)); Assert.That(model.IsActive, Is.True); }
public async Task CreatePatient_ReturnsBadRequest_GivenInvalidPatient() { PatientController sut = this.sutBuilder.WithRepository(this.mockRepositories.Object); sut = this.sutBuilder.WithRepository(this.mockRepositories.Object); PatientViewModel patient = new PatientViewModel(); IActionResult result = await sut.CreatePatient(patient); await AllureLifecycle.Instance.WrapInStep(async() => { // Arrange sut.ModelState.AddModelError("error", "some error"); //Act result = await sut.CreatePatient(null); }, "Action: Create patient error model"); AllureLifecycle.Instance.WrapInStep(() => { // Assert Assert.IsInstanceOf <BadRequestObjectResult>(result); }, "Expected: Returns BadRequest"); }
public async Task InsertPatient_ValidPatient_InsertionOK(string name, string lastname, string email) { IActionResult result = null; PatientController sut = null; Guid id = Guid.NewGuid(); PatientViewModel patientToInsert = new PatientViewModel(); AllureLifecycle.Instance.WrapInStep(() => { // Arrange patientToInsert = new PatientViewModel { Email = email, Id = id, Surname = lastname, Name = name }; Patient mappedPatientToInsert = this.mapper.Map <Patient>(patientToInsert); this.mockPatientRepository.Setup(repo => repo.Add(It.Is <Patient>(p => p.Equals(mappedPatientToInsert)))); sut = this.sutBuilder.WithRepository(this.mockRepositories.Object); }, "Action: Step 1: Arrange"); await AllureLifecycle.Instance.WrapInStep(async() => { // Act result = await sut.CreatePatient(patientToInsert); }, $"Action: Step 2: Insert patient with Name:{patientToInsert.Name}, surname: {patientToInsert.Surname}, id: {patientToInsert.Id} and email: {patientToInsert.Email} "); AllureLifecycle.Instance.WrapInStep(() => { // Assert this.mockRepositories.Verify(); PatientViewModel model = AssertAndGetModel <PatientViewModel>(result); // we expect the MRN to be this string patientToInsert.MedicalNumber = MockedMedicalRecordNumber; Assert.AreEqual(JsonConvert.SerializeObject(patientToInsert), JsonConvert.SerializeObject(model)); }, "Check if the patient was inserted"); }
public async void InsertPatient_ValidPatient_InsertionOK(string name, string lastname, string email) { Guid id = Guid.NewGuid(); string testId = string.Empty; try { testId = Test.AddTest( new testDefinition { name = "Insert a Patient", description = "This test should insert a patient", storyName = "Insert a Patient", featureName = "Positive Tests", epicName = "Unit Tests" }); // Arrange Test.AddStep(new step { description = "Arrange", name = "Step 1: Arrange" }); PatientViewModel patientToInsert = new PatientViewModel { Email = email, Id = id, Surname = lastname, Name = name }; Patient mappedPatientToInsert = this.mapper.Map <Patient>(patientToInsert); this.mockPatientRepository.Setup(repo => repo.Add(It.Is <Patient>(p => p.Equals(mappedPatientToInsert)))); PatientController sut = this.sutBuilder.WithRepository(this.mockRepositories.Object); Test.StopStep(Status.passed); // Act Test.AddStep( new step { description = "Insert patient", name = "Step 2: Act", listParamenters = new List <Parameter> { new Parameter { name = "Email", value = patientToInsert.Email }, new Parameter { name = "Name", value = patientToInsert.Name }, new Parameter { name = "Surname", value = patientToInsert.Surname }, new Parameter { name = "Id", value = patientToInsert.Id.ToString() } } }); var result = await sut.CreatePatient(patientToInsert); Test.StopStep(Status.passed); // Assert Test.AddStep(new step { description = "Check if the patient was inserted", name = "Step 3: Assert" }); this.mockRepositories.Verify(); var viewResult = Assert.IsType <OkObjectResult>(result); var model = Assert.IsAssignableFrom <PatientViewModel>(viewResult.Value); // we expect the MRN to be this string patientToInsert.MedicalNumber = MockedMedicalRecordNumber; Assert.Equal(JsonConvert.SerializeObject(patientToInsert), JsonConvert.SerializeObject(model)); Test.StopStep(Status.passed); Test.StopTest(testId, Status.passed, "Test success", "Passed"); } catch (Exception ex) { Test.StopStep(Status.failed); Test.StopTest(testId, Status.passed, "Test failed", ex.ToString()); Assert.True(false); } }
public async Task CreatePatient_Should_Create_A_New_Patient() { string testId = string.Empty; try { testId = Test.AddTest( new testDefinition { name = "Create a new Patient", description = "This test should create a new patient", storyName = "Patient Creation", featureName = "Positive Tests", epicName = "Unit Tests" }); // Arrange Test.AddStep(new step { description = "Arrange", name = "Step 1: Arrange" }); PatientController sut = this.sutBuilder.WithRepository(this.mockRepositories.Object); PatientViewModel patient = new PatientViewModel { Name = "Carlos", Surname = "Carmona", Email = "*****@*****.**" }; Test.StopStep(Status.passed); // Act Test.AddStep( new step { description = "Act", name = "Step 2: Act", listParamenters = new List <Parameter> { new Parameter { name = "Email", value = "*****@*****.**" }, new Parameter { name = "Name", value = "Carlos" }, new Parameter { name = "Surname", value = "Carmona" } } }); var result = await sut.CreatePatient(patient); Test.StopStep(Status.passed); // Assert Test.AddStep(new step { description = "Assert", name = "Step 3: Assert" }); var viewResult = Assert.IsType <OkObjectResult>(result); var model = Assert.IsType <PatientViewModel>(viewResult.Value); this.mockPatientRepository.Verify(repo => repo.Add(It.IsAny <Patient>())); Assert.Equal(patient.Email, model.Email); Assert.Equal(patient.Name, model.Name); Assert.Equal(patient.Surname, model.Surname); Assert.Equal(MockedMedicalRecordNumber, model.MedicalNumber); Test.StopStep(Status.passed); Test.StopTest(testId, Status.passed, "Test success", "Passed"); } catch (Exception ex) { Test.StopStep(Status.failed); Test.StopTest(testId, Status.passed, "Test failed", ex.ToString()); Assert.True(false, ex.ToString()); } }
public async Task InsertPatient_ValidPatient_InsertionOK(string name, string lastname, string email, int id) { string testId = ""; try { testId = Test.addTest(new testDefinition { name = "Insert a Patient", description = "This test should insert a patient", storyName = "Insert a Patient", featureName = "Positive Tests", epicName = "Unit Tests" }); // Arrange Test.addStep(new step { description = "Arrange", name = "Step 1: Arrange" }); PatientViewModel patientToInsert = new PatientViewModel { Email = email, Id = id, Surname = lastname, Name = name }; Patient mappedPatientToInsert = this.mapper.Map <Patient>(patientToInsert); this.mockUserRepo.Setup(repo => repo.AddPatient(It.Is <Patient>(p => p.Equals(mappedPatientToInsert)))); PatientController sut = this.sutBuilder.WithRepository(this.mockUserRepo.Object); Test.stopStep(Status.passed); // Act Test.addStep(new step { description = "Insert patient", name = "Step 2: Act", listParamenters = new List <Allure.Commons.Parameter> { { new Allure.Commons.Parameter { name = "Email", value = patientToInsert.Email } }, { new Allure.Commons.Parameter { name = "Name", value = patientToInsert.Name } }, { new Allure.Commons.Parameter { name = "Surname", value = patientToInsert.Surname } }, { new Allure.Commons.Parameter { name = "Id", value = patientToInsert.Id.ToString() } } } }); var result = await sut.CreatePatient(patientToInsert); Test.stopStep(Status.passed); // Assert Test.addStep(new step { description = "Check if the patient was inserted", name = "Step 3: Assert" }); this.mockUserRepo.Verify(); var viewResult = Assert.IsType <OkObjectResult>(result); var model = Assert.IsAssignableFrom <PatientViewModel>(viewResult.Value); Assert.Equal(JsonConvert.SerializeObject(patientToInsert), JsonConvert.SerializeObject(model)); Test.stopStep(Status.passed); Test.stopTest(testId, Status.passed, "Test success", "Passed"); } catch (Exception ex) { Test.stopStep(Status.failed); Test.stopTest(testId, Status.passed, "Test failed", ex.ToString()); Assert.True(false); } }
public async void Create_new_patient_Test() { var response = await _patientController.CreatePatient(_patientCreate); Assert.IsType <OkResult>(response); }