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);
        }
예제 #2
0
        public void FriendRequest(string friend)
        {
            string         me      = HttpContext.Session.GetString("User_Login");
            FriendsService service = new FriendsService(services);

            service.AddFriend(me, friend);
        }
예제 #3
0
        public void CreateFriendAndSendNotification()
        {
            var notificationService = new Mock <INotificationService>();
            var friendsRepository   = new Mock <IFriendRepository>();
            var friendsService      = new FriendsService(notificationService.Object, friendsRepository.Object);

            friendsService.AddFriend(Guid.NewGuid(), "", "", "");

            friendsRepository.Verify(f => f.Create(It.IsAny <Guid>(), It.IsAny <string>()));
            notificationService.Verify(n => n.SendNotification(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()));
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            Guid   currentUserId    = (Guid)Membership.GetUser().ProviderUserKey;
            string currentUserName  = MyProfile.CurrentUser.Name;
            string currentUserEmail = Membership.GetUser().Email;
            string friendEmail      = Request.QueryString["email"];
            var    friendsService   = new FriendsService();

            friendsService.AddFriend(currentUserId, currentUserEmail, currentUserName, friendEmail);

            SuccessLabel.Text = "Added friend: " + Request.QueryString["email"];
        }
        public async Task Throw_AddYourSelfAsFriendException_WhenAddYourSelfAsFriend()
        {
            Guid   currentUserId    = Guid.NewGuid();
            string currentUserEmail = "*****@*****.**";
            string friendEmail      = "*****@*****.**";

            var friendsRepositoryMock = new Mock <IFriendRepository>();
            var profileRepositoryMock = new Mock <IProfileRepository>();

            var friendService = new FriendsService(friendsRepositoryMock.Object, profileRepositoryMock.Object);

            await Assert.ThrowsExceptionAsync <AddYourSelfAsFriendException>(() => friendService.AddFriend(currentUserId, currentUserEmail, friendEmail));
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            string currentUserEmail = Membership.GetUser().Email;
            string currentUserName  = MyProfile.CurrentUser.Name;
            string friendEmail      = Request.QueryString["email"];
            Guid   currentUserId    = (Guid)Membership.GetUser().ProviderUserKey;

            //var friendsService = new FriendsService();
            var friendsService = new FriendsService(new EfFriendRepository(), new NotificationService(new EfQueryUsersByEmail(), new DebugEmailSender()));

            friendsService.AddFriend(currentUserId, currentUserEmail, currentUserName, friendEmail);

            SuccessLabel.Text = "Added Friend: " + friendEmail;
        }
        protected void SaveButton_Click(object sender, EventArgs e)
        {
            string currentUserEmail = Membership.GetUser().Email;
            string currentUserName  = MyProfile.CurrentUser.Name;
            string friendEmail      = EmailTextBox.Text;
            Guid   currentUserId    = (Guid)Membership.GetUser().ProviderUserKey;

            //var friendsService = new FriendsService();

            var friendsService = new FriendsService(new EfFriendRepository(), new NotificationService(new EfQueryUsersByEmail(), new DebugEmailSender()));

            friendsService.AddFriend(currentUserId, currentUserEmail, currentUserName, friendEmail);

            Response.Redirect("Friends.aspx");
        }
        public async Task Throw_NoSuchUserException_WhenAddFriendCantFindUserToAddFriend()
        {
            Guid   currentUserId    = Guid.NewGuid();
            string currentUserEmail = "*****@*****.**";
            string friendEmail      = "*****@*****.**";

            var friendsRepositoryMock = new Mock <IFriendRepository>();

            friendsRepositoryMock.Setup(f => f.ListFriendsOfUser(currentUserId)).Returns(new List <Friend>());

            var profileRepositoryMock = new Mock <IProfileRepository>();

            profileRepositoryMock.Setup(f => f.GetUser(currentUserId)).ReturnsAsync(default(PluralSightBookIdentityUser));

            var friendService = new FriendsService(friendsRepositoryMock.Object, profileRepositoryMock.Object);

            await Assert.ThrowsExceptionAsync <NoSuchUserException>(() => friendService.AddFriend(currentUserId, currentUserEmail, friendEmail));
        }
