Пример #1
0
 public ActionResult <Author> Create([FromBody] Author newAuthor)
 {
     try
     {
         return(Ok(_as.Create(newAuthor)));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
Пример #2
0
        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));
        }
Пример #3
0
 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));
     }
 }
Пример #4
0
        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);
        }
Пример #5
0
 public ActionResult Create(AuthorViewModel authorViewModel)
 {
     authorsService.Create(authorViewModel);
     return(Json(new[] { authorViewModel }));
 }
Пример #6
0
        public void Create_InvalidDto_ShouldThrownAuthorIncorrectException()
        {
            var dto = new AuthorDto();

            Assert.Throws <AuthorIncorrectException>(async() => await AuthorsService.Create(dto));
        }