public ActionResult Create(DocumentType documentType) { if (ModelState.IsValid) { _service.Create(documentType); return(RedirectToAction("Index")); } return(View(documentType)); }
public void DocumentTypeService_CheckInsert_ThrowNameException() { // Arrange var mock = new Mock <IDocumentTypeRepository>(); mock.Setup(repo => repo.Create(new DocumentTypeEntity())) .Returns(() => Task.CompletedTask); var service = new DocumentTypeService(mock.Object); // Act var ex = Assert.ThrowsAnyAsync <NameException>(() => service.Create(new DocumentType())); // Assert Assert.Equal("The DocumentType have not empty or null name.", ex.Result.Message); }
public void DocumentTypeService_CheckInsert_Created() { // Arrange var mock = new Mock <IDocumentTypeRepository>(); mock.Setup(repo => repo.Create(StubsObjects.DocumentType.ToEntity())) .Returns(() => Task.CompletedTask); var service = new DocumentTypeService(mock.Object); // Act var result = service.Create(StubsObjects.DocumentType).Result; // Assert Assert.Equal(StatusCode.Created, result); }
// POST: api/DocumentType public IHttpActionResult Post([FromBody] DocumentType model) { _service.Create(model); return(Ok(model)); }