예제 #1
0
        public void WhenThereAreNoRelationshipsReturnsEmptyListForPersonalRelationships()
        {
            var(person, _, _, _, _) = PersonalRelationshipsHelper.SavePersonWithPersonalRelationshipToDatabase(DatabaseContext, withRelationship: false);

            var response = _databaseGateway.GetPersonWithPersonalRelationshipsByPersonId(person.Id);

            response.PersonalRelationships.Should().BeEmpty();
        }
예제 #2
0
        public void WhenDetailsIs1000CharactersReturnsItIsValid()
        {
            var validRequest = PersonalRelationshipsHelper.CreatePersonalRelationshipRequest(details: _faker.Random.String(1000));

            var response = createPersonalRelationshipRequestValidator.Validate(validRequest);

            response.IsValid.Should().BeTrue();
        }
예제 #3
0
        public void WhenRequestIsValidReturnsItIsValid()
        {
            var validRequest = PersonalRelationshipsHelper.CreatePersonalRelationshipRequest();

            var response = createPersonalRelationshipRequestValidator.Validate(validRequest);

            response.IsValid.Should().BeTrue();
        }
예제 #4
0
        public void WhenIsInformalCarerIsValidReturnsItIsValid(string isInformalCarer)
        {
            var validRequest = PersonalRelationshipsHelper.CreatePersonalRelationshipRequest(isInformalCarer: isInformalCarer);

            var response = createPersonalRelationshipRequestValidator.Validate(validRequest);

            response.IsValid.Should().BeTrue();
        }
예제 #5
0
        public void WhenThereIsARelationshipWithDetailsReturnsTheDetails()
        {
            var(person, _, _, _, personalRelationshipDetail) = PersonalRelationshipsHelper.SavePersonWithPersonalRelationshipToDatabase(DatabaseContext, details: "Emergency contact");

            var response = _databaseGateway.GetPersonWithPersonalRelationshipsByPersonId(person.Id);

            response.PersonalRelationships.FirstOrDefault().Details.Details.Should().BeEquivalentTo(personalRelationshipDetail.Details);
        }
예제 #6
0
        public void WhenIncludeEndedRelationshipsIsTrueReturnsPersonalRelationships()
        {
            var(person, _, _, _, _) = PersonalRelationshipsHelper.SavePersonWithPersonalRelationshipToDatabase(DatabaseContext, hasEnded: true);

            var response = _databaseGateway.GetPersonWithPersonalRelationshipsByPersonId(person.Id, includeEndedRelationships: true);

            response.PersonalRelationships.Should().NotBeEmpty();
        }
예제 #7
0
        public void WhenDetailsIsAbove1000CharactersReturnsErrorWithMessage()
        {
            var badRequest = PersonalRelationshipsHelper.CreatePersonalRelationshipRequest(details: _faker.Random.String(1001));

            var response = createPersonalRelationshipRequestValidator.Validate(badRequest);

            response.IsValid.Should().BeFalse();
            response.Errors.Should().Contain(e => e.ErrorMessage == "'details' must be less than or equal to 1,000 characters.");
        }
        public void CallsPersonalRelationshipsUseCaseToCreatePersonalRelationship()
        {
            _mockPersonalRelationshipsUseCase.Setup(x => x.ExecutePost(It.IsAny <CreatePersonalRelationshipRequest>()));
            var request = PersonalRelationshipsHelper.CreatePersonalRelationshipRequest();

            var response = _relationshipController.CreatePersonalRelationship(request) as BadRequestObjectResult;

            _mockPersonalRelationshipsUseCase.Verify(x => x.ExecutePost(request));
        }
예제 #9
0
        public void WhenMatchingIDReturnsRelationship()
        {
            var(person, _, personalRelationship, _, _) = PersonalRelationshipsHelper.SavePersonWithPersonalRelationshipToDatabase(DatabaseContext);

            var response = _databaseGateway.GetPersonalRelationshipById(personalRelationship.Id);

            response.Id.Should().Be(personalRelationship.Id);
            response.PersonId.Should().Be(person.Id);
        }
