public void UpdateCaseInfoBadRequestFailureTest()
        {
            var caseInfoDto = new CaseInfoDto
            {
                CaseId          = 1,
                CaseNumber      = "1",
                CourtNumber     = "1",
                Value           = 1,
                Judge           = 'F',
                Court           = "Test",
                CounterParty    = "Test",
                Note            = "Test",
                DateCreated     = DateTime.Now,
                DateModified    = DateTime.Now,
                IsDeleted       = false,
                CaseCategory    = 1,
                CustomerId      = 1,
                ClientId        = 1,
                CreatedByUserId = 1
            };

            var caseInfoRepo = new Mock <ICaseInfoRepository>();

            caseInfoRepo.Setup(x => x.EditCaseInfoById(It.IsAny <int>(), It.IsAny <CaseInfoDto>())).Throws <Exception>();
            var     caseInfoManipulation = new CaseInfoManipulation(caseInfoRepo.Object);
            IMapper _mapper    = new Mapper(null);
            var     controller = new CaseInfoController(caseInfoManipulation, _mapper);
            var     result     = controller.Put(1, caseInfoDto);

            Assert.IsType <Boolean>(result);
        }
        public void DeleteCaseInfoSuccessTest()
        {
            var caseInfoDto = new CaseInfoDto
            {
                CaseId          = 1,
                CaseNumber      = "1",
                CourtNumber     = "1",
                Value           = 1,
                Judge           = 'F',
                Court           = "Test",
                CounterParty    = "Test",
                Note            = "Test",
                DateCreated     = DateTime.Now,
                DateModified    = DateTime.Now,
                IsDeleted       = false,
                CaseCategory    = 1,
                CustomerId      = 1,
                ClientId        = 1,
                CreatedByUserId = 1
            };

            var caseInfoRepo = new Mock <ICaseInfoRepository>();

            caseInfoRepo.Setup(x => x.DeleteCase(It.IsAny <int>()));
            var     caseInfoManipulation = new CaseInfoManipulation(caseInfoRepo.Object);
            IMapper _mapper    = new Mapper(null);
            var     controller = new CaseInfoController(caseInfoManipulation, _mapper);
            var     result     = controller.DeleteCase(1);

            Assert.IsType <OkObjectResult>(result);
        }
        public void CreateCaseInfoNoContentFailureTest()
        {
            var caseInfoDto = new CaseInfoDto
            {
                CaseId          = 1,
                CaseNumber      = "1",
                CourtNumber     = "1",
                Value           = 1,
                Judge           = 'F',
                Court           = "Test",
                CounterParty    = "Test",
                Note            = "Test",
                DateCreated     = DateTime.Now,
                DateModified    = DateTime.Now,
                IsDeleted       = false,
                CaseCategory    = 1,
                CustomerId      = 1,
                ClientId        = 1,
                CreatedByUserId = 1
            };

            var mockRepo = new Mock <ICaseInfoManipulation>();

            mockRepo.Setup(x => x.CreateCaseInfo(It.IsAny <CaseInfoDto>()));
            IMapper _mapper    = new Mapper(null);
            var     controller = new CaseInfoController(mockRepo.Object, _mapper);
            var     result     = controller.Post(caseInfoDto);

            Assert.IsType <NoContentResult>(result);
        }
Exemple #4
0
        //public bool DeleteCaseInfoById(int caseId) {
        //    try
        //    {
        //        var caseInfo = _dbContext.CaseInfo.FirstOrDefault(x => x.CaseId == caseId);
        //        if (caseInfo != null)
        //        {
        //            if (_dbContext.CaseInfo.Remove(caseInfo) != null)
        //            {
        //                _dbContext.SaveChanges();
        //                return true;
        //            }
        //        }
        //        return false;
        //    }
        //    catch (Exception ex)
        //    {
        //        throw new Exception(ex.InnerException.Message);
        //    }
        //}

        public bool EditCaseInfoById(int caseId, CaseInfoDto caseInfoDto)
        {
            if (caseInfoDto == null)
            {
                throw new ArgumentNullException(nameof(caseInfoDto), "Address argument is not provided!");
            }

            try
            {
                var CaseInfoTmp = _dbContext.CaseInfo.FirstOrDefault(x => x.CaseId == caseId);
                if (CaseInfoTmp != null)
                {
                    _logger.LogError(CaseInfoTmp.ToString());
                    CaseInfoTmp = Mappers.CaseInfoRepository.MapToDbEntityEdit(CaseInfoTmp, caseInfoDto);
                    _dbContext.CaseInfo.Update(CaseInfoTmp);
                    _dbContext.SaveChanges();
                    return(true);
                }
                else
                {
                    throw new Exception("DatabaseError");
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.InnerException.Message);
            }
        }
