public async Task <IActionResult> CreateUserProfile([FromBody] CreateUserProfileRequest request) { var createUserProfileCommand = new CreateUserProfileCommand(request); var result = await mediator.Send(createUserProfileCommand); return(StatusCode((int)result.Code, result.Value)); }
public async Task <IActionResult> CreateAsync(CreateUserProfileCommand command) { var userid = HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); command.UserId = Guid.Parse(userid); var response = await _mediator.Send(command); return(response.Success ? new CreatedAtRouteResult(new { command.UserId }, response) : BadRequest(response)); }
public void UserProfileGuaranteedCreatedInSingleInstance() { var command = new CreateUserProfileCommand() { Id = "11111111-1111-1111-1111-111111111111" }; var handler = new CreateUserProfileCommand.CreateUserProfileCommandHandler(_applicationDbContext); handler.Handle(command, CancellationToken.None).Wait(); var userProfiles = _applicationDbContext.UserProfiles.Where(up => up.Id == command.Id).ToArray(); Assert.Single(userProfiles); }
public void ProfileImageEmpty() { var userprofile = new Mock <IUserProfileRepository>(); userprofile.Setup(repository => repository.GetAsync(_guid, CancellationToken.None)).ReturnsAsync(new UserProfileAggregate(Guid.NewGuid(), "sup", "hey", "https://upload.wikimedia.org/wikipedia/commons/thumb/b/b6/Image_created_with_a_mobile_phone.png/1200px-Image_created_with_a_mobile_phone.png")); var validator = new CreateUserProfileCommandValidator(userprofile.Object); CreateUserProfileCommand model = new CreateUserProfileCommand { UserId = Guid.NewGuid(), UserDisplayName = "heyehey", UserProfileDescription = "hey", UserProfileImage = "" }; var result = validator.TestValidate(model); result.ShouldNotHaveValidationErrorFor(x => x.UserId); result.ShouldNotHaveValidationErrorFor(x => x.UserDisplayName); result.ShouldNotHaveValidationErrorFor(x => x.UserProfileDescription); result.ShouldHaveValidationErrorFor(x => x.UserProfileImage); }