DegreeOfSeparation() public method

public DegreeOfSeparation ( User indirectFriend ) : IList
indirectFriend User
return IList
Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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);
        }