Example #1
0
 public void ShouldBeAbleToCreateUserWithProfile()
 {
     var loginid = new LoginId("*****@*****.**");
     var name = new Name("firstName", "lastName");
     var profile = new Profile("Some useful profile goes here");
     new User(loginid, name) {Profile = profile};
 }
Example #2
0
        public void DegreeOfSeparationShouldBeMinimumOfTwoPathsForTheSameFriend()
        {
            IUserRepository repository = new UserRepository(session);

            var loginid = new LoginId("*****@*****.**");
            var name = new Name("Suchit", "Puri");
            var suchit = new User(loginid, name) { Repository = repository };

            var loginid2 = new LoginId("*****@*****.**");
            var name2 = new Name("Sumit", "Gupta");
            var sumit = new User(loginid2, name2) { Repository = repository };

            var loginid3 = new LoginId("*****@*****.**");
            var name3 = new Name("Manav", "Prasad");
            var manav = new User(loginid3, name3) { Repository = repository };

            repository.Save(sumit);
            repository.Save(suchit);
            repository.Save(manav);

            suchit.InviteFriend(sumit);
            sumit.AcceptFriendInvite(suchit);
            sumit.InviteFriend(manav);
            manav.AcceptFriendInvite(sumit);

            suchit.InviteFriend(manav);
            manav.AcceptFriendInvite(suchit);

            session.Flush();
            session.Evict(suchit);
            session.Evict(sumit);
            session.Evict(manav);
            Assert.AreEqual(1, suchit.DegreeOfSeparation(manav).Count);
        }
Example #3
0
        public void UserCanPostToSubscribedGroup()
        {
            //            Mock<Group> mockGroup = new Mock<Group>();
            Post post = new Post() {Content = "Some stupid content", PostedDateTime = new DateTime(2010, 01, 01)};

            //            Group group = mockGroup.Object;
            Group group = new Group("test");

            //            mockGroup.Setup(foo => foo.post(post));
            //            mockGroup.Setup(foo => foo.Equals(It.IsAny<Group>())).Returns(true);

            LoginId loginid = new LoginId("*****@*****.**");
            string firstname = "firstName";
            string lastname = "lastName";
            Name name = new Name(firstname, lastname);

            User footballFan = new User(loginid, name);

            footballFan.Groups.Add(group);

            try
            {
                footballFan.PostToGroup(group, post);
            }
            catch (Exception ex)
            {
                Assert.Fail("Failed");
            }
        }
Example #4
0
        public void ShouldStoreUserProfileTextOfMaxLength()
        {
            var loginid = new LoginId("*****@*****.**");
            var name = new Name("firstName", "lastName");

            System.String tooBigText = getBigProfileText("../../../GetIn/MaxProfile.txt");
            var profile = new Profile(tooBigText);

            var user = new User(loginid, name) { Profile = profile };

            session.Save(user);

            IList<User> users = session.CreateQuery("from User").List<User>();
            Assert.AreEqual(profile, users.First().Profile);
        }
Example #5
0
        public void DegreeOfSeparationShouldBeOneWhenDirectFriends()
        {
            IUserRepository repository = new UserRepository(session);

            var loginid = new LoginId("*****@*****.**");
            var name = new Name("Suchit", "Puri");
            var suchit = new User(loginid, name) { Repository = repository };

            var loginid2 = new LoginId("*****@*****.**");
            var name2 = new Name("Sumit", "Gupta");
            var sumit = new User(loginid2, name2) { Repository = repository };

            repository.Save(sumit);
            repository.Save(suchit);

            suchit.InviteFriend(sumit);
            sumit.AcceptFriendInvite(suchit);
            session.Flush();
            session.Evict(suchit);
            session.Evict(sumit);
            Assert.AreEqual(1, sumit.DegreeOfSeparation(suchit).Count);
        }
Example #6
0
        public void UserCannotPostToUnsubscribedGroup()
        {
            Mock<Group> mockGroup = new Mock<Group>();
            Post post = new Post() {Content = "Some stupid content", PostedDateTime = new DateTime(2010, 01, 01)};

            Group group = mockGroup.Object;
            mockGroup.Setup(foo => foo.post(post));

            LoginId loginid = new LoginId("*****@*****.**");
            string firstname = "firstName";
            string lastname = "lastName";
            Name name = new Name(firstname, lastname);

            User footballFan = new User(loginid, name);

            try
            {
                footballFan.PostToGroup(group, post);
                Assert.Fail("Failed");
            }
            catch (Exception ex)
            {
            }
        }
