コード例 #1
0
    public async Task GetByFriendship_ShouldGetFriendships()
    {
        // Arrange
        const int friendshipId = 1;

        IEnumerable <FriendshipChange> changes = new[]
        {
            new FriendshipChange {
                FriendshipChangeId = 1, FriendshipId = 1
            },
            new FriendshipChange {
                FriendshipChangeId = 2, FriendshipId = 1
            },
            new FriendshipChange {
                FriendshipChangeId = 3, FriendshipId = 2
            },
            new FriendshipChange {
                FriendshipChangeId = 4, FriendshipId = 2
            },
        };

        await _context.FriendshipChanges.AddRangeAsync(changes);

        await _context.SaveChangesAsync();

        IFriendshipChangeRepository repository = new FriendshipChangeRepository(_context);

        // Act
        IEnumerable <FriendshipChange> actualChanges = await repository.GetByFriendship(friendshipId);

        // Assert
        Assert.Equal(2, actualChanges.Count());
        Assert.All(actualChanges, change => Assert.Equal(friendshipId, change.FriendshipId));
    }
コード例 #2
0
    public async Task Add_ShouldAddFriendshipChange()
    {
        // Arrange
        FriendshipChange change = new();

        IFriendshipChangeRepository repository = new FriendshipChangeRepository(_context);

        // Act
        await repository.Add(change);

        // Assert
        Assert.NotEqual(0, change.FriendshipChangeId);
        FriendshipChange addedChange = await _context.FriendshipChanges.FindAsync(change.FriendshipChangeId);

        Assert.NotNull(addedChange);
    }
コード例 #3
0
        public async Task GetByFriendship_ShouldGetFriendships()
        {
            // Arrange
            const int friendshipId = 1;

            IEnumerable <FriendshipChange> changes = new[]
            {
                new FriendshipChange {
                    FriendshipChangeId = 1, FriendshipId = 1
                },
                new FriendshipChange {
                    FriendshipChangeId = 2, FriendshipId = 1
                },
                new FriendshipChange {
                    FriendshipChangeId = 3, FriendshipId = 2
                },
                new FriendshipChange {
                    FriendshipChangeId = 4, FriendshipId = 2
                },
            };

            Mock <DbSet <FriendshipChange> > friendshipChangeDbSetMock = changes
                                                                         .AsQueryable()
                                                                         .BuildMockDbSet();

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

            contextMock
            .Setup(m => m.FriendshipChanges)
            .Returns(friendshipChangeDbSetMock.Object);

            FriendshipChangeRepository repository = new FriendshipChangeRepository(contextMock.Object);

            // Act
            IEnumerable <FriendshipChange> actualChanges = await repository
                                                           .GetByFriendship(friendshipId)
                                                           .ToListAsync();

            // Assert
            Assert.Equal(2, actualChanges.Count());
            Assert.All(actualChanges, change => Assert.Equal(friendshipId, change.FriendshipId));
        }
コード例 #4
0
        public async Task Add_ShouldAddFriendshipChange()
        {
            // Arrange
            FriendshipChange change = new FriendshipChange();

            Mock <DbSet <FriendshipChange> > friendshipChangeDbSetMock = Enumerable
                                                                         .Empty <FriendshipChange>()
                                                                         .AsQueryable()
                                                                         .BuildMockDbSet();

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

            contextMock
            .Setup(m => m.FriendshipChanges)
            .Returns(friendshipChangeDbSetMock.Object);

            IFriendshipChangeRepository repository = new FriendshipChangeRepository(contextMock.Object);

            // Act
            await repository.Add(change);

            // Assert
            contextMock.Verify(m => m.FriendshipChanges.AddAsync(change, It.IsAny <CancellationToken>()));
        }