Пример #1
0
    public async Task Add_ShouldAddGroupMembershipsToTheDbContext()
    {
        // Arrange
        GroupMembership membership = new();

        IGroupMembershipRepository repository = new GroupMembershipRepository(_context);

        // Act
        await repository.Add(membership);

        // Assert
        Assert.NotEqual(0, membership.GroupMembershipId);
        GroupMembership addedMembership = await _context.GroupMemberships.FindAsync(membership.GroupMembershipId);

        Assert.NotNull(addedMembership);
    }
        public async Task Add_ShouldAddGroupMembershipsToTheDbContext()
        {
            // Arrange
            GroupMembership membership = new GroupMembership();

            Mock <DbSet <GroupMembership> > membershipDbSetMock = Enumerable
                                                                  .Empty <GroupMembership>()
                                                                  .AsQueryable()
                                                                  .BuildMockDbSet();

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

            contextMock
            .Setup(m => m.GroupMemberships)
            .Returns(membershipDbSetMock.Object);

            GroupMembershipRepository repository = new GroupMembershipRepository(contextMock.Object);

            // Act
            await repository.Add(membership);

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