Example #7
0
        public void UserShouldBeAbleToComputeSimilarityScoreWithAnotherUser()
        {
            LoginId loginId1 = new LoginId("*****@*****.**");
            string firstname1 = "firstName";
            string lastname1 = "lastName";
            Name name1 = new Name(firstname1, lastname1);

            Like[] likes1 = new Like[]
                               {
                                   new Like() {UserId = loginId1, Text = "Like1"},
                                   new Like() {UserId = loginId1, Text = "Like2"},
                                   new Like() {UserId = loginId1, Text = "Like3"},
                               };

            Dislike[] dlikes1 = new Dislike[]
                                   {
                                       new Dislike() {UserId = loginId1, Text = "Dislike1"},
                                       new Dislike() {UserId = loginId1, Text = "Dislike2"},
                                       new Dislike() {UserId = loginId1, Text = "Dislike3"},
                                   };

            User currentUser = new User(loginId1, name1)
            {
                Likes = new HashedSet<Like>(likes1),
                Dislikes = new HashedSet<Dislike>(dlikes1),
            };

            LoginId loginId2 = new LoginId("*****@*****.**");
            Like[] likes2 = new Like[]
                               {
                                   new Like() {UserId = loginId2, Text = "Like1"},
                                   new Like() {UserId = loginId2, Text = "Like2"},
                                   new Like() {UserId = loginId2, Text = "Like4"},
                               };
            Dislike[] dlikes2 = new Dislike[]
                                   {
                                       new Dislike() {UserId = loginId2, Text = "Dislike1"},
                                       new Dislike() {UserId = loginId2, Text = "Dislike4"},
                                       new Dislike() {UserId = loginId2, Text = "Dislike5"},
                                   };

            User anotherUser = new User(loginId2, new Name("anotherFirstName", "anotherLastName"))
            {
                Likes = new HashedSet<Like>(likes2),
                Dislikes = new HashedSet<Dislike>(dlikes2),
            };

            Assert.AreEqual(2.7d, currentUser.SimilarityScore(anotherUser));
        }
Example #8
0
        public void DegreeOfSeparationShouldBeThreeWhenThreeIndirectFrindsBetweenInputUsers()
        {
            IUserRepository repository = new UserRepository(session);

            var loginid = new LoginId("*****@*****.**");
            var name = new Name("Suchit", "Puri");
            var suchit = new User(loginid, name) { Repository = repository };

            var loginid2 = new LoginId("*****@*****.**");
            var name2 = new Name("Sumit", "Gupta");
            var sumit = new User(loginid2, name2) { Repository = repository };

            var loginid3 = new LoginId("*****@*****.**");
            var name3 = new Name("Manav", "Prasad");
            var manav = new User(loginid3, name3) { Repository = repository };

            var loginid4 = new LoginId("*****@*****.**");
            var name4 = new Name("Krishna", "Prasad");
            var krishna = new User(loginid4, name4) { Repository = repository };

            repository.Save(sumit);
            repository.Save(suchit);
            repository.Save(manav);
            repository.Save(krishna);

            suchit.InviteFriend(sumit);
            sumit.AcceptFriendInvite(suchit);
            sumit.InviteFriend(manav);
            manav.AcceptFriendInvite(sumit);

            manav.InviteFriend(krishna);
            krishna.AcceptFriendInvite(manav);

            session.Flush();
            session.Evict(suchit);
            session.Evict(sumit);
            session.Evict(manav);
            session.Evict(krishna);
            Assert.AreEqual(3, suchit.DegreeOfSeparation(krishna).Count);
        }
