public void WhenThereAreNoRelationshipsReturnsEmptyListForPersonalRelationships() { var(person, _, _, _, _) = PersonalRelationshipsHelper.SavePersonWithPersonalRelationshipToDatabase(DatabaseContext, withRelationship: false); var response = _databaseGateway.GetPersonWithPersonalRelationshipsByPersonId(person.Id); response.PersonalRelationships.Should().BeEmpty(); }
public void WhenDetailsIs1000CharactersReturnsItIsValid() { var validRequest = PersonalRelationshipsHelper.CreatePersonalRelationshipRequest(details: _faker.Random.String(1000)); var response = createPersonalRelationshipRequestValidator.Validate(validRequest); response.IsValid.Should().BeTrue(); }
public void WhenRequestIsValidReturnsItIsValid() { var validRequest = PersonalRelationshipsHelper.CreatePersonalRelationshipRequest(); var response = createPersonalRelationshipRequestValidator.Validate(validRequest); response.IsValid.Should().BeTrue(); }
public void WhenIsInformalCarerIsValidReturnsItIsValid(string isInformalCarer) { var validRequest = PersonalRelationshipsHelper.CreatePersonalRelationshipRequest(isInformalCarer: isInformalCarer); var response = createPersonalRelationshipRequestValidator.Validate(validRequest); response.IsValid.Should().BeTrue(); }
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); }
public void WhenIncludeEndedRelationshipsIsTrueReturnsPersonalRelationships() { var(person, _, _, _, _) = PersonalRelationshipsHelper.SavePersonWithPersonalRelationshipToDatabase(DatabaseContext, hasEnded: true); var response = _databaseGateway.GetPersonWithPersonalRelationshipsByPersonId(person.Id, includeEndedRelationships: true); response.PersonalRelationships.Should().NotBeEmpty(); }
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)); }
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); }
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); }
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'."); }
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."); }
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); }
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"); }
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); }
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'."); }
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); }
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"); }
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>(); }
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."); }
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); }
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()); }
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); }
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)); }