public ActionResult <Author> Create([FromBody] Author newAuthor) { try { return(Ok(_as.Create(newAuthor))); } catch (Exception e) { return(BadRequest(e.Message)); } }
public void Create_ExistsAuthor_ShouldThrownAuthorDublicateException() { var dto = new AuthorDto() { Lastname = DefaultData.Authors.Flenagan.Lastname, Firstname = DefaultData.Authors.Flenagan.Firstname, Middlename = DefaultData.Authors.Flenagan.Middlename, }; Assert.Throws <AuthorDublicateException>(async() => await AuthorsService.Create(dto)); }
public ActionResult <Author> Create([FromBody] Author newAuthor) { try { // req.user.sub || req.userInfo.sub string userId = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value; // NOTE DONT TRUST THE USER TO TELL YOU WHO THEY ARE!!!! newAuthor.Name = userId; return(Ok(_as.Create(newAuthor))); } catch (Exception e) { return(BadRequest(e.Message)); } }
public async Task Create_ShouldCreated() { Assert.That((await AuthorsService.GetAll(It.IsAny <PagingParameterModel>())).Count(), Is.EqualTo(Authors.Count)); var oldCount = Authors.Count; var id = Random.Next(int.MaxValue); var authorDto = new AuthorDto() { Id = id, Lastname = "Rotenberg", Firstname = "Arkadii", Middlename = "Bar" }; await AuthorsService.Create(authorDto); Assert.That(Authors.Count, Is.EqualTo(oldCount + 1)); Assert.That(await AuthorsService.Get(authorDto.Id), Is.Not.Null); }
public ActionResult Create(AuthorViewModel authorViewModel) { authorsService.Create(authorViewModel); return(Json(new[] { authorViewModel })); }
public void Create_InvalidDto_ShouldThrownAuthorIncorrectException() { var dto = new AuthorDto(); Assert.Throws <AuthorIncorrectException>(async() => await AuthorsService.Create(dto)); }