예제 #10
0
        public void WhenPersonHasPersonalRelationshipsReturnsRelationshipsMappedToType()
        {
            var(person, _, _) = PersonalRelationshipsHelper.CreatePersonWithPersonalRelationships();
            _mockDatabaseGateway.Setup(x => x.GetPersonWithPersonalRelationshipsByPersonId(It.IsAny <long>(), It.IsAny <bool>())).Returns(person);

            var result = _relationshipsUseCase.ExecuteGet(person.Id);

            result.PersonalRelationships.Should().HaveCount(3);
        }
예제 #11
0
        public void WhenIsInformalCarerIsInvalidReturnsErrorWithMessage(string isInformalCarer)
        {
            var badRequest = PersonalRelationshipsHelper.CreatePersonalRelationshipRequest(isInformalCarer: isInformalCarer);

            var response = createPersonalRelationshipRequestValidator.Validate(badRequest);

            response.IsValid.Should().BeFalse();
            response.Errors.Should().Contain(e => e.ErrorMessage == "'isInformalCarer' must be 'Y' or 'N'.");
        }
예제 #12
0
        public void WhenCreatedByIsNotAnEmailAddressReturnsErrorWithMessage()
        {
            var badRequest = PersonalRelationshipsHelper.CreatePersonalRelationshipRequest(createdBy: "foobar");

            var response = createPersonalRelationshipRequestValidator.Validate(badRequest);

            response.IsValid.Should().BeFalse();
            response.Errors.Should().Contain(e => e.ErrorMessage == "'createdBy' must be an email address.");
        }
예제 #13
0
        public void WhenThereIsARelationshipReturnsTheDescriptionOfThePersonalRelationshipType()
        {
            var(person, _, _, personalRelationshipType, _) = PersonalRelationshipsHelper.SavePersonWithPersonalRelationshipToDatabase(DatabaseContext, relationshipType: "stepParent");

            var response = _databaseGateway.GetPersonWithPersonalRelationshipsByPersonId(person.Id);
            var personalRelationshipTypeInResponse = response.PersonalRelationships.FirstOrDefault().Type;

            personalRelationshipTypeInResponse.Description.Should().Equals(personalRelationshipType.Description);
        }
        public void Setup()
        {
            _mockProcessDataGateway = new Mock <IProcessDataGateway>();
            _mockSystemTime         = new Mock <ISystemTime>();

            _databaseGateway = new DatabaseGateway(DatabaseContext, _mockProcessDataGateway.Object,
                                                   _mockSystemTime.Object);

            (_, _, _relationship, _, _, _oppositeRelationship) = PersonalRelationshipsHelper.SavePersonWithPersonalRelationshipAndOppositeToDatabase(DatabaseContext);
        }
예제 #15
0
        public void WhenThereArePersonalRelationshipsReturnsAnObjectForEachExistingType()
        {
            var(person, _, personalRelationships) = PersonalRelationshipsHelper.CreatePersonWithPersonalRelationships();

            var response = personalRelationships.ToResponse();

            response.Should().HaveCount(3);
            response.Should().Contain(pr => pr.Type == "parent");
            response.Should().Contain(pr => pr.Type == "child");
            response.Should().Contain(pr => pr.Type == "neighbour");
        }
예제 #16
0
        public void WhenThereIsARelationshipReturnsThePersonalRelationship()
        {
            var(person, _, personalRelationship, _, _) = PersonalRelationshipsHelper.SavePersonWithPersonalRelationshipToDatabase(DatabaseContext);

            var response = _databaseGateway.GetPersonWithPersonalRelationshipsByPersonId(person.Id);

            response.PersonalRelationships.FirstOrDefault().Id.Should().Be(personalRelationship.Id);
            response.PersonalRelationships.FirstOrDefault().PersonId.Should().Be(personalRelationship.PersonId);
            response.PersonalRelationships.FirstOrDefault().OtherPersonId.Should().Be(personalRelationship.OtherPersonId);
            response.PersonalRelationships.FirstOrDefault().TypeId.Should().Be(personalRelationship.TypeId);
        }
