Exemple #1
0
        public async Task <IActionResult> CreateNewCase(NewCaseModel caseModel)
        {
            if (ModelState.IsValid == false)
            {
                return(ValidationProblem());
            }
            (int existingCaseId, DateTime? deleted) = await _courtCasesService
                                                      .ExistsCaseNumberAsync(caseModel.CaseNumber, caseModel.AppealNumber);

            if (existingCaseId != -1 && deleted.HasValue == false)
            {
                return(UnprocessableEntity("Case already exists"));
            }
            if (caseModel.AppealNumber > 0)
            {
                (int prevAppealCaseId, DateTime? prevAppealDeleted) = await _courtCasesService
                                                                      .ExistsCaseNumberAsync(caseModel.CaseNumber, caseModel.AppealNumber - 1);

                if (prevAppealCaseId == -1 || prevAppealDeleted.HasValue)
                {
                    return(UnprocessableEntity("Previous appeal does not exist"));
                }
                CaseStatusModel caseStatus = await _courtCasesService.GetCaseStatusAsync(prevAppealCaseId);

                if (caseStatus.StatusName != ProceedingDecisions.FinalJudgement)
                {
                    return(UnprocessableEntity($"Previous appeal status, {caseStatus.StatusName}, must be {ProceedingDecisions.FinalJudgement}"));
                }
            }
            int currUser = _sessionService.GetUserId(HttpContext);
            int caseId   = await _courtCasesService.CreateAsync(caseModel, currUser); // restore case if deleted

            return(Created("api/Case/Details", caseId));
        }
        private static CaseStatusModel GetSampleData_CaseStatus()
        {
            var result = new CaseStatusModel
            {
                StatusId   = 1,
                StatusName = "FINAL JUDGEMENT"
            };

            return(result);
        }
        private bool CaseNeedsToBeUpdated(CaseStatusModel nisraCaseStatusModel, CaseStatusModel existingCaseStatusModel,
                                          string instrumentName)
        {
            if (existingCaseStatusModel == null)
            {
                _loggerService.LogWarn($"The nisra case '{nisraCaseStatusModel.PrimaryKey}' does not exist in the database for the instrument '{instrumentName}'");
                return(false);
            }

            return(_caseComparisonService.CaseNeedsToBeUpdated(nisraCaseStatusModel, existingCaseStatusModel, instrumentName));
        }
        public void Given_The_Nisra_Case_Has_A_Valid_Outcome_But_Existing_Case_Has_An_Outcome_Of_Zero_When_I_Call_CaseNeedsToBeUpdated_Then_True_Is_Returned(int nisraOutcome)
        {
            //arrange
            var nisraCaseStatusModel    = new CaseStatusModel(_primaryKey, _hOutPartial, _date1);
            var existingCaseStatusModel = new CaseStatusModel(_primaryKey, _hOutNotStarted, _date2);

            //act
            var result = _sut.CaseNeedsToBeUpdated(nisraCaseStatusModel, existingCaseStatusModel, _instrumentName);

            //assert
            Assert.IsTrue(result);
        }
        public void Given_The_Nisra_Case_Has_An_Outcome_Of_Complete_And_Existing_Case_Has_An_Outcome_Between_210_And_542_When_I_Call_CaseNeedsToBeUpdated_Then_True_Is_Returned(int existingOutcome)
        {
            //arrange
            var nisraCaseStatusModel    = new CaseStatusModel(_primaryKey, _hOutComplete, _date1);
            var existingCaseStatusModel = new CaseStatusModel(_primaryKey, existingOutcome, _date2);

            //act
            var result = _sut.CaseNeedsToBeUpdated(nisraCaseStatusModel, existingCaseStatusModel, _instrumentName);

            //assert
            Assert.IsTrue(result);
        }
        public void Given_The_Nisra_Case_Has_An_Outcome_Of_Partial_And_Existing_Case_Has_An_Outcome_Of_Ineligible_When_I_Call_CaseNeedsToBeUpdated_Then_True_Is_Returned()
        {
            //arrange
            var nisraCaseStatusModel    = new CaseStatusModel(_primaryKey, _hOutPartial, _date1);
            var existingCaseStatusModel = new CaseStatusModel(_primaryKey, _hOutIneligible, _date2);

            //act
            var result = _sut.CaseNeedsToBeUpdated(nisraCaseStatusModel, existingCaseStatusModel, _instrumentName);

            //assert
            Assert.IsTrue(result);
        }
        public void Given_The_Case_Has_Been_Processed_Before_When_I_Call_CaseNeedsToBeUpdated_Then_False_Is_Returned()
        {
            //arrange
            var nisraCaseStatusModel    = new CaseStatusModel(_primaryKey, _hOutComplete, _date1);
            var existingCaseStatusModel = new CaseStatusModel(_primaryKey, _hOutComplete, _date1);

            //act
            var result = _sut.CaseNeedsToBeUpdated(nisraCaseStatusModel, existingCaseStatusModel, _instrumentName);

            //assert
            Assert.IsFalse(result);
        }
        public void Given_The_Nisra_Outcome_Is_Zero_When_I_Call_CaseNeedsToBeUpdated_Then_False_Is_Returned(int existingOutcome)
        {
            //arrange
            var nisraCaseStatusModel    = new CaseStatusModel(_primaryKey, _hOutNotStarted, _date1);
            var existingCaseStatusModel = new CaseStatusModel(_primaryKey, existingOutcome, _date2);

            //act
            var result = _sut.CaseNeedsToBeUpdated(nisraCaseStatusModel, existingCaseStatusModel, _instrumentName);

            //assert
            Assert.IsFalse(result);
        }
