public void ATemplateBlankObjectTest() { ATemplateViewModel MyATemplate = new ATemplateViewModel() { Id = 1 }; Assert.AreEqual(1, MyATemplate.Id); }
public void ATemplateService_Add_ThrowsCaciChallengeExceptionOnRepositoryException() { mockRepository.Setup(m => m.Insert(It.IsAny<CACI.DAL.Models.ATemplate>())).Throws<DbUpdateException>(); ATemplateService service = new ATemplateService(mockRepository.Object, mapper, mockLogger.Object); ATemplateViewModel obj = new ATemplateViewModel() { Id = 0 }; Assert.ThrowsException<CaciChallengeException>(() => service.Add(obj)); }
public void ATemplateContoller_Post() { ATemplateViewModel application = new ATemplateViewModel() { Id = 1 }; ATemplateController _controller = new ATemplateController(_mockService.Object, _logger.Object); var result = _controller.Post(application); Assert.IsNotNull(result); }
//[ValidateAntiForgeryToken] //[Authorize(Roles ="admin")] public ActionResult <ATemplateViewModel> Post([FromBody] ATemplateViewModel saveMe) // Insert { try { return(Ok(service.Add(saveMe))); } catch (Exception ex) { logger.LogError($"{this.GetType().FullName} - Failed to save: {ex}"); return(BadRequest("Failed to save")); } }
public void ATemplateService_Add() { var dao = new CACI.DAL.Models.ATemplate() { Id = 1 }; mockRepository.Setup(m => m.Insert(It.IsAny<CACI.DAL.Models.ATemplate>())).Returns(dao); ATemplateService service = new ATemplateService(mockRepository.Object, mapper, mockLogger.Object); ATemplateViewModel obj = new ATemplateViewModel() { Id = 0 }; var result = service.Add(obj); Assert.IsNotNull(result); Assert.AreEqual(1, result.Id); }
//[ValidateAntiForgeryToken] //[Authorize(Roles ="admin")] public ActionResult <ATemplateViewModel> Put(int id, [FromBody] ATemplateViewModel saveMe) // Update { try { saveMe.Id = id; return(Ok(service.Update(saveMe))); } catch (Exception ex) { logger.LogError($"{this.GetType().FullName} - Failed to save: {ex}"); return(BadRequest("Failed to save")); } }
public void ATemplateContoller_Post_ReturnsBadRequestOnException() { _mockService.Setup(m => m.Add(It.IsAny <ATemplateViewModel>())).Throws(new System.Exception("Test Exception")); ATemplateController _controller = new ATemplateController(_mockService.Object, _logger.Object); ATemplateViewModel application = new ATemplateViewModel() { Id = 1 }; var result = _controller.Post(application); Assert.IsTrue(result.Result is BadRequestObjectResult); }
public ATemplateViewModel Update(ATemplateViewModel saveMe) // Update record { try { var dao = mapper.Map <CACI.DAL.Models.ATemplate>(saveMe); var result = repository.Update(dao); return(mapper.Map <ATemplateViewModel>(result)); } catch (Exception ex) { var message = $"{this.GetType().FullName} - Failed to save the item: {ex}"; logger.LogError(message, ex); throw new CaciChallengeException(message, ex); } }