Ejemplo n.º 1
0
 public async Task <IActionResult> AddIdentityNumber(IdsDto idsDto)
 {
     try
     {
         if (string.IsNullOrWhiteSpace(idsDto.idNumbers))
         {
             return(BadRequest("No identity numbers in request"));
         }
         //split identity numbers from request
         var idNumbers = idsDto.idNumbers.Trim()
                         .Split(new string[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
         //Get the valid and invalid id information if they exist.
         IdInfo idInfo = _identityNumberService.ExtractIdInformation(idNumbers, _identityNumberValidator);
         // Save to data store: In case as a csv file
         if (idInfo.validIdInfos.Any())
         {
             await _dataRepository.Save(idInfo.validIdInfos);
         }
         if (idInfo.InvalidIdInfos.Any())
         {
             await _dataRepository.Save(idInfo.InvalidIdInfos);
         }
         return(NoContent());
     }
     catch (Exception e)
     {
         _logger.LogError(e.Message, e);
         return(StatusCode(500, e.Message));
     }
 }
Ejemplo n.º 2
0
        public void ExtractIdInformation_GivenRightAndWrongIdentityNumber_SplitsIdsToValidAndInvalidIdInfo()
        {
            var idNumbers = new string[] { "8605065397083", "0109046424188" };
            var idInfo    = _identityNumberService.ExtractIdInformation(idNumbers, _identityNumberValidator);

            Assert.That(idInfo.validIdInfos.Any(), Is.True);
            Assert.That(idInfo.InvalidIdInfos.Any, Is.True);
        }