Beispiel #1
0
        public void AddsNewEpisodeReasonAnswerUsingTheStartAndEndDateOfTheCurrentAnswers()
        {
            var personId = 123;
            var groupId  = Guid.NewGuid().ToString();
            var currentActiveAnswersStartDate = DateTime.Today.AddDays(-10);

            var caseStatus = TestHelpers.CreateCaseStatus(type: "LAC", personId: personId);

            var currentActiveAnswers = TestHelpers.CreateCaseStatusAnswers(caseStatusId: caseStatus.Id, startDate: currentActiveAnswersStartDate, min: 2, max: 2, groupId: groupId);

            caseStatus.Answers = new List <CaseStatusAnswerInfrastructure>();
            caseStatus.Answers.AddRange(currentActiveAnswers);
            DatabaseContext.CaseStatuses.Add(caseStatus);
            DatabaseContext.SaveChanges();

            var requestAnswer = CaseStatusHelper.CreateCaseStatusRequestAnswers(min: 1, max: 1);

            var request = CaseStatusHelper.CreateCaseStatusAnswerRequest(caseStatusId: caseStatus.Id, answers: requestAnswer, startDate: DateTime.Today.AddDays(-2));

            _caseStatusGateway.ReplaceCaseStatusAnswers(request);

            var updatedCaseStatus = DatabaseContext.CaseStatuses.FirstOrDefault();

            updatedCaseStatus.Answers.Where(x => x.GroupId == groupId).Count().Should().Be(3);

            var episodeEndReasonAnswer = updatedCaseStatus.Answers.Where(x => x.GroupId == groupId && x.Option == CaseStatusAnswerOption.EpisodeReason && x.Value == CaseStatusAnswerValue.X1).FirstOrDefault();

            episodeEndReasonAnswer.Should().NotBeNull();
            episodeEndReasonAnswer.StartDate.Should().Be(currentActiveAnswersStartDate);
            episodeEndReasonAnswer.EndDate.Should().Be(request.StartDate);
            episodeEndReasonAnswer.CreatedBy = request.CreatedBy;
        }
Beispiel #2
0
        public void WhenRequestIsValidReturnsIsValid()
        {
            var validRequest = CaseStatusHelper.CreateCaseStatusAnswerRequest();

            var response = _createCaseStatusAnswerRequestValidator.Validate(validRequest);

            response.IsValid.Should().BeTrue();
        }
Beispiel #3
0
        public void ReplaceActiveCaseStatusAnswersThrowsAnExceptionWhenCaseStatusNotFound()
        {
            var request = CaseStatusHelper.CreateCaseStatusAnswerRequest();

            Action act = () => _caseStatusGateway.ReplaceCaseStatusAnswers(request);

            act.Should().Throw <CaseStatusDoesNotExistException>().WithMessage($"Case status id {request.CaseStatusId} does not exist.");
        }
Beispiel #4
0
        public void WhenStartDateIsDefaultDateTimeValueReturnsErrorWithMessage()
        {
            var badRequest = CaseStatusHelper.CreateCaseStatusAnswerRequest(startDate: DateTime.MinValue);

            var response = _createCaseStatusAnswerRequestValidator.Validate(badRequest);

            response.IsValid.Should().BeFalse();
            response.Errors.Should().Contain(e => e.ErrorMessage == "'startDate' must have a valid value");
        }
Beispiel #5
0
        public void WhenCreatedByIsNotAnEmailAddressReturnsErrorWithMessage()
        {
            var badRequest = CaseStatusHelper.CreateCaseStatusAnswerRequest(createdBy: "foobar");

            var response = _createCaseStatusAnswerRequestValidator.Validate(badRequest);

            response.IsValid.Should().BeFalse();
            response.Errors.Should().Contain(e => e.ErrorMessage == "'createdBy' must be an email address");
        }
 public void SetUp()
 {
     _mockCaseStatusGateway = new Mock <ICaseStatusGateway>();
     _mockDatabaseGateway   = new Mock <IDatabaseGateway>();
     _caseStatusesUseCase   = new CaseStatusesUseCase(_mockCaseStatusGateway.Object, _mockDatabaseGateway.Object);
     _request             = CaseStatusHelper.CreateCaseStatusAnswerRequest();
     _lacCaseStatusDomain = CaseStatusHelper.CreateCaseStatus(type: "LAC").ToDomain();
     _worker        = TestHelpers.CreateWorker();
     _lacCaseStatus = TestHelpers.CreateCaseStatus(type: "LAC");
 }
