Esempio n. 1
0
        public void Initialize()
        {
            var status1 = new Status {
                ID = 1, groupId = 1, body = "status1", userId = "User1"
            };
            var status2 = new Status {
                ID = 2, groupId = 1, body = "status2", userId = "User1"
            };
            var status3 = new Status {
                ID = 3, groupId = 2, body = "status3", userId = "User2"
            };
            List <Status> statuses = new List <Status> {
                status1, status2, status3
            };

            var group1 = new Group {
                ID = 1, name = "group1", ownerId = "User1"
            };
            var group2 = new Group {
                ID = 2, name = "group2", ownerId = "User2"
            };
            var group3 = new Group {
                ID = 2, name = "group2", ownerId = "User2"
            };

            var groupProfileFK1 = new GroupProfileFK {
                ID = 1, groupID = 1, profileID = "User1"
            };
            var groupProfileFK2 = new GroupProfileFK {
                ID = 2, groupID = 2, profileID = "User1"
            };
            var userRating = new UserStatusRating {
                ID = 1, rating = 2, statusId = 1, userId = "User1"
            };

            foreach (var item in statuses)
            {
                mockDb.userStatuses.Add(item);
            }
            mockDb.groups.Add(group1);
            mockDb.groups.Add(group2);
            mockDb.groups.Add(group3);
            mockDb.groupProfileFks.Add(groupProfileFK1);
            mockDb.groupProfileFks.Add(groupProfileFK2);
            mockDb.userStatusRating.Add(userRating);

            service = new GroupService(mockDb);
        }
Esempio n. 2
0
        public void Initialize()
        {
            var profileEntity = new Profile();

            profileEntity.name          = "Carlos Ragnar Kárason";
            profileEntity.userID        = "CarlosUserID";
            profileEntity.profilePicUrl = "picture.jpg";

            mockDb.profiles.Add(profileEntity);


            var status1 = new Status {
                ID = 1, groupId = null, body = "Status 1", userId = "CarlosUserID"
            };
            var status2 = new Status {
                ID = 2, groupId = null, body = "Status 2", userId = "CarlosUserID"
            };
            var status3 = new Status {
                ID = 3, groupId = null, body = "Status 3", userId = "CarlosUserID"
            };
            List <Status> statuses = new List <Status> {
                status1, status2, status3
            };

            foreach (var item in statuses)
            {
                mockDb.userStatuses.Add(item);
            }

            UserStatusRating rating1 = new UserStatusRating {
                ID = 1, userId = "CarlosUserID", statusId = 1, rating = 1
            };
            UserStatusRating rating2 = new UserStatusRating {
                ID = 2, userId = "CarlosUserID", statusId = 2, rating = 2
            };

            List <UserStatusRating> myRatings = new List <UserStatusRating> {
                rating1, rating2
            };

            foreach (var item in myRatings)
            {
                mockDb.userStatusRating.Add(item);
            }

            service = new ProfileService(mockDb);
        }
Esempio n. 3
0
        public void UpdateRatingToUpvoteCurrentDownvote()
        {
            // Arrange
            var userRating = new UserStatusRating {
                ID = 1, rating = (int)Ratings.Upvote, statusId = 1, userId = "User1"
            };
            var numberOfUpvotes   = 1;
            var numberOfDownvotes = -1;
            var currentRating     = (int)Ratings.Downvote;

            // Act
            service.UpdateRating("User1", currentRating, "up", 1);

            // Assert
            Assert.AreEqual(userRating.rating, mockDb.userStatusRating.ElementAt(0).rating);
            Assert.AreEqual(numberOfUpvotes, mockDb.userStatuses.ElementAt(0).upvotes);
            Assert.AreEqual(numberOfDownvotes, mockDb.userStatuses.ElementAt(0).downvotes);
        }
Esempio n. 4
0
        public void UpdateRatingUserHasNotRated()
        {
            // Arrange
            var userRating = new UserStatusRating {
                ID = 5, rating = (int)Ratings.Upvote, statusId = 3, userId = "User1"
            };
            var numberOfUpvotes   = 1;
            var numberOfDownvotes = 0;
            var currentRating     = (int)Ratings.Neutral;
            var numberOfRatings   = 5;

            // Act
            service.UpdateRating("User1", currentRating, "up", 3);

            // Assert
            Assert.AreEqual(userRating.rating, mockDb.userStatusRating.ElementAt(4).rating);
            Assert.AreEqual(numberOfUpvotes, mockDb.userStatuses.ElementAt(2).upvotes);
            Assert.AreEqual(numberOfDownvotes, mockDb.userStatuses.ElementAt(2).downvotes);
            Assert.AreEqual(numberOfRatings, mockDb.userStatusRating.Count());
        }
