コード例 #1
0
        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>()));
        }
コード例 #2
0
        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);
            }
        }