Esempio n. 1
0
        public UsersViewModel CreateObservedByUserViewModel(Guid watcherUserId, Guid userId, int page, int amountOnPage)
        {
            IList <User> observers      = _userConnectionService.FindObservedByUser(userId, page, amountOnPage);
            var          usersViewModel = CreateUsersViewModel(observers, watcherUserId);

            return(usersViewModel);
        }
        public void service_must_return_expected_users_that_are_observed_by_user()
        {
            var user1 = DatabaseHelper.CreateValidUser("user29");
            var user2 = DatabaseHelper.CreateValidUser("user30");
            var user3 = DatabaseHelper.CreateValidUser("user31");
            var user4 = DatabaseHelper.CreateValidUser("user32");

            _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();

            IList <User> users = _userConnectionService.FindObservedByUser(user1.Id, 0, 10);

            _unitOfWork.Commit();

            Assert.AreEqual(2, users.Count, "Service must return correct amount of users that are observing by user");
            Assert.IsNotNull(users.FirstOrDefault(x => x.Id == user2.Id), "Service must return expected user that are observing by user (1)");
            Assert.IsNotNull(users.FirstOrDefault(x => x.Id == user4.Id), "Service must return expected user that are observing by user (2)");
        }