示例#1
0
    public async Task GetLatestGroupedByRecipients_ShouldIncludeRecipientByDirectMessage_WhenTheUserIsTheAuthorInPrivateMessage()
    {
        // Arrange
        const int userId = 1;

        IEnumerable <MessageRecipient> messageRecipients = new[]
        {
            new MessageRecipient
            {
                MessageRecipientId = 1,
                Message            = new Message {
                    MessageId = 1, AuthorId = 1, Created = new DateTime(2020, 1, 1), HtmlContent = "<p>Hello World</p>"
                },
                Recipient = new Recipient {
                    UserId = 2
                }
            },
            new MessageRecipient
            {
                MessageRecipientId = 2,
                Message            = new Message {
                    MessageId = 2, AuthorId = 2, Created = new DateTime(2020, 1, 2), HtmlContent = "<p>Hello World</p>"
                },
                Recipient = new Recipient {
                    UserId = 3
                }
            },
            new MessageRecipient
            {
                MessageRecipientId = 3,
                Message            = new Message {
                    MessageId = 3, AuthorId = 1, Created = new DateTime(2020, 1, 3), HtmlContent = "<p>Hello World</p>"
                },
                Recipient = new Recipient {
                    UserId = 3
                }
            },
        };

        await _context.MessageRecipients.AddRangeAsync(messageRecipients);

        await _context.SaveChangesAsync();

        IMessageRecipientRepository repository = new MessageRecipientRepository(_context);

        // Act
        IEnumerable <MessageRecipient> result = await repository.GetLatestGroupedByRecipients(userId);

        // Assert
        Assert.NotEmpty(result);
        Assert.Equal(2, result.Count());

        Assert.Equal(3, result.ElementAt(0).MessageRecipientId);
        Assert.Equal(1, result.ElementAt(1).MessageRecipientId);
    }
        public async Task GetLatestGroupedByRecipients_ShouldIncludeRecipientByDirectMessage_WhenTheUserIsTheAuthorInPrivateMessage()
        {
            // Arrange
            const int userId = 1;

            IEnumerable <MessageRecipient> databaseMessageRecipients = new[]
            {
                new MessageRecipient
                {
                    MessageRecipientId = 1,
                    Message            = new Message {
                        MessageId = 1, AuthorId = 1, Created = new DateTime(2020, 1, 1)
                    },
                    Recipient = new Recipient {
                        UserId = 2
                    }
                },
                new MessageRecipient
                {
                    MessageRecipientId = 2,
                    Message            = new Message {
                        MessageId = 2, AuthorId = 2, Created = new DateTime(2020, 1, 2)
                    },
                    Recipient = new Recipient {
                        UserId = 3
                    }
                },
                new MessageRecipient
                {
                    MessageRecipientId = 3,
                    Message            = new Message {
                        MessageId = 3, AuthorId = 1, Created = new DateTime(2020, 1, 3)
                    },
                    Recipient = new Recipient {
                        UserId = 3
                    }
                },
            };

            DbSet <MessageRecipient> dbSetMock = databaseMessageRecipients
                                                 .AsQueryable()
                                                 .BuildMockDbSet()
                                                 .Object;

            _contextMock
            .Setup(m => m.MessageRecipients)
            .Returns(dbSetMock);

            MessageRecipientRepository repository = new MessageRecipientRepository(_contextMock.Object);

            // Act
            IEnumerable <MessageRecipient> result = await repository
                                                    .GetLatestGroupedByRecipients(userId)
                                                    .ToListAsync();

            // Assert
            Assert.NotEmpty(result);
            Assert.Equal(2, result.Count());

            Assert.Equal(3, result.ElementAt(0).MessageRecipientId);
            Assert.Equal(1, result.ElementAt(1).MessageRecipientId);
        }