Example #9
0
        public void ShouldNotBeAbleToRegisterUserIfAlreadyExists()
        {
            LoginId loginid = new LoginId("*****@*****.**");
            Name name = new Name("firstName", "lastName");

            var likes = new[]
                               {
                                   new Like() {UserId = loginid, Text = "Like1"},
                                   new Like() {UserId = loginid, Text = "Like2"},
                                   new Like() {UserId = loginid, Text = "Like3"},
                               };

            var dislikes = new[]
                               {
                                   new Dislike() {UserId = loginid, Text = "Dislike1"},
                                   new Dislike() {UserId = loginid, Text = "Dislike2"},
                                   new Dislike() {UserId = loginid, Text = "Dislike3"},
                               };

            User user = new User(loginid, name)
            {
                DateOfBirth = new GetInDate(DateTime.Today.AddYears(-25)),
                Location = new Location { City = "Banglore" },
                Gender = new Gender(),
                Likes = new HashedSet<Like>(likes),
                Dislikes = new HashedSet<Dislike>(dislikes),
                Picture = new Photo { Bytes = new byte[] { 1, 2, 3, 4, 5 } },
                Profile = new Profile("Big Profile")
            };

            var repositoryMock = new Moq.Mock<IUserRepository>();
            repositoryMock.Setup(p => p.LookupUsers(It.IsAny<User>())).Returns(new List<User> { user });
            user.Repository = repositoryMock.Object;
            Assert.Throws(typeof(UserAlreadyExistsException), user.Register);
            repositoryMock.VerifyAll();
        }
Example #10
0
        public void ShouldBeAbleToSetUserProperties()
        {
            LoginId loginid = new LoginId("*****@*****.**");
            string firstname = "firstName";
            string lastname = "lastName";
            Name name = new Name(firstname, lastname);

            Like[] likes = new Like[]
                               {
                                   new Like() {UserId = loginid, Text = "Like1"},
                                   new Like() {UserId = loginid, Text = "Like2"},
                                   new Like() {UserId = loginid, Text = "Like3"},
                               };

            Dislike[] dlikes = new Dislike[]
                               {
                                   new Dislike() {UserId = loginid, Text = "Dislike1"},
                                   new Dislike() {UserId = loginid, Text = "Dislike2"},
                                   new Dislike() {UserId = loginid, Text = "Dislike3"},
                               };

            Image image = new Bitmap(1, 1);

            User user = new User(loginid, name)
                            {
                                DateOfBirth = new GetInDate(DateTime.Today.AddYears(-25)),
                                Location = new Location { City = "Banglore" },
                                Gender = new Gender(),
                                Likes = new HashedSet<Like>(likes),
                                Dislikes = new HashedSet<Dislike>(dlikes),
                                Picture = new Photo { Bytes = new byte[] { 1, 2, 3, 4, 5 } },
                                Profile = new Profile("Big Profile")
                            };
        }
Example #11
0
        public void ShouldBeAbleToRejectInvitation()
        {
            var loginid = new LoginId("*****@*****.**");
            var name = new Name("Manish", "Manish");
            var manish = new User(loginid, name);

            var loginid2 = new LoginId("*****@*****.**");
            var name2 = new Name("Umar", "Umar");
            var umar = new User(loginid2, name2);

            manish.InviteFriend(umar);

            Assert.AreEqual(1, umar.Inviters.Count);

            umar.RejectFriendInvite(manish);

            Assert.AreEqual(0, umar.Inviters.Count);
            Assert.IsTrue(!umar.Friends.Contains(manish));
        }
Example #12
0
        public void ShouldBeAbleToRegisterUser()
        {
            LoginId loginid = new LoginId("*****@*****.**");
            string firstname = "firstName";
            string lastname = "lastName";
            Name name = new Name(firstname, lastname);

            Image image = new Bitmap(1, 1);

            Like[] likes = new Like[]
                               {
                                   new Like() {UserId = loginid, Text = "Like1"},
                                   new Like() {UserId = loginid, Text = "Like2"},
                                   new Like() {UserId = loginid, Text = "Like3"},
                               };

            Dislike[] dlikes = new Dislike[]
                               {
                                   new Dislike() {UserId = loginid, Text = "Dislike1"},
                                   new Dislike() {UserId = loginid, Text = "Dislike2"},
                                   new Dislike() {UserId = loginid, Text = "Dislike3"},
                               };

            User user = new User(loginid, name)
                            {
                                DateOfBirth = new GetInDate(DateTime.Today.AddYears(-25)),
                                Location = new Location { City = "Banglore" },
                                Gender = new Gender(),
                                Likes = new HashedSet<Like>(likes),
                                Dislikes = new HashedSet<Dislike>(dlikes),
                                Picture = new Photo { Bytes = new byte[] { 1, 2, 3, 4, 5 } },
                                Profile = new Profile("Big Profile")
                            };

            var repositoryMock = new Moq.Mock<IUserRepository>();
            repositoryMock.Setup(p => p.LookupUsers(It.IsAny<User>())).Returns(new List<User>());
            repositoryMock.Setup(p => p.Save(user));

            user.Repository = repositoryMock.Object;

            user.Register();
            repositoryMock.VerifyAll();
        }
