public async Task AddAuthorAsync_ShouldReturnExpectedAuthorWithId() { // given (arrange) Filler <CreateAuthorDto> authorFiller = new Filler <CreateAuthorDto>(); authorFiller.Setup() .OnProperty(x => x.ContactEmail) .Use(new EmailAddresses(".com")) .OnProperty(x => x.ContactPhoneNumber) .Use("555-555-5555"); CreateAuthorDto authorDtoToAdd = authorFiller.Create(); Author authorToAdd = this.mapper.Map <Author>(authorDtoToAdd); Author databaseAuthor = this.mapper.Map <Author>(authorToAdd); databaseAuthor.Id = 1; databaseAuthor.DateCreated = databaseAuthor.DateUpdated = DateTime.UtcNow; this.appDbContextMock .Setup(db => db.CreateAuthorAsync(It.IsAny <Author>())) .ReturnsAsync(databaseAuthor); // when (act) var actualAuthor = await subject.AddAuthorAsync(authorDtoToAdd); // then (assert) actualAuthor.Should().BeEquivalentTo(databaseAuthor); appDbContextMock.Verify(db => db.CreateAuthorAsync(It.IsAny <Author>()), Times.Once); appDbContextMock.VerifyNoOtherCalls(); }
public async Task <ActionResult> AddAuthor(CreateAuthorRequest author) { if (author == null) { return(BadRequest()); } await _authorService.AddAuthorAsync(author); return(Ok(author)); }
public async Task <IActionResult> AddAuthor([FromBody] AuthorCreation model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var id = await _service.AddAuthorAsync(model); return(CreatedAtRoute("GetAuthor", new { id = id }, await _service.GetAuthorAsync(id))); }
public async Task <ActionResult> Create(AuthorInputViewModel vm) { if (ModelState.IsValid) { var addedA = await _authorService.AddAuthorAsync(vm); TempData["message"] = $"Author \"{addedA.Name}\" was added."; return(RedirectToAction(nameof(Create))); } return(View(vm)); }
private async void AddAuthor() { var author = new Author() { Name = Name, PenName = PenName }; await _service.AddAuthorAsync(author); Name = ""; Messenger.Default.Send <Author>(author); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } await authorService.AddAuthorAsync(AuthorDto); return(RedirectToPage("./Index")); }
public async Task <IActionResult> CreateAuthor([FromBody] AuthorDto author) { try { if (!ModelState.IsValid) { return(BadRequest("Invalid model object")); } await _authorService.AddAuthorAsync(author); return(CreatedAtRoute("CategoryById", new { id = author.Id }, author)); } catch (Exception ex) { return(StatusCode(500, ex.Message)); } }
public async Task <IActionResult> Post(AddAuthorRequest request) { var result = await _artistService.AddAuthorAsync(request); return(CreatedAtAction(nameof(GetById), new { id = result.AuthorId }, null)); }
public async Task <ActionResult> AddAsync([FromBody] AuthorCreationDto authorDto) { await _authorService.AddAuthorAsync().ConfigureAwait(false); return(Ok()); }
public async Task <IActionResult> AddAuthor([FromForm] AddAuthorDto addAuthor) { return(Ok(await _authorService.AddAuthorAsync(addAuthor))); }
public async Task <IActionResult> Post([FromBody] AuthorDTO author) // DTO should move to infra and should handle book creation { await _authorService.AddAuthorAsync(author.Name, author.Surname, author.Books, author.ActiveYear); return(Created($"api/authors/{author.Name}", null)); }