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); }
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); }
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); }
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)); }
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)); }
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)); }
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)); }
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); }