Beispiel #7
0
        public void WhenAnswerCountIsTwoReturnsItIsValid()
        {
            var answers = CaseStatusHelper.CreateCaseStatusRequestAnswers(min: 2, max: 2);

            var request = CaseStatusHelper.CreateCaseStatusAnswerRequest(answers: answers);

            var response = _createCaseStatusAnswerRequestValidator.Validate(request);

            response.IsValid.Should().BeTrue();
        }
Beispiel #8
0
        public void WhenAnswerCountIsNotOneOrTwoReturnsErrorWithMessage(int answerCount)
        {
            var answers = CaseStatusHelper.CreateCaseStatusRequestAnswers(min: answerCount, max: answerCount);

            var request = CaseStatusHelper.CreateCaseStatusAnswerRequest(answers: answers);

            var response = _createCaseStatusAnswerRequestValidator.Validate(request);

            response.IsValid.Should().BeFalse();
            response.Errors.Should().Contain(e => e.ErrorMessage == "Provide either one or two answers only");
        }
Beispiel #9
0
 public void SetUp()
 {
     _answers = CaseStatusHelper.CreateCaseStatusRequestAnswers(min: 1, max: 1);
     _mockCaseStatusGateway = new Mock <ICaseStatusGateway>();
     _mockDatabaseGateway   = new Mock <IDatabaseGateway>();
     _caseStatusesUseCase   = new CaseStatusesUseCase(_mockCaseStatusGateway.Object, _mockDatabaseGateway.Object);
     _request            = CaseStatusHelper.CreateCaseStatusAnswerRequest(answers: _answers);
     _cpCaseStatusDomain = CaseStatusHelper.CreateCaseStatus(type: "CP").ToDomain();
     _worker             = TestHelpers.CreateWorker();
     _cpCaseStatus       = TestHelpers.CreateCaseStatus(type: "CP");
 }
Beispiel #10
0
        public void UpdatesTheEndDateOnActiveAnswersAndReplacesCurrentScheduledCaseStatusAnswers()
        {
            var personId = 123;
            var groupId  = Guid.NewGuid().ToString();

            var caseStatus = TestHelpers.CreateCaseStatus(type: "LAC", personId: personId);

            var currentScheduledAnswers = TestHelpers.CreateCaseStatusAnswers(caseStatusId: caseStatus.Id, startDate: DateTime.Today.AddDays(10).Date, min: 2, max: 2, groupId: groupId);

            caseStatus.Answers.AddRange(currentScheduledAnswers);
            DatabaseContext.CaseStatuses.Add(caseStatus);
            DatabaseContext.SaveChanges();

            var requestAnswer1 = new CaseStatusRequestAnswers()
            {
                Option = "placementType",
                Value  = "P1"
            };

            var requestAnswer2 = new CaseStatusRequestAnswers()
            {
                Option = "legalStatus",
                Value  = "L1"
            };

            var requestAnswers = new List <CaseStatusRequestAnswers>()
            {
                requestAnswer1, requestAnswer2
            };

            var request = CaseStatusHelper.CreateCaseStatusAnswerRequest(caseStatusId: caseStatus.Id, answers: requestAnswers, startDate: DateTime.Today.AddDays(20));

            _caseStatusGateway.ReplaceCaseStatusAnswers(request);

            var caseStatusAnswers = DatabaseContext.CaseStatuses.Include(x => x.Answers).FirstOrDefault().Answers;

            caseStatusAnswers.Count.Should().Be(4);

            var discardedScheduledAnswers = caseStatusAnswers.Where(x => x.GroupId == groupId);

            discardedScheduledAnswers.All(x => x.DiscardedAt != null).Should().BeTrue();
            discardedScheduledAnswers.All(x => x.EndDate == null).Should().BeTrue();
            discardedScheduledAnswers.All(x => x.LastModifiedBy == request.CreatedBy).Should().BeTrue();

            var newScheduledAnswers = caseStatusAnswers.Where(x => x.GroupId != groupId);

            newScheduledAnswers.All(x => x.StartDate == request.StartDate).Should().BeTrue();
            newScheduledAnswers.Any(x => x.Option == requestAnswer1.Option && x.Value == requestAnswer1.Value).Should().BeTrue();
            newScheduledAnswers.Any(x => x.Option == requestAnswer2.Option && x.Value == requestAnswer2.Value).Should().BeTrue();
        }