Example #13
0
        public void ShouldBeAbleToInviteFriends()
        {
            var loginid = new LoginId("*****@*****.**");
            var name = new Name("firstName", "lastName");
            var manish = new User(loginid, name);

            var loginid2 = new LoginId("*****@*****.**");
            var name2 = new Name("firstName2", "lastName2");
            var umar = new User(loginid2, name2);

            Assert.AreEqual(0, umar.Inviters.Count);

            manish.InviteFriend(umar);

            Assert.AreEqual(1, umar.Inviters.Count);
            Assert.AreEqual(manish, umar.Inviters.ElementAt(0));
        }
Example #14
0
        public void DegreeOfSeparationShouldReturnZeroSizeListWhenDegreeOfSeparationGreaterThanThree()
        {
            IUserRepository repository = new UserRepository(session);

            var loginid = new LoginId("*****@*****.**");
            var name = new Name("Suchit", "Puri");
            var suchit = new User(loginid, name) { Repository = repository };

            var loginid2 = new LoginId("*****@*****.**");
            var name2 = new Name("Sumit", "Gupta");
            var sumit = new User(loginid2, name2) { Repository = repository };

            var loginid3 = new LoginId("*****@*****.**");
            var name3 = new Name("Manav", "Prasad");
            var manav = new User(loginid3, name3) { Repository = repository };

            var loginid4 = new LoginId("*****@*****.**");
            var name4 = new Name("Krishna", "Prasad");
            var krishna = new User(loginid4, name4) { Repository = repository };

            var loginid5 = new LoginId("*****@*****.**");
            var name5 = new Name("Srinivas", "");
            var srinivas = new User(loginid5, name5) { Repository = repository };

            repository.Save(sumit);
            repository.Save(suchit);
            repository.Save(manav);
            repository.Save(krishna);
            repository.Save(srinivas);

            suchit.InviteFriend(sumit);
            sumit.AcceptFriendInvite(suchit);
            sumit.InviteFriend(manav);
            manav.AcceptFriendInvite(sumit);

            manav.InviteFriend(krishna);
            krishna.AcceptFriendInvite(manav);

            krishna.InviteFriend(srinivas);
            srinivas.AcceptFriendInvite(krishna);

            session.Flush();
            session.Evict(suchit);
            session.Evict(sumit);
            session.Evict(manav);
            session.Evict(krishna);
            session.Evict(srinivas);
            Assert.AreEqual(0, suchit.DegreeOfSeparation(srinivas).Count);
        }
