Esempio n. 1
0
        public void GetUserName()
        {
            var mock = new Mock<IDataStore>();
            var messengerService = new MessengerService {DataStore = mock.Object};
            messengerService.GetUserName(1);

            mock.Verify(w => w.GetUserName(It.IsAny<int>()));
        }
Esempio n. 2
0
        public void GetMessages()
        {
            var mock = new Mock<IDataStore>();
            var messengerService = new MessengerService {DataStore = mock.Object};
            messengerService.GetMessages(1, 2);

            mock.Verify(w => w.GetMessages(It.IsAny<int>(), It.IsAny<int>()));
        }
Esempio n. 3
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>()));
        }
Esempio n. 4
0
        public void GetUserNameException()
        {
            var mock = new Mock<IDataStore>();
            mock.Setup(o => o.GetUserName(It.IsAny<int>())).Throws(new Exception("Test Exception"));
            var messengerService = new MessengerService {DataStore = mock.Object};

            try
            {
                messengerService.GetUserName(1);
            }
            catch (Exception exception)
            {
                Assert.AreEqual("Test Exception", exception.Message);
            }
        }
Esempio n. 5
0
        public void Login()
        {
            var mock = new Mock<IDataStore>();
            var messengerService = new MessengerService {DataStore = mock.Object};
            messengerService.Login("admin");

            mock.Verify(w => w.Login(It.IsAny<string>()));
        }
Esempio n. 6
0
        public void SendMessageException()
        {
            var mock = new Mock<IDataStore>();
            mock.Setup(o => o.IfUser(It.IsAny<int>())).Returns(false);
            var messengerService = new MessengerService {DataStore = mock.Object};

            try
            {
                messengerService.SendMessage(new Message(1, 2, DateTime.Now, "test"));
            }
            catch (Exception exception)
            {
                Assert.AreEqual("Cann't send message. User not found.", exception.Message);
            }
        }
Esempio n. 7
0
        public void SendMessage()
        {
            var mock = new Mock<IDataStore>();
            mock.Setup(o => o.IfUser(It.IsAny<int>())).Returns(true);
            var messengerService = new MessengerService {DataStore = mock.Object};
            messengerService.SendMessage(new Message(1, 2, DateTime.Now, "test"));

            mock.Verify(w => w.IfUser(1));
            mock.Verify(w => w.IfUser(2));
            mock.Verify(w => w.AddMessage(It.IsAny<Message>()));
        }
Esempio n. 8
0
        public void LoginException()
        {
            var mock = new Mock<IDataStore>();
            mock.Setup(o => o.Login(It.IsAny<string>())).Throws(new Exception("Test Exception"));
            var messengerService = new MessengerService {DataStore = mock.Object};

            try
            {
                messengerService.Login("admin");
            }
            catch (Exception exception)
            {
                Assert.AreEqual("Test Exception", exception.Message);
            }
        }