public void GetUserById_Test() { var userId = 1; var expected = "AAA"; var user = new User { UserName = expected, Id = userId }; var userRepositoryMock = new Mock <IRepository <User> >(); userRepositoryMock.Setup(m => m.GetById(userId)).Returns(user).Verifiable(); var unitOfWorkMock = new Mock <IUnitOfWork>(); unitOfWorkMock.Setup(m => m.UserRepository).Returns(userRepositoryMock.Object); IUserSystem sut = new UserSystem(unitOfWorkMock.Object); //Act var actual = sut.GetUser(userId); //Assert userRepositoryMock.Verify(); Assert.IsNotNull(actual); Assert.AreEqual(expected, actual.UserName); }