Exemple #1
0
        public async Task ReturnsSuccessStatusCode()
        {
            //Arrage
            var client  = _factory.GetAnonymousClient();
            var command = new CreateAppUserCommand()
            {
                Email    = "*****@*****.**",
                UserName = "******",
                Password = "******"
            };
            var content = Utilities.GetRequestContent(command);

            //Act
            var response = await client.PostAsync($"api/user/signup", content);

            //Assert
            response.EnsureSuccessStatusCode();

            var appUsers = _identityDbContext.Users.Where(user => user.Email == command.Email && user.UserName == command.UserName).ToArray();

            Assert.Single(appUsers);

            var profiles = _applicationDbContext.UserProfiles.Where(userProfile => userProfile.Id == appUsers[0].Id).ToArray();

            Assert.Single(profiles);
        }
Exemple #2
0
        public async Task <IActionResult> SignUp([FromBody] CreateAppUserCommand request)
        {
            //The user is created in two iterations: creating identity data and creating a user profile with public data
            var newAppUserId = await Mediator.Send(request);

            await Mediator.Send(new CreateUserProfileCommand { Id = newAppUserId });

            await _userManagerService.SendConfirmationEmail(request.Email, OriginUrl);

            return(Created());
        }
Exemple #3
0
        public void ThrowException_WhenUserNameOrEmailAlreadyTaken(string userName, string email)
        {
            var userManager = MockHelper.MockUserManager <AppUser>().Object;
            var command     = new CreateAppUserCommand()
            {
                UserName = userName, Email = email
            };
            var handler = new CreateAppUserCommand.CreateAppUserCommandHandler(userManager, _identityContext);

            Assert.ThrowsAsync <NotCreatedException>(() => handler.Handle(command, CancellationToken.None));
        }
Exemple #4
0
        public void ReturnedUserIdValueNotNull(string userName, string email)
        {
            var mockMngr = MockHelper.MockUserManager <AppUser>();

            mockMngr.Setup(um => um.CreateAsync(It.IsAny <AppUser>(), It.IsAny <string>())).ReturnsAsync(IdentityResult.Success);
            var command = new CreateAppUserCommand()
            {
                UserName = userName, Email = email, Password = "******"
            };
            var handler = new CreateAppUserCommand.CreateAppUserCommandHandler(mockMngr.Object, _identityContext);

            var task = handler.Handle(command, CancellationToken.None);

            Assert.NotNull(task.Result);
        }
Exemple #5
0
        public async Task ReturnsUnprocessableEntityStatusCode_WhenDataIsNotValid(string email, string userName, string password)
        {
            var client  = _factory.GetAnonymousClient();
            var command = new CreateAppUserCommand()
            {
                Email    = email,
                UserName = userName,
                Password = password
            };
            var content = Utilities.GetRequestContent(command);

            var response = await client.PostAsync($"api/user/signup", content);

            Assert.Equal(HttpStatusCode.UnprocessableEntity, response.StatusCode);
        }
Exemple #6
0
        public async Task ReturnsBadRequestStatusCode_WhenEmailOrUsernameAlreadyTaken(string email, string userName, string password)
        {
            var client  = _factory.GetAnonymousClient();
            var command = new CreateAppUserCommand()
            {
                Email    = email,
                UserName = userName,
                Password = password
            };
            var content = Utilities.GetRequestContent(command);

            var response = await client.PostAsync($"api/user/signup", content);

            Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
        }
        public async Task <IActionResult> Create(CreateAppUserCommand vm)
        {
            vm.BaseUrl = new Uri(new Uri(Request.Scheme + "://" + Request.Host.Value), "Identity/Account/ConfirmEmail").ToString();
            IdentityResult result = await _mediator.Send(vm);

            if (result.Succeeded)
            {
                _logger.LogInformation($"Created new account for {vm.Username}");
                return(RedirectToAction(nameof(Index)).WithSuccess($"Created new user {vm.Username}"));
            }
            AddErrors(result);

            // If we got this far, something failed, redisplay form
            ViewData["UserRole"] = new SelectList(SecurityConstants.GetRoles());
            return(View(vm));
        }
        public async Task <IActionResult> Create(CreateAppUserCommand vm)
        {
            vm.BaseUrl = new Uri(new Uri(Request.Scheme + "://" + Request.Host), "roster/Identity/Account/ConfirmEmail").ToString();
            IdentityResult result = await _mediator.Send(vm);

            if (result.Succeeded)
            {
                _logger.LogInformation($"Created new account for {vm.Username}");
                return(RedirectToAction(nameof(Index)).WithSuccess($"Created new user {vm.Username}"));
            }
            AddErrors(result);

            // If we got this far, something failed, redisplay form
            ViewData["GenderId"]     = new SelectList(await _mediator.Send(new GetGendersQuery()), "Id", "Name");
            ViewData["ShiftGroupId"] = new SelectList(await _mediator.Send(new GetShiftGroupsQuery()), "Id", "Name");
            ViewData["ShiftRoleId"]  = new SelectList(await _mediator.Send(new GetShiftRolesQuery()), "Id", "RoleName");
            return(View(vm));
        }