Exemplo n.º 1
0
 public PopoverViewModel CreatePopoverViewModel(Guid fromUserId, Guid toUserId)
 {
     return(new PopoverViewModel
     {
         User = _userService.FindById(toUserId),
         YouObserveUser = fromUserId != toUserId && _userConnectionService.IsConnectionBetweenUsers(fromUserId, toUserId),
         UserObservesYou = fromUserId != toUserId && _userConnectionService.IsConnectionBetweenUsers(toUserId, fromUserId),
         IsThisSameUser = fromUserId == toUserId,
         AmountOfAllObservedByUser = _userConnectionService.AmountOfAllObservedByUser(toUserId),
         AmountOfAllUserObservers = _userConnectionService.AmountOfAllUserObservers(toUserId)
     });
 }
        public void service_must_return_correct_amount_of_users_that_observe_user()
        {
            var user1 = DatabaseHelper.CreateValidUser("user9");
            var user2 = DatabaseHelper.CreateValidUser("user10");
            var user3 = DatabaseHelper.CreateValidUser("user11");
            var user4 = DatabaseHelper.CreateValidUser("user12");

            _userReposiotry.Create(user1);
            _userReposiotry.Create(user2);
            _userReposiotry.Create(user3);
            _userReposiotry.Create(user4);
            _userConnectionRepository.Create(new UserConnection {
                Id = Guid.NewGuid(), FromUser = user1, ToUser = user2
            });
            _userConnectionRepository.Create(new UserConnection {
                Id = Guid.NewGuid(), FromUser = user3, ToUser = user1
            });
            _userConnectionRepository.Create(new UserConnection {
                Id = Guid.NewGuid(), FromUser = user1, ToUser = user4
            });
            _userConnectionRepository.Create(new UserConnection {
                Id = Guid.NewGuid(), FromUser = user2, ToUser = user1
            });
            _userConnectionRepository.Create(new UserConnection {
                Id = Guid.NewGuid(), FromUser = user3, ToUser = user4
            });
            _unitOfWork.Commit();

            int amount = _userConnectionService.AmountOfAllUserObservers(user1.Id);

            _unitOfWork.Commit();

            Assert.AreEqual(2, amount, "Service must return correct amount of users observing user");
        }