Ejemplo n.º 1
0
        public void ShouldThrowExceptionWhenSuccessfullyAddedChatButToUserIsNull()
        {
            var addDbResult = _chatMessages.FirstOrDefault();
            var getDbResult = _chatMessages.FirstOrDefault() ?? new ChatMessage();
            getDbResult.ToUser = null;

            var chatMessageParam = new Common.Contracts.ChatMessage
            {
                Id = 1,
                Text = "Lorem ipsum dolor sit amet",
                FromUser = new Common.Contracts.User
                {
                    Id = 1,
                    UserName = "******"
                },
                ToUser = new Common.Contracts.User
                {
                    Id = 2,
                    UserName = "******"
                }
            };

            _chatMessageRepository = new Mock<IChatMessageRepository>();
            _chatMessageRepository.Setup(a => a.Add(It.IsAny<ChatMessage>())).Returns(addDbResult);
            _chatMessageRepository.Setup(a => a.Find(It.IsAny<Expression<Func<ChatMessage, bool>>>(), null, It.IsAny<string>())).Returns(new List<ChatMessage> { getDbResult });

            _userRepository = new Mock<IUserRepository>();

            _chatMessagesLogic = new ChatMessagesLogic(_chatMessageRepository.Object, _userRepository.Object);

            var exception = Assert.Throws<BlogException>(() => _chatMessagesLogic.Add(chatMessageParam));

            Assert.AreEqual("Successfully created message but failed to get users related to the message.", exception.Message);
        }
Ejemplo n.º 2
0
        public void ShouldThrowExceptionWhenAddingChatMessageFails()
        {
            var chatMessageParam = new Common.Contracts.ChatMessage
            {
                Id = 1,
                Text = "Lorem ipsum dolor sit amet",
                FromUser = new Common.Contracts.User
                {
                    Id = 1,
                    UserName = "******"
                },
                ToUser = new Common.Contracts.User
                {
                    Id = 2,
                    UserName = "******"
                }
            };

            _chatMessageRepository = new Mock<IChatMessageRepository>();
            _chatMessageRepository.Setup(a => a.Add(It.IsAny<ChatMessage>())).Throws(new Exception());

            _userRepository = new Mock<IUserRepository>();

            _chatMessagesLogic = new ChatMessagesLogic(_chatMessageRepository.Object, _userRepository.Object);

            Assert.Throws<BlogException>(() => _chatMessagesLogic.Add(chatMessageParam));
        }
Ejemplo n.º 3
0
        public void ShouldAddChatMessage()
        {
            var dbResult = _chatMessages.FirstOrDefault();
            var chatMessageParam = new Common.Contracts.ChatMessage
            {
                Id = 1,
                Text = "Lorem ipsum dolor sit amet",
                FromUser = new Common.Contracts.User
                {
                    Id = 1,
                    UserName = "******"
                },
                ToUser = new Common.Contracts.User
                {
                    Id = 2,
                    UserName = "******"
                }
            };

            _chatMessageRepository = new Mock<IChatMessageRepository>();
            _chatMessageRepository.Setup(a => a.Add(It.IsAny<ChatMessage>())).Returns(dbResult);
            _chatMessageRepository.Setup(a => a.Find(It.IsAny<Expression<Func<ChatMessage, bool>>>(), null, It.IsAny<string>())).Returns(_chatMessages);

            _userRepository = new Mock<IUserRepository>();

            _chatMessagesLogic = new ChatMessagesLogic(_chatMessageRepository.Object, _userRepository.Object);

            var result = _chatMessagesLogic.Add(chatMessageParam);

            Assert.IsNotNull(result);
            Assert.IsNotNull(result.FromUser);
            Assert.IsNotNull(result.ToUser);
            Assert.IsInstanceOf(typeof(Common.Contracts.ChatMessage), result);
        }