Beispiel #1
0
        public async void GetMessages_MessagesAmount_ReturnsCorrectAmountOfMessages(int expectedAmountMessages)
        {
            //Arrange
            IList <Message> messages = new List <Message>();

            for (int i = 0; i < expectedAmountMessages; i++)
            {
                messages.Add(GenerateFake.Message());
            }
            _mockContext.Setup(x => x.Messages).ReturnsDbSet(messages);

            //Act
            var messagesFromRepo = await _mockRepo.GetMessages();

            //Assert
            Assert.Equal(expectedAmountMessages, messagesFromRepo.Count());
        }
Beispiel #2
0
        public async void GetMessageById_MessageExists_ReturnsCorrectMessageId(int expectedId)
        {
            // Arrange
            IList <Message> messages = new List <Message> {
                new Message()
                {
                    Id   = expectedId,
                    Text = "This should work."
                },
                GenerateFake.Message(),
                GenerateFake.Message()
            };

            _mockContext.Setup(x => x.Messages).ReturnsDbSet(messages);

            // Act
            var message = await _mockRepo.GetMessageById(expectedId);

            // Assert
            Assert.Equal(expectedId, message.Id);
        }
Beispiel #3
0
        public async void GetMessageById_MessageNotExists_ReturnsNull(int nonExistantId)
        {
            // Arrange
            IList <Message> messages = new List <Message> {
                new Message()
                {
                    Id      = 1000,
                    Text    = "This should work.",
                    Created = DateTime.Now
                },
                GenerateFake.Message(),
                GenerateFake.Message()
            };

            _mockContext.Setup(x => x.Messages).ReturnsDbSet(messages);

            // Act
            var message = await _mockRepo.GetMessageById(nonExistantId);

            // Assert
            Assert.Null(message);
        }