public void GetUsers() { var mock = new Mock<IDataStore>(); mock.Setup(o => o.GetUsers(It.IsAny<int>())).Returns(new List<User> {new User(1, "admin", true), new User(2, "test", false)}); var messengerService = new MessengerService {DataStore = mock.Object}; messengerService.GetUsers(1); mock.Verify(w => w.GetUsers(It.IsAny<int>())); }
public void GetUsersException() { var mock = new Mock<IDataStore>(); mock.Setup(o => o.GetUsers(It.IsAny<int>())).Throws(new Exception("Test Exception")); var messengerService = new MessengerService {DataStore = mock.Object}; try { messengerService.GetUsers(1); } catch (Exception exception) { Assert.AreEqual("Test Exception", exception.Message); } }