public async Task <IActionResult> Register(RegisterViewModel model, string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { var user = new PluralSightBookIdentityUser { UserName = model.Email, Email = model.Email }; var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { _logger.LogInformation("User created a new account with password."); await _signInManager.SignInAsync(user, isPersistent : false); return(RedirectToLocal(returnUrl)); } AddError(result); } // If we got this far, something failed, redisplay form return(View(model)); }
public async Task AddFriend_When_CorrectParamettersArePassed() { Guid currentUserId = Guid.NewGuid(); string currentUserEmail = "*****@*****.**"; string friendEmail = "*****@*****.**"; var userName = "******"; var userFavoriteAuthor = "TestUserFavoriteAuthor"; var friendsRepositoryMock = new Mock <IFriendRepository>(); friendsRepositoryMock.Setup(f => f.ListFriendsOfUser(currentUserId)).Returns(new List <Friend>()); PluralSightBookIdentityUser user = new PluralSightBookIdentityUser() { Id = currentUserId.ToString(), UserName = userName, FavoriteAuthor = userFavoriteAuthor }; var profileRepositoryMock = new Mock <IProfileRepository>(); profileRepositoryMock.Setup(f => f.GetUser(currentUserId)).ReturnsAsync(user); var friendService = new FriendsService(friendsRepositoryMock.Object, profileRepositoryMock.Object); await friendService.AddFriend(currentUserId, currentUserEmail, friendEmail); friendsRepositoryMock.Verify(f => f.Create(friendEmail, currentUserId), Times.Once); }
public async Task Throw_AlreadyFriendWithThisUserException_WhenAddFriendTryToAddAlreadyFriend() { Guid currentUserId = Guid.NewGuid(); string currentUserEmail = "*****@*****.**"; string friendEmail = "*****@*****.**"; var userName = "******"; var userFavoriteAuthor = "TestUserFavoriteAuthor"; var friendsRepositoryMock = new Mock <IFriendRepository>(); friendsRepositoryMock.Setup(f => f.ListFriendsOfUser(currentUserId)).Returns(new List <Friend>()); PluralSightBookIdentityUser user = new PluralSightBookIdentityUser() { Id = currentUserId.ToString(), UserName = userName, FavoriteAuthor = userFavoriteAuthor }; user.Friends.Add(new Friend() { Email = currentUserEmail }); var profileRepositoryMock = new Mock <IProfileRepository>(); profileRepositoryMock.Setup(f => f.GetUser(currentUserId)).ReturnsAsync(user); var friendService = new FriendsService(friendsRepositoryMock.Object, profileRepositoryMock.Object); await Assert.ThrowsExceptionAsync <AlreadyFriendWithThisUserException>(() => friendService.AddFriend(currentUserId, currentUserEmail, friendEmail)); }
public async Task ReturnProfile_When_Correct_UserIdIsPassed() { Guid userId = new Guid(); var userName = "******"; var userFavoriteAuthor = "TestUserFavoriteAuthor"; PluralSightBookIdentityUser user = new PluralSightBookIdentityUser() { Id = userId.ToString(), UserName = userName, FavoriteAuthor = userFavoriteAuthor }; var profileRepositoryMoq = new Mock <IProfileRepository>(); profileRepositoryMoq.Setup(s => s.GetUser(userId)).ReturnsAsync(user); var profileService = new ProfileService(profileRepositoryMoq.Object); var profileServiceCall = await profileService.Profile(userId); Assert.AreEqual(userName, profileServiceCall.Name); Assert.AreEqual(userFavoriteAuthor, profileServiceCall.FavoriteAuthor); }