Esempio n. 5
0
        public void Initialize()
        {
            var status1 = new Status {
                ID = 1, groupId = null, body = "status1", userId = "User1"
            };
            var status2 = new Status {
                ID = 2, groupId = null, body = "status2", userId = "User1"
            };
            var status3 = new Status {
                ID = 3, groupId = 1, body = "status3", userId = "User2"
            };
            var status4 = new Status {
                ID = 4, groupId = null, body = "status4", userId = "User3"
            };
            List <Status> statuses = new List <Status> {
                status1, status2, status3, status4
            };

            foreach (var item in statuses)
            {
                mockDb.userStatuses.Add(item);
            }
            var stalker1 = new Stalking {
                ID = 1, userId = "User1", stalkedId = "User1"
            };
            var stalker2 = new Stalking {
                ID = 2, userId = "User2", stalkedId = "User2"
            };
            var stalker3 = new Stalking {
                ID = 3, userId = "User3", stalkedId = "User3"
            };
            var stalker4 = new Stalking {
                ID = 4, userId = "User4", stalkedId = "User4"
            };
            var stalker5 = new Stalking {
                ID = 5, userId = "User1", stalkedId = "User3"
            };
            var stalker6 = new Stalking {
                ID = 6, userId = "User2", stalkedId = "User3"
            };
            var stalker7 = new Stalking {
                ID = 7, userId = "User2", stalkedId = "User1"
            };
            var stalker8 = new Stalking {
                ID = 8, userId = "User2", stalkedId = "User4"
            };
            var stalker9 = new Stalking {
                ID = 9, userId = "User3", stalkedId = "User4"
            };
            var stalker10 = new Stalking {
                ID = 10, userId = "User4", stalkedId = "User1"
            };
            List <Stalking> stalkings = new List <Stalking> {
                stalker1, stalker2, stalker3, stalker4, stalker5, stalker6, stalker7, stalker8, stalker9, stalker10
            };

            foreach (var item in stalkings)
            {
                mockDb.stalking.Add(item);
            }
            var userRating1 = new UserStatusRating {
                ID = 1, rating = (int)Ratings.Downvote, statusId = 1, userId = "User1"
            };
            var userRating2 = new UserStatusRating {
                ID = 2, rating = (int)Ratings.Upvote, statusId = 2, userId = "User1"
            };
            var userRating3 = new UserStatusRating {
                ID = 3, rating = (int)Ratings.Neutral, statusId = 1, userId = "User2"
            };
            var userRating4 = new UserStatusRating {
                ID = 4, rating = (int)Ratings.Downvote, statusId = 1, userId = "User3"
            };
            List <UserStatusRating> ratings = new List <UserStatusRating> {
                userRating1, userRating2, userRating3, userRating4
            };

            foreach (var item in ratings)
            {
                mockDb.userStatusRating.Add(item);
            }

            service = new NewsfeedService(mockDb);
        }
Esempio n. 6
0
        public void UpdateRating(string userId, int currRating, string arrowDirection, int statusId)
        {
            try
            {
                // Get users current rating of the status.
                // Return null if user hasn't rated the status.
                var myRating = (from r in db.userStatusRating
                                where r.userId == userId
                                where r.statusId == statusId
                                select r).SingleOrDefault();
                var result = new UserStatusRating();
                var status = (from s in db.userStatuses
                              where s.ID == statusId
                              select s).SingleOrDefault();

                if (arrowDirection == "up" && currRating != (int)Ratings.Upvote)
                {
                    result.rating   = (int)Ratings.Upvote;
                    result.statusId = statusId;
                    result.userId   = userId;
                    if (currRating == (int)Ratings.Downvote)
                    {
                        status.downvotes--;
                    }
                    status.upvotes++;
                }
                else if (arrowDirection == "down" && currRating != (int)Ratings.Downvote)
                {
                    result.rating   = (int)Ratings.Downvote;
                    result.statusId = statusId;
                    result.userId   = userId;
                    if (currRating == (int)Ratings.Upvote)
                    {
                        status.upvotes--;
                    }
                    status.downvotes++;
                }
                else
                {
                    result.rating   = (int)Ratings.Neutral;
                    result.statusId = statusId;
                    result.userId   = userId;
                    if (arrowDirection == "up")
                    {
                        status.upvotes--;
                    }
                    else
                    {
                        status.downvotes--;
                    }
                }


                // Update the rating if the user had already rated the status.
                // Else add the rating to userStatusRating.
                if (myRating != null)
                {
                    myRating.rating = result.rating;
                }
                else
                {
                    db.userStatusRating.Add(result);
                }

                db.SaveChanges();
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.Write(ex.Message + Environment.NewLine + "Location of error: " + ex.Source +
                                               Environment.NewLine + "StackTrace: " + Environment.NewLine + ex.StackTrace +
                                               Environment.NewLine + "Time : " + DateTime.Now + Environment.NewLine);
            }
        }