public void TestToDraftProject() { var model = new DraftProjectBindingModel { Description = "desc", Name = "name", ProgramId = 1 }; var user = new User(1); var draftProject = model.ToDraftProject(user); Assert.AreEqual(user.Id, draftProject.Audit.User.Id); Assert.AreEqual(model.Description, draftProject.Description); Assert.AreEqual(model.Name, draftProject.Name); Assert.AreEqual(model.ProgramId, draftProject.ProgramId); }
public async Task <IHttpActionResult> PostProjectAsync(DraftProjectBindingModel model) { if (ModelState.IsValid) { var currentUser = userProvider.GetCurrentUser(); var businessUser = userProvider.GetBusinessUser(currentUser); var project = await projectService.CreateAsync(model.ToDraftProject(businessUser)); await projectService.SaveChangesAsync(); var dto = await projectService.GetProjectByIdAsync(project.ProjectId); return(Ok(dto)); } else { return(BadRequest(ModelState)); } }
public void TestDescriptionMaxLength() { var project = new DraftProjectBindingModel { Name = new string('a', Project.MAX_NAME_LENGTH), Description = new string('a', Project.MAX_DESCRIPTION_LENGTH), }; var items = new Dictionary <object, object>(); var vc = new ValidationContext(project, null, items); var results = new List <ValidationResult>(); var actual = Validator.TryValidateObject(project, vc, results, true); Assert.IsTrue(actual); Assert.AreEqual(0, results.Count); project.Description = new string('a', Project.MAX_DESCRIPTION_LENGTH + 1); actual = Validator.TryValidateObject(project, vc, results, true); Assert.IsFalse(actual); Assert.AreEqual(1, results.Count); Assert.AreEqual("Description", results.First().MemberNames.First()); }