Beispiel #11
0
        public void UpdatesTheEndDateOnActiveAnswersAndAddsNewAnswers()
        {
            var personId   = 123;
            var groupId    = Guid.NewGuid().ToString();
            var caseStatus = TestHelpers.CreateCaseStatus(type: "LAC", personId: personId);

            var currentActiveAnswers = TestHelpers.CreateCaseStatusAnswers(caseStatusId: caseStatus.Id, startDate: DateTime.Today.AddDays(-10), min: 2, max: 2, groupId: groupId);

            caseStatus.Answers.AddRange(currentActiveAnswers);
            DatabaseContext.CaseStatuses.Add(caseStatus);
            DatabaseContext.SaveChanges();

            var requestAnswer1 = new CaseStatusRequestAnswers()
            {
                Option = "placementType",
                Value  = "P1"
            };

            var requestAnswer2 = new CaseStatusRequestAnswers()
            {
                Option = "legalStatus",
                Value  = "L1"
            };

            var requestAnswers = new List <CaseStatusRequestAnswers>()
            {
                requestAnswer1, requestAnswer2
            };

            var request = CaseStatusHelper.CreateCaseStatusAnswerRequest(caseStatusId: caseStatus.Id, answers: requestAnswers, startDate: DateTime.Today.AddDays(-2));

            _caseStatusGateway.ReplaceCaseStatusAnswers(request);

            var caseStatusAnswers = DatabaseContext.CaseStatuses.FirstOrDefault().Answers;

            caseStatusAnswers.Count.Should().Be(5);

            var previousActiveAnswers = caseStatusAnswers.Where(x => x.GroupId == groupId && x.Option != CaseStatusAnswerOption.EpisodeReason);

            previousActiveAnswers.All(x => x.EndDate != null).Should().BeTrue();
            previousActiveAnswers.All(x => x.EndDate == request.StartDate);
            previousActiveAnswers.All(x => x.DiscardedAt == null).Should().BeTrue();
            previousActiveAnswers.All(x => x.LastModifiedBy == request.CreatedBy).Should().BeTrue();

            var newActiveAnswers = caseStatusAnswers.Where(x => x.GroupId != groupId);

            newActiveAnswers.All(x => x.EndDate == null).Should().BeTrue();
            newActiveAnswers.All(x => x.StartDate == request.StartDate).Should().BeTrue();
            newActiveAnswers.All(x => x.DiscardedAt == null).Should().BeTrue();
        }
Beispiel #12
0
        public void CreatesMultipleCaseStatusAnswers()
        {
            var caseStatus = TestHelpers.CreateCaseStatus(type: "LAC");

            DatabaseContext.CaseStatuses.Add(caseStatus);
            DatabaseContext.SaveChanges();

            var request = CaseStatusHelper.CreateCaseStatusAnswerRequest(caseStatusId: caseStatus.Id);

            request.Answers = CaseStatusHelper.CreateCaseStatusRequestAnswers(min: 2);

            _caseStatusGateway.CreateCaseStatusAnswer(request);

            var updatedCaseStatus = DatabaseContext.CaseStatuses.Include(x => x.Answers).FirstOrDefault();

            updatedCaseStatus.Answers.Count.Should().Be(request.Answers.Count);
        }
Beispiel #13
0
        public void WhenAnswersAreNotProvidedReturnsAnErrorWithMessages()
        {
            var requestWithoutAnswers = CaseStatusHelper
                                        .CreateCaseStatusAnswerRequest(answers:
                                                                       new List <CaseStatusRequestAnswers>()
            {
                new CaseStatusRequestAnswers()
                {
                    Option = "", Value = ""
                }
            }
                                                                       );

            var response = _createCaseStatusAnswerRequestValidator.Validate(requestWithoutAnswers);

            response.IsValid.Should().BeFalse();
            response.Errors.Should().Contain(e => e.ErrorMessage == "'option' must not be empty");
            response.Errors.Should().Contain(e => e.ErrorMessage == "'value' must not be empty");
        }
