Пример #1
0
 public IActionResult Put(int id, [FromBody] TypeReqModelIn typeReqIn)
 {
     if (ModelState.IsValid)
     {
         try
         {
             typeReqIn.Id = id;
             var typeReq = mapper.Map <TypeReqModelIn, TypeReqEntity>(typeReqIn);
             typeReqLogic.Update(typeReq);
             var updatedTypeReq         = typeReqLogic.GetById(id);
             var updatedTypeReqModelOut = mapper.Map <TypeReqEntity, TypeReqModelOut>(updatedTypeReq);
             return(Created("Put succesfully", updatedTypeReqModelOut));
         }
         catch (ArgumentException e)
         {
             return(BadRequest(e.Message));
         }
         catch (Exception ex)
         {
             return(BadRequest(ex.Message));
         }
     }
     else
     {
         return(BadRequest(ModelState));
     }
 }
Пример #2
0
        public void UpdateTypeReqTest()
        {
            var testTypeReqEntityUpd = new TypeReqEntity
            {
                Id               = 1234,
                Name             = "Tax",
                AdditionalFields = new AdditionalFieldEntity[] { new AdditionalFieldEntity() }
            };

            typeReqRepository.Setup(u => u.Exists(It.IsAny <Expression <Func <TypeReqEntity, bool> > >())).Returns(true);
            typeReqRepository.Setup(u => u.FirstOrDefault(It.IsAny <Expression <Func <TypeReqEntity, bool> > >())).Returns(testTypeReqEntityUpd);
            typeReqRepository.Setup(u => u.Update(It.IsAny <TypeReqEntity>())).Verifiable();
            typeReqRepository.Setup(u => u.FirstOrDefault(It.IsAny <Expression <Func <TypeReqEntity, bool> > >())).Returns(testTypeReqEntityUpd);
            unitOfWork.Setup(r => r.Save());

            typeReqLogic.Update(testTypeReqEntity);

            var result = typeReqLogic.GetById(testTypeReqEntityUpd.Id);

            typeReqRepository.VerifyAll();
            Assert.IsNotNull(result);
            Assert.AreEqual(testTypeReqEntityUpd.Name, result.Name);
        }