예제 #17
0
        public void WhenDetailsIsNullDoesNotThrowNullReferenceException()
        {
            var(person, otherPersons, personalRelationships) = PersonalRelationshipsHelper.CreatePersonWithPersonalRelationships();
            person.PersonalRelationships[0].Details          = null;
            person.PersonalRelationships[1].Details          = null;
            person.PersonalRelationships[2].Details          = null;

            Action act = () => personalRelationships.ToResponse();

            act.Should().NotThrow <NullReferenceException>();
        }
        public void WhenRequestIsValidReturnsSuccessfulResponse()
        {
            var request = PersonalRelationshipsHelper.CreatePersonalRelationshipRequest();

            var response = _relationshipController.CreatePersonalRelationship(request);

            response.Should().BeOfType <CreatedAtActionResult>();
            var createdAtAction = response as CreatedAtActionResult;

            createdAtAction.StatusCode.Should().Be(201);
            createdAtAction.Value.Should().Be("Successfully created personal relationship.");
        }
        public void WhenRequestIsInValidReturnsBadRequest400WithMessage()
        {
            var badRequest = PersonalRelationshipsHelper.CreatePersonalRelationshipRequest(isMainCarer: "invalid");

            var response = _relationshipController.CreatePersonalRelationship(badRequest);

            response.Should().BeOfType <BadRequestObjectResult>();
            var badRequestObject = response as BadRequestObjectResult;

            badRequestObject.StatusCode.Should().Be(400);
            badRequestObject.Value.Should().Be("'isMainCarer' must be 'Y' or 'N'.");
        }
예제 #20
0
        public void WhenThereIsARelationshipReturnsTheDetailsOfTheOtherPerson()
        {
            var(person, otherPerson, _, _, _) = PersonalRelationshipsHelper.SavePersonWithPersonalRelationshipToDatabase(DatabaseContext);

            var response = _databaseGateway.GetPersonWithPersonalRelationshipsByPersonId(person.Id);
            var otherPersonInResponse = response.PersonalRelationships.FirstOrDefault().OtherPerson;

            otherPersonInResponse.Id.Should().Be(otherPerson.Id);
            otherPersonInResponse.FirstName.Should().Be(otherPerson.FirstName);
            otherPersonInResponse.LastName.Should().Be(otherPerson.LastName);
            otherPersonInResponse.Gender.Should().Be(otherPerson.Gender);
        }
        public void WhenWorkerNotFoundExceptionIsThrownReturns400WithMessage()
        {
            var exceptionMessage = "error message";

            _mockPersonalRelationshipsUseCase.Setup(x => x.ExecutePost(It.IsAny <CreatePersonalRelationshipRequest>()))
            .Throws(new WorkerNotFoundException(exceptionMessage));
            var request = PersonalRelationshipsHelper.CreatePersonalRelationshipRequest();

            var response = _relationshipController.CreatePersonalRelationship(request) as BadRequestObjectResult;

            response?.StatusCode.Should().Be(400);
            response?.Value.Should().Be(exceptionMessage);
        }
예제 #22
0
        public void WhenIsMainCarerIsLowercaseConvertsItToUppercase()
        {
            var(person, otherPerson) = PersonalRelationshipsHelper.SavePersonAndOtherPersonToDatabase(DatabaseContext);
            var type    = DatabaseContext.PersonalRelationshipTypes.FirstOrDefault(prt => prt.Description == "parent");
            var request = PersonalRelationshipsHelper.CreatePersonalRelationshipRequest(
                person.Id, otherPerson.Id, type.Id, type.Description, isMainCarer: "y"
                );

            _databaseGateway.CreatePersonalRelationship(request);

            var personalRelationship = DatabaseContext.PersonalRelationships.FirstOrDefault();

            personalRelationship?.IsMainCarer.Should().Be("Y");
        }
예제 #23
0
        public void WhenIsMainCarerIsNullItDoesNotThrowANullException()
        {
            var(person, otherPerson) = PersonalRelationshipsHelper.SavePersonAndOtherPersonToDatabase(DatabaseContext);
            var type    = DatabaseContext.PersonalRelationshipTypes.FirstOrDefault(prt => prt.Description == "parent");
            var request = PersonalRelationshipsHelper.CreatePersonalRelationshipRequest(
                person.Id, otherPerson.Id, type.Id, type.Description
                );

            request.IsMainCarer = null;

            Action act = () => _databaseGateway.CreatePersonalRelationship(request);

            act.Should().NotThrow <NullReferenceException>();
        }