Beispiel #14
0
        public void CreatesACaseStatusAnswer()
        {
            var caseStatus = TestHelpers.CreateCaseStatus(type: "LAC");

            DatabaseContext.CaseStatuses.Add(caseStatus);
            DatabaseContext.SaveChanges();

            var request = CaseStatusHelper.CreateCaseStatusAnswerRequest(caseStatusId: caseStatus.Id);

            _caseStatusGateway.CreateCaseStatusAnswer(request);

            var caseStatusAnswer = DatabaseContext.CaseStatuses.Include(x => x.Answers).FirstOrDefault(x => x.Id == caseStatus.Id).Answers.FirstOrDefault();

            caseStatusAnswer.CaseStatusId.Should().Be(caseStatus.Id);
            caseStatusAnswer.CreatedBy.Should().Be(request.CreatedBy);
            caseStatusAnswer.CreatedAt.Should().NotBeNull();
            caseStatusAnswer.Option.Should().Be(request.Answers.First().Option);
            caseStatusAnswer.Value.Should().Be(request.Answers.First().Value);
            caseStatusAnswer.StartDate.Should().Be(request.StartDate);
            caseStatusAnswer.CreatedAt.Should().NotBeNull();
        }
        public async Task EndLACCaseStatusThatHasScheduledAnswers()
        {
            //create new LAC case status, start date 12/01/2000
            var postUri = new Uri($"api/v1/residents/{_person.Id}/case-statuses", UriKind.Relative);

            var answers = CaseStatusHelper.CreateCaseStatusRequestAnswers(min: 2, max: 2);

            var request = CaseStatusHelper.CreateCaseStatusRequest(
                personId: _person.Id,
                type: "LAC",
                answers: answers,
                startDate: new DateTime(2000, 01, 12),
                createdBy: _worker.Email
                );

            request.Notes = null;

            var requestContent = new StringContent(JsonSerializer.Serialize(request), Encoding.UTF8, "application/json");

            var createCaseStatusResponse = await Client.PostAsync(postUri, requestContent).ConfigureAwait(true);

            createCaseStatusResponse.StatusCode.Should().Be(201);

            //Get request to check that the case status has been added
            var getUri = new Uri($"api/v1/residents/{_person.Id}/case-statuses", UriKind.Relative);
            var getCaseStatusesResponse = await Client.GetAsync(getUri).ConfigureAwait(true);

            getCaseStatusesResponse.StatusCode.Should().Be(200);

            var addedContent = await getCaseStatusesResponse.Content.ReadAsStringAsync().ConfigureAwait(true);

            var addedCaseStatusResponse = JsonConvert.DeserializeObject <List <CaseStatusResponse> >(addedContent).ToList();

            addedCaseStatusResponse.Count.Should().Be(1);
            addedCaseStatusResponse.Single().Answers.Count.Should().Be(2);
            addedCaseStatusResponse.Single().EndDate.Should().BeNull();
            addedCaseStatusResponse.Single().Notes.Should().BeNull();
            addedCaseStatusResponse.Single().StartDate.Should().Be(request.StartDate.ToString("O"));
            addedCaseStatusResponse.Single().Type.Should().Be(request.Type);

            //patch request to update the start date to 11/01/2000
            var caseStatusId = addedCaseStatusResponse.First().Id;

            var patchUri = new Uri($"api/v1/case-statuses/{caseStatusId}", UriKind.Relative);

            var patchRequest = TestHelpers.CreateUpdateCaseStatusRequest(startDate: new DateTime(2000, 01, 11), email: _worker.Email, caseStatusId: caseStatusId, min: 2, max: 2);

            patchRequest.Notes   = null;
            patchRequest.EndDate = null;

            var patchRequestContent = new StringContent(JsonSerializer.Serialize(patchRequest), Encoding.UTF8, "application/json");

            var patchStatusResponse = await Client.PatchAsync(patchUri, patchRequestContent).ConfigureAwait(true);

            patchStatusResponse.StatusCode.Should().Be(200);

            //Get request to check that the case status was update
            var getCaseStatusesResponseAfterUpdate = await Client.GetAsync(getUri).ConfigureAwait(true);

            getCaseStatusesResponseAfterUpdate.StatusCode.Should().Be(200);

            var updateContent = await getCaseStatusesResponseAfterUpdate.Content.ReadAsStringAsync().ConfigureAwait(true);

            var updatedCaseStatusResponse = JsonConvert.DeserializeObject <List <CaseStatusResponse> >(updateContent).ToList();

            updatedCaseStatusResponse.Count.Should().Be(1);
            updatedCaseStatusResponse.Single().Answers.Count.Should().Be(2);
            updatedCaseStatusResponse.Single().EndDate.Should().BeNull();
            updatedCaseStatusResponse.Single().Notes.Should().BeNull();
            updatedCaseStatusResponse.Single().StartDate.Should().Be(patchRequest.StartDate?.ToString("O"));
            updatedCaseStatusResponse.Single().Type.Should().Be(request.Type);

            //add new scheduled answer
            var postScheduledAnswersUri = new Uri($"api/v1/case-statuses/{caseStatusId}/answers", UriKind.Relative);

            var addScheduledAnswersRequest = CaseStatusHelper.CreateCaseStatusAnswerRequest(
                caseStatusId: caseStatusId,
                startDate: new DateTime(2040, 02, 01),
                createdBy: _worker.Email
                );

            request.Notes = null;

            var scheduledAnswersRequestContent = new StringContent(JsonSerializer.Serialize(addScheduledAnswersRequest), Encoding.UTF8, "application/json");

            var createScheduledAnswersResponse = await Client.PostAsync(postScheduledAnswersUri, scheduledAnswersRequestContent).ConfigureAwait(true);

            createScheduledAnswersResponse.StatusCode.Should().Be(201);

            //Get request to check that the scheduled answers were added
            var getCaseStatusesResponseAfterScheduledUpdate = await Client.GetAsync(getUri).ConfigureAwait(true);

            getCaseStatusesResponseAfterScheduledUpdate.StatusCode.Should().Be(200);

            var updatedContentWithScheduledStatus = await getCaseStatusesResponseAfterScheduledUpdate.Content.ReadAsStringAsync().ConfigureAwait(true);

            var updatedCaseStatusWithScheduledStatusResponse = JsonConvert.DeserializeObject <List <CaseStatusResponse> >(updatedContentWithScheduledStatus).ToList();

            updatedCaseStatusWithScheduledStatusResponse.Count.Should().Be(1);
            updatedCaseStatusWithScheduledStatusResponse.Single().Answers.Count.Should().Be(5);
            updatedCaseStatusWithScheduledStatusResponse.Single().Answers.Where(x => x.Option != CaseStatusAnswerOption.EpisodeReason).Last().StartDate.Should().Be(addScheduledAnswersRequest.StartDate);

            //patch case status to end it
            var endRequest = TestHelpers.CreateUpdateCaseStatusRequest(endDate: new DateTime(2000, 01, 11), email: _worker.Email, caseStatusId: caseStatusId, min: 1, max: 1);

            patchRequest.Notes     = null;
            patchRequest.StartDate = null;

            var serialisedEndRequest = JsonSerializer.Serialize(endRequest);
            var endRequestContent    = new StringContent(serialisedEndRequest, Encoding.UTF8, "application/json");

            var endStatusResponse = await Client.PatchAsync(patchUri, endRequestContent).ConfigureAwait(true);

            endStatusResponse.StatusCode.Should().Be(200);

            //get request to check that the case has been closed (end point only returns active ones at the moment)
            var getCaseStatusesResponseAfterEnd = await Client.GetAsync(getUri).ConfigureAwait(true);

            getCaseStatusesResponseAfterEnd.StatusCode.Should().Be(200);

            var contentAfterContent = await getCaseStatusesResponseAfterEnd.Content.ReadAsStringAsync().ConfigureAwait(true);

            var endCaseStatusResponse = JsonConvert.DeserializeObject <List <CaseStatusResponse> >(contentAfterContent).ToList();

            endCaseStatusResponse.Count.Should().Be(0);
        }
Beispiel #16
0
 public void SetUp()
 {
     _mockCaseStatusesUseCase = new Mock <ICaseStatusesUseCase>();
     _caseStatusController    = new CaseStatusController(_mockCaseStatusesUseCase.Object);
     _request = CaseStatusHelper.CreateCaseStatusAnswerRequest(answers: CaseStatusHelper.CreateCaseStatusRequestAnswers(min: 2, max: 2)); //TODO: use DI for validator setup for easy mocking
 }