Save() public method

public Save ( User user ) : void
user User
return void
コード例 #1
0
ファイル: UserTest.cs プロジェクト: bagheera/getin
        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);
        }
コード例 #2
0
ファイル: UserTest.cs プロジェクト: bagheera/getin
        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);
        }
コード例 #3
0
ファイル: CommentsTest.cs プロジェクト: bagheera/getin
 public void UserShouldBeAbleToSaveComments()
 {
     IUserRepository repository = new UserRepository(_session);
     repository.Save(new User(new LoginId("*****@*****.**"), new Name("firstName1", "lastName1")));
     var user2 = new User(new LoginId("*****@*****.**"), new Name("firstName2", "lastName2")) { Profile = new Profile("This is the profile on which user1 will comment") };
     new Comment(new User(new LoginId("*****@*****.**"), new Name("firstName1", "lastName1")), user2, "This is what I am going to comment");
     repository.Save(user2);
     User interestedUser = null;
     IList<User> users = _session.CreateQuery("from User").List<User>();
     foreach (User user in users){
         if (user.LoginId.Value == new LoginId("*****@*****.**").Value){
             interestedUser = user;
             break;
         }
     }
     if (interestedUser != null){
         Assert.AreEqual("This is what I am going to comment", interestedUser.GetLatestProfileComment().Content);
         Assert.AreEqual(new User(new LoginId("*****@*****.**"), new Name("firstName1", "lastName1")),interestedUser.GetLatestProfileComment().Commentor);
     }
     else{
         Assert.Fail();
     }
 }
コード例 #4
0
ファイル: UserTest.cs プロジェクト: bagheera/getin
        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);
        }
コード例 #5
0
ファイル: UserTest.cs プロジェクト: bagheera/getin
        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);
        }
コード例 #6
0
ファイル: UserTest.cs プロジェクト: bagheera/getin
        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));
        }
コード例 #7
0
ファイル: UserTest.cs プロジェクト: bagheera/getin
        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));
        }
コード例 #8
0
ファイル: UserTest.cs プロジェクト: bagheera/getin
        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);
        }