예제 #9
0
        public JsonResult AddFriend(int firstuserId, int secondUserId)
        {
            var st = _friendsService.AddFriend(firstuserId, secondUserId);

            return(Json(st, JsonRequestBehavior.AllowGet));
        }
        public JsonResult RespondToFriendRequest()
        {
            if (Request.Form["response"] != null && (Request.Form["initiatorProfileId"] != null || Request.Form["notificationId"] != null))
            {
                var           currentUserId  = User.Identity.GetUserId();
                var           currentProfile = _userProfileService.GetUserProfileByUserId(new Guid(currentUserId));
                FriendRequest friendRequest  = null;
                if ((Request.Form["initiatorProfileId"] == null || Request.Form["initiatorProfileId"] == "") && Request.Form["notificationId"] != null)
                {
                    //we get the friend request id from the notification
                    if (Int32.TryParse(Request.Form["notificationId"], out var notifId))
                    {
                        var notification = _notificationService.GetNotification(notifId);
                        if (Int32.TryParse(notification.EntityId, out var frId))
                        {
                            friendRequest = _friendRequestService.GetFriendRequest(frId);
                        }
                        else
                        {
                            return(Json(new { Message = "invalid friend request id" }));
                        }
                    }
                    else
                    {
                        return(Json(new { Message = "invalid notification id" }));
                    }
                }
                else
                {
                    friendRequest = _friendRequestService.CheckIfFriendRequestExists(new Guid(Request.Form["initiatorProfileId"]), currentProfile.Id);
                }
                if (friendRequest != null)
                {
                    var initiatorProfileId = friendRequest.InitiatorUserProfileId;
                    if (!short.TryParse(Request.Form["response"], out var response))
                    {
                        response = 0;
                    }

                    if (response == 1 || response == 2)
                    {
                        //we have a valid response
                        _friendRequestService.MarkFriendRequestAsUsed(friendRequest.Id, response);
                        if (Request.Form["notificationId"] != null)
                        {
                            // in case this request comes from a notification
                            _notificationService.MarkNotificationAsSeen(Request.Form["notificationId"]);
                        }

                        if (response == 1)
                        {
                            //friend request accepted , add user profile as friend
                            _friendsService.AddFriend(currentProfile.Id, initiatorProfileId);
                            return(Json(new { Message = "friend added" }));
                        }
                        else
                        {
                            return(Json(new { Message = "friend request denied" }));
                        }
                    }
                    else
                    {
                        return(Json(new { Message = "invalid response" }));
                    }
                }
                else
                {
                    return(Json(new { Message = "no friend request found" }));
                }
            }
            else
            {
                return(Json(new { Message = "missing response" }));
            }
        }
        public async Task Throw_AlreadyFriendWithThisUserException_WhenAddExistingFriend()
        {
            Guid   currentUserId    = Guid.NewGuid();
            string currentUserEmail = "*****@*****.**";
            string friendEmail      = "*****@*****.**";

            var friendsRepositoryMock = new Mock <IFriendRepository>();

            friendsRepositoryMock.Setup(f => f.ListFriendsOfUser(currentUserId)).Returns(new List <Friend>()
            {
                new Friend()
                {
                    Email = friendEmail
                }
            });

            var profileRepositoryMock = new Mock <IProfileRepository>();

            var friendService = new FriendsService(friendsRepositoryMock.Object, profileRepositoryMock.Object);

            await Assert.ThrowsExceptionAsync <AlreadyFriendWithThisUserException>(() => friendService.AddFriend(currentUserId, currentUserEmail, friendEmail));
        }
        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));
        }