public void FindUserByName()
        {
            Mock <IUserRepository> repository = new Mock <IUserRepository>();
            IUserService           subject    = new TodoApi.Services.UserService(repository.Object);

            User user1 = new User();

            user1.Name   = "TestName";
            user1.UserId = 1;

            User user2 = new User();

            user2.Name   = "NameSecond";
            user2.UserId = 2;

            User user3 = new User();

            user3.Name   = "BillyBoBob";
            user3.UserId = 3;

            repository.Setup(repo => repo.GetEntities()).Returns(new List <User>()
            {
                user1, user2, user3
            }.AsQueryable());

            var result = subject.FindUserByName("Name");

            Assert.IsAssignableFrom <IEnumerable <User> >(result);
            Assert.Equal(2, result.Count());
            Assert.Contains(user1, result);
            Assert.Contains(user2, result);
            Assert.DoesNotContain(user3, result);
        }
Esempio n. 2
0
        public void GetAllUsers()
        {
            Mock <IUserRepository> repository = new Mock <IUserRepository>();
            IUserService           subject    = new TodoApi.Services.UserService(repository.Object);

            User user1 = new User();

            user1.Name   = "TestName";
            user1.UserId = 1;

            User user2 = new User();

            user2.Name   = "NameSecond";
            user2.UserId = 2;

            repository.Setup(repo => repo.GetEntities()).Returns(new List <User>()
            {
                user1, user2
            }.AsQueryable());

            var result = subject.GetAllUsers();

            Assert.IsAssignableFrom <IEnumerable <User> >(result);
            Assert.Equal(2, result.Count());
            Assert.Equal("TestName", result.ElementAt(0).Name);
            Assert.Equal("NameSecond", result.ElementAt(1).Name);
        }
Esempio n. 3
0
        public void CannotFindUserWithIdReturnsNull()
        {
            Mock <IUserRepository> repository = new Mock <IUserRepository>();
            IUserService           subject    = new TodoApi.Services.UserService(repository.Object);

            repository.Setup(repo => repo.GetById(It.IsAny <long>()));

            var result = subject.FindUserById(1);

            Assert.Null(result);
        }
Esempio n. 4
0
        public void FindUserWithId()
        {
            Mock <IUserRepository> repository = new Mock <IUserRepository>();
            IUserService           subject    = new TodoApi.Services.UserService(repository.Object);

            User user = new User();

            user.Name   = "TestName";
            user.UserId = 1;
            repository.Setup(repo => repo.GetById(It.IsAny <long>())).Returns(user);

            var result = subject.FindUserById(1);

            Assert.Equal("TestName", result.Name);
            Assert.Equal(1, result.UserId);
        }