コード例 #1
0
        public UsersViewModel CreateUserObserversViewModel(Guid watcherUserId, Guid userId, int page, int amountOnPage)
        {
            IList <User> observers      = _userConnectionService.FindUserObservers(userId, page, amountOnPage);
            var          usersViewModel = CreateUsersViewModel(observers, watcherUserId);

            return(usersViewModel);
        }
コード例 #2
0
        public void service_must_return_expected_users_that_observe_user()
        {
            var user1 = DatabaseHelper.CreateValidUser("user13");
            var user2 = DatabaseHelper.CreateValidUser("user14");
            var user3 = DatabaseHelper.CreateValidUser("user15");
            var user4 = DatabaseHelper.CreateValidUser("user16");

            _userReposiotry.Create(user1);
            _userReposiotry.Create(user2);
            _userReposiotry.Create(user3);
            _userReposiotry.Create(user4);
            _userConnectionRepository.Create(new UserConnection {
                Id = Guid.NewGuid(), FromUser = user1, ToUser = user2, CreationDate = DateTime.UtcNow.AddDays(-5)
            });
            _userConnectionRepository.Create(new UserConnection {
                Id = Guid.NewGuid(), FromUser = user3, ToUser = user1, CreationDate = DateTime.UtcNow.AddDays(-4)
            });
            _userConnectionRepository.Create(new UserConnection {
                Id = Guid.NewGuid(), FromUser = user1, ToUser = user4, CreationDate = DateTime.UtcNow.AddDays(-3)
            });
            _userConnectionRepository.Create(new UserConnection {
                Id = Guid.NewGuid(), FromUser = user2, ToUser = user1, CreationDate = DateTime.UtcNow.AddDays(-2)
            });
            _userConnectionRepository.Create(new UserConnection {
                Id = Guid.NewGuid(), FromUser = user3, ToUser = user4, CreationDate = DateTime.UtcNow.AddDays(-1)
            });
            _unitOfWork.Commit();

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

            _unitOfWork.Commit();

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