예제 #1
0
        public void GetUserByIdTest()
        {
            IndividualUserTestData testData = new IndividualUserTestData();
            var objects = testData.ToList();

            List <User> users = new List <User>();

            int i = 0;

            foreach (var item in objects)
            {
                User u = (User)item[0];
                u.ID = i;
                users.Add(u);
                i++;
            }

            var          moqRep      = new Mock <IUserRepository>();
            IUserService userService = new UserService(moqRep.Object);

            for (int id = 0; id < objects.Count; id++)
            {
                moqRep.Setup(x => x.ReadByID(id)).Returns(users.FirstOrDefault(u => u.ID == id));
                User retrievedUser = userService.GetUserByID(id);
                moqRep.Verify(x => x.ReadByID(id), Times.Once);
                Assert.Equal(id, retrievedUser.ID);
                moqRep.Reset();
            }
        }
예제 #2
0
        public void GetAllUsersTest()
        {
            IndividualUserTestData testData = new IndividualUserTestData();
            var objects = testData.ToList();

            List <User> users = new List <User>();

            foreach (var item in objects)
            {
                users.Add((User)item[0]);
            }

            var moqRep = new Mock <IUserRepository>();

            moqRep.Setup(x => x.ReadAll(null)).Returns(new CrownCleanApp.Core.DomainService.Filtering.FilteredList <User>()
            {
                List = users
            });

            IUserService userService = new UserService(moqRep.Object);

            List <User> retrievedUsers = userService.GetAllUsers(null).List.ToList();

            moqRep.Verify(x => x.ReadAll(null), Times.Once);
            Assert.Equal(users, retrievedUsers);
        }