public void FindsAConsentedPersonWhenConsentIsRequired()
        {
            var personOneAgain = createContext.Find <PersonEntity>(personOne.Id);
            var study          = new StudyEntity {
                Name = Random.String()
            };
            var subject = new StudySubjectEntity
            {
                Person = personOneAgain, Study = study, SubjectIdentifier = Random.String()
            };
            var consent = new ConsentEntity
            {
                DateProvided = DateTime.Today, GivenBy = personOneAgain, StudySubject = subject
            };

            createContext.AddRange(study, subject, consent);
            createContext.SaveChanges();

            repository.FindPersonBy(
                new PersonIdentifierSpecification(Identifiers.NhsNumber(personOneNhsNumber))
                )?.Id.Should().Be(personOne.Id);

            repository.FindPersonBy(
                new CompositePersonSpecification(
                    new PersonIdentifierSpecification(Identifiers.NhsNumber(personOneNhsNumber)),
                    new ConsentedPersonSpecification(new StudyIdentity(study.Id))
                    )
                ).Should().Be((PersonIdentity)personOne.Id);
        }
Esempio n. 2
0
 private static void AssertStudySubject(StudySubjectEntity expected, StudySubject actual)
 {
     using (new AssertionScope())
     {
         actual.StudyId.Id.Should().Be(expected.Study.Id);
         actual.PersonId.Id.Should().Be(expected.Person.Id);
         actual.SubjectIdentifier.Should().Be(expected.SubjectIdentifier);
     }
 }
Esempio n. 3
0
        /// <inheritdoc />
        public ConsentRepositoryTests(ITestOutputHelper outputHelper, DatabaseFixture fixture) : base(outputHelper, fixture)
        {
            readContext   = CreateNewContextInSameTransaction();
            updateContext = CreateNewContextInSameTransaction();
            createContext = CreateNewContextInSameTransaction();


            study = createContext.Studies.Add(new StudyEntity {
                Name = Random.String()
            }).Entity;

            var consentedPerson = createContext.People.Add(new PersonEntity()).Entity;

            consentedStudySubject = createContext.Add(new StudySubjectEntity {
                Study = study, Person = consentedPerson, SubjectIdentifier = "Consented"
            }).Entity;
            createContext.Add(
                new ConsentEntity
            {
                StudySubject  = consentedStudySubject,
                DateProvided  = 1.December(1965),
                DateWithdrawn = 1.January(1966),
                GivenBy       = consentedPerson
            });

            activeConsent = createContext.Add(
                new ConsentEntity
            {
                StudySubject = consentedStudySubject,
                DateProvided = 1.February(1966),
                GivenBy      = consentedPerson
            }).Entity;

            var unconsentedPerson = createContext.People.Add(new PersonEntity()).Entity;

            createContext.Add(
                new StudySubjectEntity {
                Study = study, Person = unconsentedPerson, SubjectIdentifier = "Unconsented"
            });

            var withdrawnConsent = createContext.Add(new PersonEntity()).Entity;
            var withdrawnSubject = createContext.Add(
                new StudySubjectEntity {
                Study = study, Person = withdrawnConsent, SubjectIdentifier = "Withdrawn"
            }).Entity;

            withdrawnSubjectWithdrawnDate = 5.January(2018);
            createContext.Add(new ConsentEntity
            {
                StudySubject  = withdrawnSubject,
                DateProvided  = 1.December(2017),
                DateWithdrawn = withdrawnSubjectWithdrawnDate,
                GivenBy       = withdrawnConsent
            });


            createContext.SaveChanges();

            studyId             = new StudyIdentity(study.Id);
            consentedPersonId   = consentedPerson;
            unconsentedPersonId = unconsentedPerson;
            withdrawnPersonId   = withdrawnConsent;

            consents = CreateConsentRepository(readContext);

            studySubjects = CreateStudySubjectRepository(readContext);
            studies       = CreateStudyRepository(readContext);
        }