示例#3
0
    public async Task GetLatestGroupedByRecipients_ShouldIncludeRecipientByGroupMessage_WhenTheUserIsMemberOfTheGroup()
    {
        // Arrange
        const int userId = 1;

        IEnumerable <MessageRecipient> messageRecipients = new[]
        {
            // User is author in message to group 1
            new MessageRecipient
            {
                MessageRecipientId = 1,
                Message            = new Message {
                    MessageId = 1, AuthorId = 1, Created = new DateTime(2020, 1, 1), HtmlContent = "<p>Hello World</p>"
                },
                Recipient = new Recipient
                {
                    GroupMembershipId = 1,
                    GroupMembership   = new GroupMembership
                    {
                        GroupId           = 1,
                        GroupMembershipId = 1, UserId = 1,
                    }
                }
            },
            new MessageRecipient
            {
                MessageRecipientId = 2,
                Message            = new Message {
                    MessageId = 2, AuthorId = 1, Created = new DateTime(2020, 1, 1), HtmlContent = "<p>Hello World</p>"
                },
                Recipient = new Recipient
                {
                    GroupMembershipId = 2,
                    GroupMembership   = new GroupMembership
                    {
                        GroupId           = 1,
                        GroupMembershipId = 2, UserId = 2,
                    }
                }
            },
            new MessageRecipient
            {
                MessageRecipientId = 3,
                Message            = new Message {
                    MessageId = 3, AuthorId = 2, Created = new DateTime(2020, 1, 2), HtmlContent = "<p>Hello World</p>"
                },
                Recipient = new Recipient
                {
                    GroupMembershipId = 3,
                    GroupMembership   = new GroupMembership
                    {
                        GroupId           = 2,
                        GroupMembershipId = 3, UserId = 2,
                    }
                }
            },
            // User is recipient in message to group 2
            new MessageRecipient
            {
                MessageRecipientId = 4,
                Message            = new Message {
                    MessageId = 4, AuthorId = 2, Created = new DateTime(2020, 1, 2), HtmlContent = "<p>Hello World</p>"
                },
                Recipient = new Recipient
                {
                    GroupMembershipId = 4,
                    GroupMembership   = new GroupMembership
                    {
                        GroupId           = 2,
                        GroupMembershipId = 4, UserId = 1,
                    }
                }
            },
        };

        await _context.MessageRecipients.AddRangeAsync(messageRecipients);

        await _context.SaveChangesAsync();

        IMessageRecipientRepository repository = new MessageRecipientRepository(_context);

        // Act
        IEnumerable <MessageRecipient> result = await repository.GetLatestGroupedByRecipients(userId);

        // Assert
        Assert.NotEmpty(result);
        Assert.Equal(2, result.Count());

        Assert.Equal(4, result.ElementAt(0).MessageRecipientId);
        Assert.Equal(1, result.ElementAt(1).MessageRecipientId);
    }
        public async Task GetLatestGroupedByRecipients_ShouldIncludeRecipientByGroupMessage_WhenTheUserIsMemberOfTheGroup()
        {
            // Arrange
            const int userId = 1;

            IEnumerable <MessageRecipient> databaseMessageRecipients = new[]
            {
                // User is author in message to group 1
                new MessageRecipient
                {
                    MessageRecipientId = 1,
                    Message            = new Message {
                        MessageId = 1, AuthorId = 1, Created = new DateTime(2020, 1, 1)
                    },
                    Recipient = new Recipient
                    {
                        GroupMembershipId = 1,
                        GroupMembership   = new GroupMembership
                        {
                            GroupId           = 1,
                            GroupMembershipId = 1, UserId = 1,
                        }
                    }
                },
                new MessageRecipient
                {
                    MessageRecipientId = 2,
                    Message            = new Message {
                        MessageId = 1, AuthorId = 1, Created = new DateTime(2020, 1, 1)
                    },
                    Recipient = new Recipient
                    {
                        GroupMembershipId = 2,
                        GroupMembership   = new GroupMembership
                        {
                            GroupId           = 1,
                            GroupMembershipId = 2, UserId = 2,
                        }
                    }
                },
                new MessageRecipient
                {
                    MessageRecipientId = 3,
                    Message            = new Message {
                        MessageId = 2, AuthorId = 2, Created = new DateTime(2020, 1, 2)
                    },
                    Recipient = new Recipient
                    {
                        GroupMembershipId = 3,
                        GroupMembership   = new GroupMembership
                        {
                            GroupId           = 2,
                            GroupMembershipId = 3, UserId = 2,
                        }
                    }
                },
                // User is recipient in message to group 2
                new MessageRecipient
                {
                    MessageRecipientId = 4,
                    Message            = new Message {
                        MessageId = 2, AuthorId = 2, Created = new DateTime(2020, 1, 2)
                    },
                    Recipient = new Recipient
                    {
                        GroupMembershipId = 4,
                        GroupMembership   = new GroupMembership
                        {
                            GroupId           = 2,
                            GroupMembershipId = 4, UserId = 1,
                        }
                    }
                },
            };

            DbSet <MessageRecipient> dbSetMock = databaseMessageRecipients
                                                 .AsQueryable()
                                                 .BuildMockDbSet()
                                                 .Object;

            _contextMock
            .Setup(m => m.MessageRecipients)
            .Returns(dbSetMock);

            MessageRecipientRepository repository = new MessageRecipientRepository(_contextMock.Object);

            // Act
            IEnumerable <MessageRecipient> result = await repository
                                                    .GetLatestGroupedByRecipients(userId)
                                                    .ToListAsync();

            // Assert
            Assert.NotEmpty(result);
            Assert.Equal(2, result.Count());

            Assert.Equal(4, result.ElementAt(0).MessageRecipientId);
            Assert.Equal(1, result.ElementAt(1).MessageRecipientId);
        }