public void TestCreateAuthorCommand() { var mediator = new Mock <IMediator>(); var authorRepo = new Mock <IAuthorRepo>(); authorRepo.Setup(x => x.Save(It.IsAny <Author>(), It.IsAny <CancellationToken>())).Returns(Task.FromResult(new Author() { Id = Guid.NewGuid(), FirstName = "Firstname", LastName = "Lastname" })); var createCommand = new CreateAuthorCommand() { FirstName = "Firstname", LastName = "Lastname" }; var handler = new CreateAuthorCommand.Handler(authorRepo.Object, mediator.Object); Assert.DoesNotThrowAsync(() => handler.Handle(createCommand, new CancellationToken())); }
public async Task <Author> CreateAuthorAsync(AuthorInput authorInput) { using var scope = _serviceProvider.CreateScope(); var logger = scope.ServiceProvider.GetRequiredService <ILogger <AuthorMutation> >(); var mediator = scope.ServiceProvider.GetRequiredService <IMediator>(); logger.LogInformation("Begin processing mutation with input ({@Input}).", authorInput); var createAuthorCommand = new CreateAuthorCommand(authorInput.FirstName, authorInput.MiddleName, authorInput.LastName, authorInput.BookIds); logger.LogDebug("Sending command {CommandName} ({@Command})", nameof(CreateAuthorCommand), createAuthorCommand); var author = await mediator.Send(createAuthorCommand); logger.LogDebug("Converting entity ({@AggregateRoot}) to response type {ResponseType}.", author, nameof(Author)); var result = author.AsAuthorType(); logger.LogDebug("Returning mutation result ({@Result})", result); return(result); }
public async Task CreatesANewAuthor() { var newAuthor = new CreateAuthorCommand() { Name = "James Eastham", PluralsightUrl = "https://app.pluralsight.com", TwitterAlias = "jeasthamdev", }; var lastAuthor = SeedData.Authors().Last(); var response = await _client.PostAsync(CreateAuthorCommand.ROUTE, new StringContent(JsonConvert.SerializeObject(newAuthor), Encoding.UTF8, "application/json")); response.EnsureSuccessStatusCode(); var stringResponse = await response.Content.ReadAsStringAsync(); var result = JsonConvert.DeserializeObject <CreateAuthorResult>(stringResponse); Assert.NotNull(result); Assert.Equal(result.Id, lastAuthor.Id + 1); Assert.Equal(result.Name, newAuthor.Name); Assert.Equal(result.PluralsightUrl, newAuthor.PluralsightUrl); Assert.Equal(result.TwitterAlias, newAuthor.TwitterAlias); }
public async Task <IActionResult> Create([FromBody] CreateAuthorCommand command) { await Mediator.Send(command); return(NoContent()); }
public async Task <IActionResult> SignUp(RegisterViewModel model) { model = model ?? throw new ArgumentNullException(); if (ModelState.IsValid) { // Create new application user. var(result, userId, token) = await _identityService.CreateUserAsync(model.Email, model.Email, model.Password); if (result == null) { ModelState.AddModelError(string.Empty, _localizer["UserExist"]); return(View(model)); } if (result.Succeeded) { // Create command to add new author. var authorDTO = new AuthorDTO { UserId = userId, FirstName = model.FirstName, LastName = model.LastName, BirthDate = model.BirthDate, Email = model.Email }; var authorCommand = new CreateAuthorCommand { Model = authorDTO }; try { await _mediator.Send(authorCommand); } catch (RequestValidationException failures) { foreach (var error in failures.Failures) { ModelState.AddModelError(string.Empty, error.Value[0]); } return(View(model)); } // Send confirmation letter to user email. var callbackUrl = Url.Action("SignUpSucceeded", "Account", new { id = userId, token = token }, protocol: HttpContext.Request.Scheme); var homePageUrl = Url.Action("Index", "Home", null, protocol: HttpContext.Request.Scheme); var logoUrl = string.Format("{0}://{1}{2}", Request.Scheme, Request.Host, "/resources/logo-1.png"); var emailModel = new EmailViewModel { AuthorName = model.FirstName + " " + model.LastName, CallbackUrl = callbackUrl, HomePageUrl = homePageUrl, LogoUrl = logoUrl, }; var body = await _razorViewToStringRenderer.RenderViewToStringAsync("Views/Email/Email_ConfirmEmail.cshtml", emailModel); await _emailService.SendEmailAsync(model.Email, _localizer["ConfirmEmail"], body); return(View("ConfirmEmail", model)); } else { foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error); } } } return(View(model)); }
public async Task <IActionResult> Create(CreateAuthorCommand Author) { await Mediator.Send(Author); return(RedirectToAction("Index")); }
public async Task <ActionResult> Post([FromBody] CreateAuthorCommand command) { return(Ok(await Mediator.Send(command))); }
public async Task <ActionResult <int> > Create(CreateAuthorCommand command) { return(await Mediator.Send(command)); }
public async Task <IActionResult> Register(CreateAuthorCommand command) { await _mediator.Send(command); return(Ok(new { message = "Registration successful, please check your email for verification instructions" })); }
public async Task<IActionResult> CreateAuthor([FromBody] CreateAuthorCommand command) { return Ok(await _mediator.Send(command)); }
public async Task <IActionResult> CreateAuthor([FromBody] CreateAuthorCommand command) { await _mediator.Send(command, HttpContext.RequestAborted); return(Ok()); }
public Task <IdResource> CreateAuthor( [FromBody] CreateAuthorCommand command) => Mediator.Send(command);
public GenericCommandResult Create([FromBody] CreateAuthorCommand command, [FromServices] AuthorHandler handler) { _logger.LogInformation("Executing api/author to post author"); return((GenericCommandResult)handler.Handle(command)); }
public Author(CreateAuthorCommand cmd) { FirstName = cmd.FirstName; LastName = cmd.LastName; }
public CreateBooksCommand(string title, DateTime releaseDate, string iSBN, string category, CreateAuthorCommand author) { Title = title; ReleaseDate = releaseDate; ISBN = iSBN; Category = category; Author = author; }
private AuthorViewModel CreateAndReturnAuthor(CreateAuthorCommand author) { var result = this.commandService.PerformCommand(author); return(authorQueries.GetById(result.GetEntityIdentifier())); }
public async Task <ActionResult <int> > Create([FromBody] CreateAuthorCommand createAuthorCommand) { var response = await _mediator.Send(createAuthorCommand); return(Ok(response)); }
public async Task <ActionResult <int> > Create(CreateAuthorCommand command) { var response = await _mediator.Send(command); return(CreatedAtAction(nameof(Create), response)); }
public async Task <ActionResult <CreateAuthorOutputModel> > Create( CreateAuthorCommand command) => await this.Send(command);