Exemplo n.º 1
0
        public void Test_Method_GetById_Success()
        {
            _userServiceMock.Setup(e => e.GetById(It.IsAny <int>())).Returns(UsersDataHelper.GetUser(1));
            var result = _usersController.GetById(1);

            Assert.AreEqual(typeof(OkObjectResult), result.GetType());
            Assert.AreEqual(JsonConvert.SerializeObject(UsersDataHelper.GetUser(1)), JsonConvert.SerializeObject((result as OkObjectResult).Value));
        }
Exemplo n.º 2
0
        public void Test_Method_Get()
        {
            _userServiceMock.Setup(e => e.GetAll()).Returns(UsersDataHelper.GetAll());
            var result = _usersController.Get();

            Assert.AreEqual(typeof(OkObjectResult), result.GetType());
            var res = (result as OkObjectResult).Value as List <User>;

            Assert.AreEqual(2, res.Count);
            Assert.AreEqual(JsonConvert.SerializeObject(UsersDataHelper.GetUser(1)), JsonConvert.SerializeObject(res[0]));
        }
Exemplo n.º 3
0
        public void Test_Method_Search(int id, string expectedUserName)
        {
            _userServiceMock.Setup(e => e.SearchByUsername(It.IsAny <string>())).Returns(new List <User> {
                UsersDataHelper.GetUser(id)
            });
            var result = _usersController.Search("");

            Assert.AreEqual(typeof(OkObjectResult), result.GetType());
            var res = (result as OkObjectResult).Value as List <User>;

            Assert.AreEqual(expectedUserName, res[0].Username);
        }
        public void Test_Method_SearchByUsername()
        {
            var res = _userService.SearchByUsername("TestUsername");

            Assert.IsTrue(JsonSerializeAndCompare(UsersDataHelper.GetAll(), res.ToList()));
        }
        public void Test_Method_GetById()
        {
            var res = _userService.GetById(1);

            Assert.IsTrue(JsonSerializeAndCompare(UsersDataHelper.GetUser(1), res));
        }
        public void Test_Method_GetAll()
        {
            var res = _userService.GetAll();

            Assert.IsTrue(JsonSerializeAndCompare(UsersDataHelper.GetAll(), res.ToList()));
        }
 private void SeedData()
 {
     context.Users.AddRange(UsersDataHelper.GetAll());
     SaveAndDetachContext(context);
 }