예제 #24
0
        public void AuditsThePersonalRelationshipDetails()
        {
            var(person, otherPerson) = PersonalRelationshipsHelper.SavePersonAndOtherPersonToDatabase(DatabaseContext);
            var type    = DatabaseContext.PersonalRelationshipTypes.FirstOrDefault(prt => prt.Description == "parent");
            var request = PersonalRelationshipsHelper.CreatePersonalRelationshipRequest(
                person.Id, otherPerson.Id, type.Id, type.Description
                );

            var response = _databaseGateway.CreatePersonalRelationship(request);

            var details = DatabaseContext.PersonalRelationshipDetails.FirstOrDefault();

            details?.CreatedAt.Should().NotBeNull();
            details?.CreatedBy.Should().Be(request.CreatedBy);
        }
        public void WhenRelationshipWithTheSameTypeAlreadyExistsThrowsPersonalRelationshipAlreadyExistsException()
        {
            var sameTypeAsRequest = _typeInRequest;

            _person.PersonalRelationships = new List <PersonalRelationship>()
            {
                PersonalRelationshipsHelper.CreatePersonalRelationship(_person, _otherPerson, sameTypeAsRequest)
            };
            _mockDatabaseGateway.Setup(x => x.GetPersonWithPersonalRelationshipsByPersonId(It.IsAny <long>(), It.IsAny <bool>()))
            .Returns(_person);

            Action act = () => _personalRelationshipsUseCase.ExecutePost(_request);

            act.Should().Throw <PersonalRelationshipAlreadyExistsException>()
            .WithMessage($"Personal relationship with 'type' of '{_request.Type}' already exists.");
        }
예제 #26
0
        public void WhenThereAreMultipleRelationshipsReturnsAllRelevantPersonalRelationships()
        {
            var(person, _, _, personalRelationshipType, _) = PersonalRelationshipsHelper.SavePersonWithPersonalRelationshipToDatabase(DatabaseContext);
            var anotherPerson          = TestHelpers.CreatePerson();
            var anotherRelationship    = PersonalRelationshipsHelper.CreatePersonalRelationship(person, anotherPerson, personalRelationshipType, id: 1);
            var andAnotherPerson       = TestHelpers.CreatePerson();
            var andAnotherRelationship = PersonalRelationshipsHelper.CreatePersonalRelationship(person, andAnotherPerson, personalRelationshipType, hasEnded: true, id: 2);

            DatabaseContext.Persons.Add(anotherPerson);
            DatabaseContext.Persons.Add(andAnotherPerson);
            DatabaseContext.PersonalRelationships.Add(anotherRelationship);
            DatabaseContext.PersonalRelationships.Add(andAnotherRelationship);
            DatabaseContext.SaveChanges();

            var response = _databaseGateway.GetPersonWithPersonalRelationshipsByPersonId(person.Id);

            response.PersonalRelationships.Should().HaveCount(2);
        }
예제 #27
0
        public void CreatesAPersonalRelationship()
        {
            var(person, otherPerson) = PersonalRelationshipsHelper.SavePersonAndOtherPersonToDatabase(DatabaseContext);
            var type    = DatabaseContext.PersonalRelationshipTypes.FirstOrDefault(prt => prt.Description == "parent");
            var request = PersonalRelationshipsHelper.CreatePersonalRelationshipRequest(
                person.Id, otherPerson.Id, type.Id, type.Description
                );

            _databaseGateway.CreatePersonalRelationship(request);

            var personalRelationship = DatabaseContext.PersonalRelationships.FirstOrDefault();

            personalRelationship?.PersonId.Should().Be(request.PersonId);
            personalRelationship?.OtherPersonId.Should().Be(request.OtherPersonId);
            personalRelationship?.TypeId.Should().Be(request.TypeId);
            personalRelationship?.IsMainCarer.Should().Be(request.IsMainCarer.ToUpper());
            personalRelationship?.IsInformalCarer.Should().Be(request.IsInformalCarer.ToUpper());
        }
