예제 #1
0
        public async Task Exists_ShouldReturnTrue_WhenFriendshipExists()
        {
            // Arrange
            const int friendshipId = 1;

            IEnumerable <Friendship> expectedFriendship = new[]
            {
                new Friendship {
                    FriendshipId = 1
                }
            };

            Mock <DbSet <Friendship> > friendshipDbSetMock = expectedFriendship
                                                             .AsQueryable()
                                                             .BuildMockDbSet();

            Mock <IChatContext> contextMock = new Mock <IChatContext>();

            contextMock
            .Setup(m => m.Friendships)
            .Returns(friendshipDbSetMock.Object);

            IFriendshipRepository repository = new FriendshipRepository(contextMock.Object);

            // Act
            bool exists = await repository.Exists(friendshipId);

            // Assert
            Assert.True(exists);
        }
    public async Task Exists_ShouldReturnFalse_WhenFriendshipDoesNotExist()
    {
        // Arrange
        const int friendshipId = 9881641;

        Friendship expectedFriendship = new() { FriendshipId = 1 };

        await _context.Friendships.AddAsync(expectedFriendship);

        await _context.SaveChangesAsync();

        IFriendshipRepository repository = new FriendshipRepository(_context);

        // Act
        bool exists = await repository.Exists(friendshipId);

        // Assert
        Assert.False(exists);
    }