Exemple #9
0
        public async Task <ActionResult <CaseStatusModel> > GetCaseStatus(int caseId)
        {
            if (caseId < 1)
            {
                return(UnprocessableEntity($"Invalid CaseId: {caseId}"));
            }
            CaseStatusModel caseStatus = await _courtCasesService.GetCaseStatusAsync(caseId);

            if (caseStatus is null)
            {
                return(NotFound());
            }
            return(Ok(caseStatus));
        }
        internal bool NisraRecordHasAlreadyBeenProcessed(CaseStatusModel nisraCaseStatusModel, CaseStatusModel existingCaseStatusModel,
                                                         string instrumentName)
        {
            var recordHasAlreadyBeenProcessed =
                nisraCaseStatusModel.Outcome == existingCaseStatusModel.Outcome &&
                nisraCaseStatusModel.LastUpdated == existingCaseStatusModel.LastUpdated;

            _loggingService.LogInfo($"Check if NISRA case has already been processed previously '{nisraCaseStatusModel.PrimaryKey}': '{recordHasAlreadyBeenProcessed}' - " +
                                    $"(NISRA HOut = '{nisraCaseStatusModel.Outcome}' timestamp = '{nisraCaseStatusModel.LastUpdated}') " +
                                    $"(Existing HOut = '{existingCaseStatusModel.Outcome}' timestamp = '{existingCaseStatusModel.LastUpdated}')" +
                                    $" for instrument '{instrumentName}'");

            return(recordHasAlreadyBeenProcessed);
        }
        public void Given_A_Record_Has_Not_Been_Processed_Before_Due_To_Different_LastUpdated_Dates_When_I_Call_NisraRecordHasAlreadyBeenProcessed_Then_False_Is_Returned()
        {
            //arrange
            var nisraCaseStatusModel    = new CaseStatusModel(_primaryKey, _hOutComplete, _date1);
            var existingCaseStatusModel = new CaseStatusModel(_primaryKey, _hOutComplete, _date2);

            //act
            var result = _sut.NisraRecordHasAlreadyBeenProcessed(nisraCaseStatusModel, existingCaseStatusModel,
                                                                 _instrumentName);

            //assert
            Assert.IsNotNull(result);
            Assert.False(result);
        }
        public void Given_The_Nisra_Case_Has_An_Outcome_Of_Complete_And_Existing_Case_Has_An_Outcome_Of_Delete_When_I_Call_CaseNeedsToBeUpdated_Then_False_Is_Returned()
        {
            //arrange
            const int outcomeCode = 561; //respondent request for data to be deleted

            var nisraCaseStatusModel    = new CaseStatusModel(_primaryKey, _hOutPartial, _date1);
            var existingCaseStatusModel = new CaseStatusModel(_primaryKey, outcomeCode, _date2);

            //act
            var result = _sut.CaseNeedsToBeUpdated(nisraCaseStatusModel, existingCaseStatusModel, _instrumentName);

            //assert
            Assert.IsFalse(result);
        }
        public NisraFileImportServiceTests()
        {
            _primaryKey       = "SN123";
            _serverParkName   = "Park1";
            _instrumentName   = "OPN123";
            _databaseFileName = "OPN123.bdbx";

            _nisraCaseStatusModel = new CaseStatusModel(_primaryKey, 110, DateTime.Now.AddHours(-1).ToString(CultureInfo.InvariantCulture));
            _existingStatusModel  = new CaseStatusModel(_primaryKey, 210, DateTime.Now.AddHours(-2).ToString(CultureInfo.InvariantCulture));

            _existingCaseStatusList = new List <CaseStatusModel>
            {
                _existingStatusModel
            };
        }
        public async Task GetCaseStatus_NotFound()
        {
            // Arrange
            int             caseId   = 1;
            CaseStatusModel expected = null;

            _mockCourtCasesService.GetCaseStatusAsync(caseId).Returns(expected);

            // Act
            ActionResult <CaseStatusModel> response = await _sut.GetCaseStatus(caseId);

            // Assert
            await _mockCourtCasesService.Received(1).GetCaseStatusAsync(caseId);

            Assert.IsType <NotFoundResult>(response.Result);
        }
        public bool CaseNeedsToBeUpdated(CaseStatusModel nisraCaseStatusModel, CaseStatusModel existingCaseStatusModel,
                                         string instrumentName)
        {
            if (nisraCaseStatusModel.Outcome == 0)
            {
                _loggingService.LogInfo($"Not processed: NISRA case '{nisraCaseStatusModel.PrimaryKey}' (NISRA HOut = 0) for instrument '{instrumentName}'");

                return(false);
            }

            if (existingCaseStatusModel.Outcome == 561 || existingCaseStatusModel.Outcome == 562)
            {
                _loggingService.LogInfo(
                    $"Not processed: NISRA case '{nisraCaseStatusModel.PrimaryKey}' (Existing HOut = '{existingCaseStatusModel.Outcome}' for instrument '{instrumentName}'");

                return(false);
            }

            if (NisraRecordHasAlreadyBeenProcessed(nisraCaseStatusModel, existingCaseStatusModel, instrumentName))
            {
                _loggingService.LogInfo(
                    $"Not processed: NISRA case '{nisraCaseStatusModel.PrimaryKey}' as is has already been updated on a previous run for instrument '{instrumentName}'");

                return(false);
            }

            if (nisraCaseStatusModel.Outcome == 580 && existingCaseStatusModel.Outcome <= 210)
            {
                _loggingService.LogInfo(
                    $"Not processed: NISRA case '{nisraCaseStatusModel.PrimaryKey}' (Existing HOut = '{existingCaseStatusModel.Outcome}' < '{nisraCaseStatusModel.Outcome}')  for instrument '{instrumentName}'");

                return(false);
            }

            if (nisraCaseStatusModel.Outcome != 580 && existingCaseStatusModel.Outcome > 0 && existingCaseStatusModel.Outcome < nisraCaseStatusModel.Outcome)
            {
                _loggingService.LogInfo(
                    $"Not processed: NISRA case '{nisraCaseStatusModel.PrimaryKey}' (Existing HOut = '{existingCaseStatusModel.Outcome}' < '{nisraCaseStatusModel.Outcome}')  for instrument '{instrumentName}'");

                return(false);
            }

            _loggingService.LogInfo(
                $"processed: NISRA case '{nisraCaseStatusModel.PrimaryKey}' (NISRA HOut = '{nisraCaseStatusModel.Outcome}' <= '{existingCaseStatusModel.Outcome}') or (Existing HOut = 0)' for instrument '{instrumentName}'");

            return(true);
        }
        public async Task GetCaseStatus_Valid()
        {
            // Arrange
            int             caseId   = 1;
            CaseStatusModel expected = GetSampleData_CaseStatus();

            _mockCourtCasesService.GetCaseStatusAsync(caseId).Returns(expected);

            // Act
            ActionResult <CaseStatusModel> response = await _sut.GetCaseStatus(caseId);

            // Assert
            await _mockCourtCasesService.Received(1).GetCaseStatusAsync(caseId);

            var             createdAtActionResult = Assert.IsType <OkObjectResult>(response.Result);
            CaseStatusModel actual = (CaseStatusModel)createdAtActionResult.Value;

            Assert.True(actual is not null);
            Assert.Equal(expected.StatusId, actual.StatusId);
            Assert.Equal(expected.StatusName, actual.StatusName);
        }
 public bool AddCaseStatus(CaseStatusModel caseStatus)
 {
     Console.WriteLine("add CaseStatusModel");
     return(true);
 }
 public bool ModifyCaseStatus(CaseStatusModel caseStatus)
 {
     Console.WriteLine("modify CaseStatusModel");
     return(true);
 }