예제 #28
0
        public void SetsStartDateToNow()
        {
            var fakeTime = new DateTime(2000, 1, 1, 15, 30, 0);

            _mockSystemTime.Setup(time => time.Now).Returns(fakeTime);

            var(person, otherPerson) = PersonalRelationshipsHelper.SavePersonAndOtherPersonToDatabase(DatabaseContext);
            var type    = DatabaseContext.PersonalRelationshipTypes.FirstOrDefault(prt => prt.Description == "parent");
            var request = PersonalRelationshipsHelper.CreatePersonalRelationshipRequest(
                person.Id, otherPerson.Id, type.Id, type.Description
                );

            _databaseGateway.CreatePersonalRelationship(request);

            var personalRelationship = DatabaseContext.PersonalRelationships.FirstOrDefault();

            personalRelationship?.StartDate.Should().Be(fakeTime);
        }
예제 #29
0
        public void SetUp()
        {
            _mockDatabaseGateway          = new Mock <IDatabaseGateway>();
            _personalRelationshipsUseCase = new PersonalRelationshipsUseCase(_mockDatabaseGateway.Object);

            _mockDatabaseGateway.Setup(x => x.GetPersonalRelationshipTypeByDescription(_typeInRequest.Description))
            .Returns(_typeInRequest);

            _request = PersonalRelationshipsHelper.CreatePersonalRelationshipRequest(type: _typeInRequest.Description);

            _person      = TestHelpers.CreatePerson(_request.PersonId);
            _otherPerson = TestHelpers.CreatePerson(_request.OtherPersonId);

            _typeInExistingRelationship = PersonalRelationshipsHelper.CreatePersonalRelationshipType("partner");

            _relationship = PersonalRelationshipsHelper.CreatePersonalRelationship(_person, _otherPerson, _typeInExistingRelationship);
            _rel_details  = PersonalRelationshipsHelper.CreatePersonalRelationshipDetail(_relationship.Id, "some details for the relationship");
        }
        public void SetUp()
        {
            _mockDatabaseGateway          = new Mock <IDatabaseGateway>();
            _personalRelationshipsUseCase = new PersonalRelationshipsUseCase(_mockDatabaseGateway.Object);

            _mockDatabaseGateway.Setup(x => x.GetPersonalRelationshipTypeByDescription(_typeInRequest.Description))
            .Returns(_typeInRequest);

            var typeInExistingRelationship = PersonalRelationshipsHelper.CreatePersonalRelationshipType("partner");

            _mockDatabaseGateway.Setup(x => x.GetPersonalRelationshipTypeByDescription(typeInExistingRelationship.Description))
            .Returns(typeInExistingRelationship);

            _request = PersonalRelationshipsHelper.CreatePersonalRelationshipRequest(type: _typeInRequest.Description);

            _person      = TestHelpers.CreatePerson(_request.PersonId);
            _otherPerson = TestHelpers.CreatePerson(_request.OtherPersonId);

            var personalRelationship = PersonalRelationshipsHelper.CreatePersonalRelationship(_person, _otherPerson, typeInExistingRelationship);

            _person.PersonalRelationships = new List <PersonalRelationship>()
            {
                personalRelationship
            };

            _mockDatabaseGateway.Setup(x => x.GetPersonsByListOfIds(It.IsAny <List <long> >()))
            .Returns(new List <Person>()
            {
                _person, _otherPerson
            });

            _mockDatabaseGateway.Setup(x => x.GetPersonWithPersonalRelationshipsByPersonId(It.IsAny <long>(), It.IsAny <bool>()))
            .Returns(_person);

            _mockDatabaseGateway.Setup(x => x.CreatePersonalRelationship(It.IsAny <CreatePersonalRelationshipRequest>()))
            .Returns(personalRelationship);

            _mockDatabaseGateway.Setup(x => x.GetWorkerByEmail(It.IsAny <string>()))
            .Returns(TestHelpers.CreateWorker(email: _request.CreatedBy));
        }