public void GetDataByIdTest() { _repository .Setup(it => it.GetDataById(It.IsAny <Int32>())) .Returns <Int32>((id) => { return(_repositoryList.Where(x => x.Id == id).ToList()); }); var result = _target.GetDataById(idValue).ToList(); Assert.AreEqual(_repositoryList.Where(x => x.Id == idValue).ToList().Count, result.Count); }