public async Task CombinationExists_ShouldReturnFalse_WhenIdsInCombinationDontExist()
    {
        // Arrange
        const int requesterId = 4351;
        const int addresseeId = 12;

        IEnumerable <Friendship> expectedFriendship = new[]
        {
            new Friendship {
                FriendshipId = 1, RequesterId = 1, AddresseeId = 3
            },
            new Friendship {
                FriendshipId = 2, RequesterId = 2, AddresseeId = 1
            },
            new Friendship {
                FriendshipId = 3, RequesterId = 1, AddresseeId = 5
            },
            new Friendship {
                FriendshipId = 4, RequesterId = 4, AddresseeId = 1
            },
        };

        await _context.Friendships.AddRangeAsync(expectedFriendship);

        await _context.SaveChangesAsync();

        IFriendshipRepository repository = new FriendshipRepository(_context);

        // Act
        bool exists = await repository.CombinationExists(requesterId, addresseeId);

        // Assert
        Assert.False(exists);
    }
Exemplo n.º 2
0
        public async Task CombinationExists_ShouldReturnFalse_WhenIdsInCombinationDontExist()
        {
            // Arrange
            const int requesterId = 4351;
            const int addresseeId = 12;

            IEnumerable <Friendship> expectedFriendship = new[]
            {
                new Friendship {
                    FriendshipId = 1, RequesterId = 1, AddresseeId = 3
                },
                new Friendship {
                    FriendshipId = 2, RequesterId = 2, AddresseeId = 1
                },
                new Friendship {
                    FriendshipId = 3, RequesterId = 1, AddresseeId = 5
                },
                new Friendship {
                    FriendshipId = 3, RequesterId = 4, AddresseeId = 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.CombinationExists(requesterId, addresseeId);

            // Assert
            Assert.False(exists);
        }