Ejemplo n.º 1
0
        public async Task GetMessagesAsync_ChannelId3_ReturnsEmptyList(MessagesResourceParameters messagesResourceParameters)
        {
            // Arrange
            var options = DatabaseUtilities.GetTestDbConextOptions <CompanyNameProjectNameContext>();

            var user = new User()
            {
                Email     = "*****@*****.**",
                FirstName = "Test",
                LastName  = "User"
            };

            var messageOne = new Message()
            {
                Text      = "Test Message One",
                ChannelId = 1,
            };
            var messageTwo = new Message()
            {
                Text      = "Test Message Two",
                ChannelId = 2,
            };

            using (var context = new CompanyNameProjectNameContext(options))
            {
                context.Database.OpenConnection();
                context.Database.EnsureCreated();

                // Add a user because we need a UserId foreign key for the messages
                var usersRepository = new UsersRepository(context, MapperUtilities.GetTestMapper());
                await usersRepository.CreateAsync(user);
            }

            using (var context = new CompanyNameProjectNameContext(options))
            {
                var messagesRepository = new MessagesRepository(context, MapperUtilities.GetTestMapper());

                messageOne.UserId = user.Id;
                messageTwo.UserId = user.Id;

                // Add the messages
                await messagesRepository.CreateAsync(messageOne);

                await messagesRepository.CreateAsync(messageTwo);
            }

            using (var context = new CompanyNameProjectNameContext(options))
            {
                var messagesRepository = new MessagesRepository(context, MapperUtilities.GetTestMapper());

                // Act
                var results = await messagesRepository.GetMessagesAsync(messagesResourceParameters);

                // Assert
                Assert.AreEqual(results.Count(), 0);
            }
        }
Ejemplo n.º 2
0
        public void GetMessagesAsync_NullParameters_ReturnsArgumentNullException()
        {
            // Arrange
            var options = DatabaseUtilities.GetTestDbConextOptions <CompanyNameProjectNameContext>();

            using (var context = new CompanyNameProjectNameContext(options))
            {
                context.Database.OpenConnection();
                context.Database.EnsureCreated();

                var messagesRepository = new MessagesRepository(context, MapperUtilities.GetTestMapper());

                // Assert
                Assert.ThrowsAsync <ArgumentNullException>(async() => await messagesRepository.GetMessagesAsync(null));
            }
        }
Ejemplo n.º 3
0
        public async Task GetMessagesAsync_AllPropertiesNull_ReturnsAllMessages()
        {
            // Arrange
            var options = DatabaseUtilities.GetTestDbConextOptions <CompanyNameProjectNameContext>();

            var user = new User()
            {
                Email     = "*****@*****.**",
                FirstName = "Test",
                LastName  = "User"
            };

            var messageOne = new Message()
            {
                Text      = "Test Message One",
                ChannelId = 1,
            };
            var messageTwo = new Message()
            {
                Text      = "Test Message Two",
                ChannelId = 1,
            };

            using (var context = new CompanyNameProjectNameContext(options))
            {
                context.Database.OpenConnection();
                context.Database.EnsureCreated();

                // Add a user because we need a UserId foreign key for the messages
                var usersRepository = new UsersRepository(context, MapperUtilities.GetTestMapper());
                await usersRepository.CreateAsync(user);
            }

            using (var context = new CompanyNameProjectNameContext(options))
            {
                var messagesRepository = new MessagesRepository(context, MapperUtilities.GetTestMapper());

                messageOne.UserId = user.Id;
                messageTwo.UserId = user.Id;

                // Add the messages
                await messagesRepository.CreateAsync(messageOne);

                await messagesRepository.CreateAsync(messageTwo);
            }

            using (var context = new CompanyNameProjectNameContext(options))
            {
                var messagesRepository = new MessagesRepository(context, MapperUtilities.GetTestMapper());

                // Act
                var parameters = new MessagesResourceParameters {
                    ChannelId = 0, SearchQuery = null
                };

                // Get messages with null properties for parameters
                var results = await messagesRepository.GetMessagesAsync(parameters);

                // Assert
                Assert.AreEqual(results.Count(), 2);
                Assert.IsTrue(results.FirstOrDefault(x => x.Text == messageOne.Text) != null);
                Assert.IsTrue(results.FirstOrDefault(x => x.Text == messageTwo.Text) != null);
            }
        }
Ejemplo n.º 4
0
 public async Task <IActionResult> GetMessagesAsync()
 {
     return(Ok(await messagesRepository.GetMessagesAsync(int.Parse(User.Identity.Name))));
 }