Example #1
0
        public void Can_Add_Message()
        {
            //Arrange
            var author = new AppUser
            {
                Id = "id1", UserName = "******", Email = "*****@*****.**"
            };
            var meeting = new Meeting
            {
                MeetingId = 1,
                Title     = "Meeting for message"
            };
            var message = new Message
            {
                Text    = "This is a text of message which is test message",
                Author  = author,
                Created = DateTime.Now,
                Meeting = meeting
            };

            using (var factory = new SQLiteDbContextFactory())
            {
                using (var context = factory.CreateContext())
                {
                    context.Users.Add(author);
                    context.Meetings.Add(meeting);
                    context.SaveChanges();
                    //Act
                    var messageRepository = new EFMessageRepository(context);
                    messageRepository.SaveMessage(message);
                }

                //Assert
                using (var context = factory.CreateContext())
                {
                    var result = context.Messages
                                 .Include(m => m.Author)
                                 .Include(m => m.Meeting)
                                 .FirstOrDefault();
                    Assert.Equal(1, context.Users.Count());
                    Assert.Equal(1, context.Meetings.Count());
                    Assert.Equal(1, context.Messages.Count());
                    Assert.Equal(message.Text, result.Text);
                    Assert.Equal(message.AuthorId, result.Author.Id);
                    Assert.Equal(message.Created, result.Created);
                    Assert.Equal(message.MeetingId, result.Meeting.MeetingId);
                }
            }
        }
Example #2
0
        public void Can_Edit_Message()
        {
            //Arrange
            var textMessage = "This is a new text of the message.";
            var author      = new AppUser
            {
                Id = "id1", UserName = "******", Email = "*****@*****.**"
            };
            var message = new Message
            {
                Text    = "This is a text of the message which is a test message",
                Author  = author,
                Created = DateTime.Now.AddDays(1)
            };

            using (var factory = new SQLiteDbContextFactory())
            {
                using (var context = factory.CreateContext())
                {
                    context.Users.Add(author);
                    context.Messages.Add(message);
                    context.SaveChanges();
                    //Act
                    var messageRepository = new EFMessageRepository(context);
                    messageRepository.SaveMessage(new Message {
                        Text = textMessage, MessageId = 1
                    });
                }

                //Assert
                using (var context = factory.CreateContext())
                {
                    var result = context.Messages
                                 .Include(m => m.Author)
                                 .FirstOrDefault();
                    Assert.Equal(1, context.Users.Count());
                    Assert.Equal(1, context.Messages.Count());
                    Assert.Equal(textMessage, result.Text);
                    Assert.Equal(message.AuthorId, result.Author.Id);
                    Assert.Equal(message.Created, result.Created);
                }
            }
        }