Exemple #5
0
 public bool Put(int id, [FromBody] CaseInfoDto _caseInfoDto)
 {
     try
     {
         return(_caseInfoRepository.EditCaseInfoById(id, _caseInfoDto));
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
Exemple #6
0
 public static CaseInfo MapToDbEntityEdit(CaseInfo caseInfoOriginal, CaseInfoDto caseInfoEdit)
 {
     caseInfoOriginal.CaseNumber      = caseInfoEdit.CaseNumber ?? caseInfoOriginal.CaseNumber;
     caseInfoOriginal.CourtNumber     = caseInfoEdit.CourtNumber ?? caseInfoOriginal.CourtNumber;
     caseInfoOriginal.Value           = caseInfoEdit.Value ?? caseInfoOriginal.Value;
     caseInfoOriginal.Judge           = caseInfoEdit.Judge ?? caseInfoOriginal.Judge;
     caseInfoOriginal.Court           = caseInfoEdit.Court ?? caseInfoOriginal.Court;
     caseInfoOriginal.CounterParty    = caseInfoEdit.CounterParty ?? caseInfoOriginal.CounterParty;
     caseInfoOriginal.Note            = caseInfoEdit.Note ?? caseInfoOriginal.Note;
     caseInfoOriginal.DateModified    = DateTime.Now;
     caseInfoOriginal.CaseCategory    = caseInfoEdit.CaseCategory;
     caseInfoOriginal.CustomerId      = caseInfoEdit.CustomerId;
     caseInfoOriginal.ClientId        = caseInfoEdit.ClientId;
     caseInfoOriginal.CreatedByUserId = caseInfoEdit.CreatedByUserId;
     return(caseInfoOriginal);
 }
Exemple #7
0
 public static CaseInfo MapToDbEntity(CaseInfoDto caseInfoDto)
 {
     return(new CaseInfo()
     {
         CaseNumber = caseInfoDto.CaseNumber,
         CourtNumber = caseInfoDto.CourtNumber,
         Value = caseInfoDto.Value,
         Judge = caseInfoDto.Judge,
         Court = caseInfoDto.Court,
         CounterParty = caseInfoDto.CounterParty,
         Note = caseInfoDto.Note,
         CaseCategory = caseInfoDto.CaseCategory,
         CustomerId = caseInfoDto.CustomerId,
         ClientId = caseInfoDto.ClientId,
         CreatedByUserId = caseInfoDto.CreatedByUserId
     });
 }
Exemple #8
0
 public CaseInfo CreateCaseInfo(CaseInfoDto caseInfoDto)
 {
     try
     {
         CaseInfo caseInfo = Mappers.CaseInfoRepository.MapToDbEntity(caseInfoDto);
         _dbContext.CaseInfo.Add(caseInfo);
         if (_dbContext.SaveChanges() != 0)
         {
             return(caseInfo);
         }
     }
     catch (Exception ex)
     {
         throw new Exception(ex.InnerException.Message);
     }
     return(null);
 }
Exemple #9
0
 public IActionResult Post([FromBody] CaseInfoDto _caseInfoDto)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     try
     {
         var caseInfo = _caseInfoRepository.CreateCaseInfo(_caseInfoDto);
         if (caseInfo != null)
         {
             return(Ok(_mapper.Map <CaseInfoDto>(caseInfo)));
         }
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.InnerException));
     }
     return(NoContent());
 }
        public void geCaseInfosTest()
        {
            var caseInfo = new CaseInfoDto
            {
                CaseId          = 1,
                CaseNumber      = "1",
                CourtNumber     = "1",
                Value           = 1,
                Judge           = 'F',
                Court           = "Test",
                CounterParty    = "Test",
                Note            = "Test",
                DateCreated     = DateTime.Now,
                DateModified    = DateTime.Now,
                IsDeleted       = false,
                CaseCategory    = 1,
                CustomerId      = 1,
                ClientId        = 1,
                CreatedByUserId = 1
            };

            var addresses = new List <CaseInfoDto>
            {
                caseInfo
            };

            var mockRepo = new Mock <ICaseInfoRepository>();

            mockRepo.Setup(x => x.GetCaseInfos()).Returns(addresses);
            var     caseInfoManipulation = new CaseInfoManipulation(mockRepo.Object);
            IMapper _mapper        = new Mapper(null);
            var     controller     = new CaseInfoController(caseInfoManipulation, _mapper);
            var     result         = controller.Get();
            var     okObjectResult = result as OkObjectResult;

            Assert.NotNull(okObjectResult);
            Assert.IsType <OkObjectResult>(result);
        }
 //public bool  DeleteCaseInfoById(int caseId) {
 //    return _caseInfoRepository.DeleteCaseInfoById(caseId);
 //}
 public bool EditCaseInfoById(int caseId, CaseInfoDto caseInfoDto)
 {
     return(_caseInfoRepository.EditCaseInfoById(caseId, caseInfoDto));
 }
 public CaseInfo CreateCaseInfo(CaseInfoDto caseInfoDto)
 {
     return(_caseInfoRepository.CreateCaseInfo(caseInfoDto));
 }