public ActionResult CreateRecord(int id, RecordCreateViewModel model) { if (ModelState.IsValid) { var documentTemplateFilePath = Server.MapPath(this.documents.GetById(model.DocumentId).FilePath); var fileExtension = System.IO.Path.GetExtension(documentTemplateFilePath); var newRecord = this.records.Create(model.Title, model.Description, model.DateCreated, model.FinishingDate, model.Status, model.StatusDate, model.DocumentId, id, fileExtension); this.CreateFileOfRecord(this.documents.GetById(model.DocumentId).FilePath, newRecord.RecordFiles.ToList()[newRecord.RecordFiles.ToList().Count - 1].Path); return RedirectToAction("Manage", new { id = id }); } ViewBag.Documents = this.GetDocumentsSelectListItems(); return View(model); }
public void CreateRecordShouldReturnPropperResultIfModelStateIsInvalid() { var areasFake = new Mock<IAreasServices>(); areasFake.Setup(a => a.GetByUserId(It.IsAny<string>())).Returns(areas); var recordsFake = new Mock<IRecordsServices>(); recordsFake.Setup(x => x.GetByAreaId(It.IsAny<int>())).Returns(this.records); var documentsFake = new Mock<IDocumentsServices>().Object; var usersFake = new Mock<IUsersServices>().Object; var controller = new AreasController(areasFake.Object, recordsFake.Object, documentsFake, usersFake); controller.ModelState.AddModelError("Invalid model", "Error message"); Mapper.CreateMap<Area, AreaShortViewModel>(); Mapper.CreateMap<Area, AreaListViewModel>(); Mapper.CreateMap<User, UserShortViewModel>(); Mapper.CreateMap<Record, RecordListViewModel>(); ViewResult viewResult = controller.Index() as ViewResult; var invalidViewModel = new RecordCreateViewModel(); controller.WithCallTo(c => c.CreateRecord(1, invalidViewModel)) .ShouldRenderView(string.Empty) .WithModel<RecordCreateViewModel>(x => Assert.AreSame(invalidViewModel, x)); }