示例#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;
        }
        public void WhenTypeIsLACAndProvidedAnswersCountIsNotOneItThrowsInvalidCaseStatusAnswersRequestException()
        {
            _mockCaseStatusGateway.Setup(x => x.GetCasesStatusByCaseStatusId(It.IsAny <long>())).Returns(_lacCaseStatus.ToDomain());

            _request.Answers = CaseStatusHelper.CreateCaseStatusRequestAnswers(min: 5, max: 5);

            Action act = () => _caseStatusesUseCase.ExecutePostCaseStatusAnswer(_request);

            act.Should().Throw <InvalidCaseStatusAnswersRequestException>().WithMessage("LAC must have only two answers");
        }
        public void WhenTypeIsLACAndTheAnswerCountIsOneReturnsItIsValid()
        {
            var answers = CaseStatusHelper.CreateCaseStatusRequestAnswers(min: 2, max: 2);

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

            var response = _createCaseStatusRequestValidator.Validate(request);

            response.IsValid.Should().BeTrue();
        }
        public void WhenTypeIsLACAndTheAnswerCountIsNotTwoReturnsErrorWithMessage(int answerCount)
        {
            var answers = CaseStatusHelper.CreateCaseStatusRequestAnswers(min: answerCount, max: answerCount);

            var request = CaseStatusHelper.CreateCaseStatusRequest(answers: answers, type: "LAC");

            var response = _createCaseStatusRequestValidator.Validate(request);

            response.IsValid.Should().BeFalse();
            response.Errors.Should().Contain(e => e.ErrorMessage == "LAC type must have two answers only");
        }
示例#5
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");
        }
示例#6
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");
 }
        public void WhenTypeIsCPorCINorLACReturnsItIsValid(string type)
        {
            var validRequest = CaseStatusHelper.CreateCaseStatusRequest(type: type);

            if (type == "LAC")
            {
                validRequest.Answers.AddRange(CaseStatusHelper.CreateCaseStatusRequestAnswers(min: 1, max: 1));
            }

            var response = _createCaseStatusRequestValidator.Validate(validRequest);

            response.IsValid.Should().BeTrue();
        }
示例#8
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);
        }
        public void WhenAnswersAreNotProvidedForTypesThatRequireThemReturnsAnErrorWithMessages(string type)
        {
            var answersWithoutValues = CaseStatusHelper.CreateCaseStatusRequestAnswers(min: 2, max: 2);

            foreach (var a in answersWithoutValues)
            {
                a.Option = "";
                a.Value  = "";
            }
            ;

            var request = CaseStatusHelper.CreateCaseStatusRequest(answers: answersWithoutValues, type: type);

            var response = _createCaseStatusRequestValidator.Validate(request);

            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");
        }
        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);
        }
示例#11
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
 }