Example #15
0
        public void ShouldBeAbleToRegisterUser()
        {
            LoginId loginid = new LoginId("*****@*****.**");
            string firstname = "firstName";
            string lastname = "lastName";
            Name name = new Name(firstname, lastname);

            Like[] likes = new Like[]
                               {
                                   new Like() {UserId = loginid, Text = "Like1"},
                                   new Like() {UserId = loginid, Text = "Like2"},
                                   new Like() {UserId = loginid, Text = "Like3"},
                               };

            Dislike[] dlikes = new Dislike[]
                                   {
                                       new Dislike() {UserId = loginid, Text = "Dislike1"},
                                       new Dislike() {UserId = loginid, Text = "Dislike2"},
                                       new Dislike() {UserId = loginid, Text = "Dislike3"},
                                   };

            Image image = new Bitmap(1, 1);

            IUserRepository repository = new UserRepository(session);
            User user = new User(loginid, name)
                            {
                                DateOfBirth = new GetInDate(DateTime.Today.AddYears(-25)),
                                Location = new Location { City = "Banglore" },
                                Gender = new Gender(),
                                Likes = new HashedSet<Like>(likes),
                                Dislikes = new HashedSet<Dislike>(dlikes),
                                Picture = new Photo { Bytes = new byte[] { 1, 2, 3, 4, 5 } },
                                Profile = new Profile("Big Profile"),
                                Repository = repository
                            };
            repository.Save(user);

            session.Flush();
            session.Evict(user);

            User savedUser = repository.LookupUsers(user)[0];

            Assert.AreEqual(savedUser.LoginId, user.LoginId);
            Assert.AreEqual(savedUser.Location.City, user.Location.City);
            Assert.AreEqual(savedUser.Location.Country, user.Location.Country);
            Assert.AreEqual(savedUser.DateOfBirth.Value, user.DateOfBirth.Value);
            Assert.AreEqual(savedUser.Picture.Bytes.Length, user.Picture.Bytes.Length);
            for (int i = 0; i < savedUser.Picture.Bytes.Length; i++)
                Assert.AreEqual(savedUser.Picture.Bytes[i], user.Picture.Bytes[i]);

            Assert.AreEqual(savedUser.Likes.Count, user.Likes.Count);
            var arraylikes1 = savedUser.Likes.ToArray();
            var arraylikes2 = user.Likes.ToArray();
            for (int i = 0; i < arraylikes1.Length; i++)
                Assert.AreEqual(arraylikes1[i].Text, arraylikes2[i].Text);

            Assert.AreEqual(savedUser.Dislikes.Count, user.Dislikes.Count);
            var arraydislikes1 = savedUser.Dislikes.ToArray();
            var arraydislikes2 = user.Dislikes.ToArray();
            for (int i = 0; i < arraydislikes1.Length; i++)
                Assert.AreEqual(arraydislikes1[i].Text, arraydislikes2[i].Text);

            Assert.AreEqual(savedUser.Name.FirstName, user.Name.FirstName);
            Assert.AreEqual(savedUser.Name.LastName, user.Name.LastName);

            Assert.AreEqual(savedUser.Gender.Code, user.Gender.Code);
        }
Example #16
0
        public void ShouldBeAbleToPersistInvitersOnInvite()
        {
            IUserRepository repository = new UserRepository(session);

            var loginid = new LoginId("*****@*****.**");
            var name = new Name("Martin", "Fowler");
            var martin = new User(loginid, name) { Repository = repository };

            var loginid2 = new LoginId("*****@*****.**");
            var name2 = new Name("Roy", "Singham");
            var roy = new User(loginid2, name2) { Repository = repository };

            repository.Save(roy);
            repository.Save(martin);

            martin.InviteFriend(roy);

            session.Flush();
            session.Evict(martin);
            session.Evict(roy);

            IList<User> users = repository.LookupUsers(roy);
            Assert.IsTrue(users[0].Inviters.Contains(martin));
        }
Example #17
0
        public void onInvitationAcceptedUserShouldBePresentinFriendsList()
        {
            IUserRepository repository = new UserRepository(session);

            var loginid = new LoginId("*****@*****.**");
            var name = new Name("Suchit", "Puri");
            var suchit = new User(loginid, name) { Repository = repository };

            var loginid2 = new LoginId("*****@*****.**");
            var name2 = new Name("Sumit", "Gupta");
            var sumit = new User(loginid2, name2) { Repository = repository };

            repository.Save(sumit);
            repository.Save(suchit);

            suchit.InviteFriend(sumit);
            sumit.AcceptFriendInvite(suchit);
            session.Flush();
            session.Evict(suchit);
            session.Evict(sumit);

            //IList<User> users = repository.LookupUsers(sumit);
            Assert.True(suchit.isFriend(sumit));
        }
Example #18
0
        public void ShouldBeAbleToCreateANewUserObject()
        {
            LoginId loginid = new LoginId("*****@*****.**");
            string firstname = "firstName";
            string lastname = "lastName";
            Name name = new Name(firstname, lastname);

            User user = new User(loginid, name);
            Assert.AreEqual(user.Name, name);
            Assert.AreEqual(user.LoginId, loginid);
        }
Example #19
0
 public User(LoginId loginid, Name name)
     : this()
 {
     LoginId = loginid;
     Name = name;
 }