public void Execute_GivenAddUpdatePatientCommandAdd_PatientShouldBeAddedToContext() { var fakeContext = A.Fake <DbContext>(); var set = new TestDbSet <Patient>(); var patientId = Guid.NewGuid(); var patientCommand = new AddUpdatePatientCommand() { PatientId = patientId, ClinicalSystemId = "1", DateOfBirth = new DateTime(1965, 01, 01), FirstName = "David", LastName = "Miller", GenderId = 1, NhsNumber = 123 }; A.CallTo(() => _unitOfWork.Context).Returns(fakeContext); A.CallTo(() => fakeContext.Set <Patient>()).Returns(set); _handler.Execute(patientCommand); set.Count(x => x.PatientId == patientId).Should().Be(1); var patient = set.First(x => x.PatientId == patientId); patient.PatientId.Should().Be(patientId); patient.ClinicalSystemId.Should().Be("1"); patient.DateOfBirth.ShouldBeEquivalentTo(new DateTime(1965, 01, 01)); patient.FirstName.Should().Be("David"); patient.LastName.Should().Be("Miller"); patient.GenderId.Should().Be(1); patient.NhsNumber.Should().Be(123); }
public void EditPOST_GivenValidModel_CommandDispatcherShouldBeCalled() { var command = new AddUpdatePatientCommand(); A.CallTo(() => _patientBuilder.BuildUpdatePatientCommand(A <EditPatientViewModel> ._)).Returns(command); _personController.Edit(A <EditPatientViewModel> ._); A.CallTo(() => _commandDispatcher.Dispatch(command)).MustHaveHappened(Repeated.Exactly.Once); }
public void CreatePOST_GivenValidModel_ShouldBeRedirectedToAssessmentCreateAction() { var patientId = Guid.NewGuid(); var command = new AddUpdatePatientCommand() { PatientId = patientId }; A.CallTo(() => _patientBuilder.BuildAddPatientCommand(A <CreatePatientViewModel> ._)).Returns(command); var result = _personController.Create(A <CreatePatientViewModel> ._) as RedirectToRouteResult; result.RouteValues["action"].Should().Be(MVC.Assessment.ActionNames.Create); result.RouteValues["controller"].Should().Be(MVC.Assessment.Name); result.RouteValues["id"].Should().Be(command.PatientId); }
public void Execute_GivenUpdatePatientCommandUpdate_PatientShouldBeUpdatedInContext() { var patientId = Guid.NewGuid(); var fakeContext = A.Fake <DbContext>(); var set = new TestDbSet <Patient> { new Patient() { PatientId = patientId } }; var command = new AddUpdatePatientCommand() { PatientId = patientId, ClinicalSystemId = "clinicalsystemid", NhsNumber = 123456789, FirstName = "firstname", LastName = "lastname", DateOfBirth = new DateTime(2015, 1, 1), GenderId = 1 }; A.CallTo(() => _unitOfWork.Context).Returns(fakeContext); A.CallTo(() => fakeContext.Set <Patient>()).Returns(set); _handler.Execute(command); var patient = set.First(x => x.PatientId == patientId); patient.ClinicalSystemId.Should().Be("clinicalsystemid"); patient.NhsNumber.Should().Be(123456789); patient.FirstName.Should().Be("firstname"); patient.LastName.Should().Be("lastname"); patient.DateOfBirth.Should().Be(new DateTime(2015, 1, 1)); patient.GenderId.Should().Be(1); }