Ejemplo n.º 1
0
        public void AddNewAdditionalFieldTextTypeTest()
        {
            AFRepository.SetupSequence(r => r.Exists(It.IsAny <Expression <Func <AdditionalFieldEntity, bool> > >())).Returns(false).Returns(true).Returns(true);
            typeRepository.Setup(t => t.Exists(It.IsAny <Expression <Func <TypeReqEntity, bool> > >())).Returns(true);
            AFRepository.Setup(u => u.Add(It.IsAny <AdditionalFieldEntity>())).Verifiable();
            typeRepository.Setup(t => t.FirstOrDefault(It.IsAny <Expression <Func <TypeReqEntity, bool> > >())).Returns(testTypeReqEntity);
            AFRepository.Setup(r => r.FirstOrDefault(It.IsAny <Expression <Func <AdditionalFieldEntity, bool> > >())).Returns(testAFEntity);
            unitOfWork.Setup(r => r.Save());
            AFRepository.Setup(r => r.FirstOrDefault(It.IsAny <Expression <Func <AdditionalFieldEntity, bool> > >())).Returns(testAFEntity);

            aFLogic.Add(testAFEntity);
            var result = aFLogic.GetById(testAFEntity.Id);

            AFRepository.VerifyAll();
            Assert.IsNotNull(result);
            Assert.AreEqual(testAFEntity.Id, result.Id);
            Assert.AreEqual(testAFEntity.Name, result.Name);
        }
Ejemplo n.º 2
0
        public IActionResult Post([FromBody] AdditionalFieldModelIn additionalFieldIn)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var additionalField = mapper.Map <AdditionalFieldModelIn, AdditionalFieldEntity>(additionalFieldIn);

                    var id = additionalFieldLogic.Add(additionalField);
                    var addedAdditionalField    = additionalFieldLogic.GetById(id);
                    var addedAdditionalFieldOut = mapper.Map <AdditionalFieldEntity, AdditionalFieldModelOut>(addedAdditionalField);
                    return(Created("Posted succesfully", addedAdditionalFieldOut));
                }
                catch (Exception ex)
                {
                    return(BadRequest(ex.Message));
                }
            }
            else
            {
                return(BadRequest(ModelState));
            }
        }