public async Task <FriendshipResource> Handle(RequestFriendshipCommand request, CancellationToken cancellationToken = default)
        {
            int userId = _userProvider.GetCurrentUserId();

            Friendship friendship = new Friendship
            {
                RequesterId = userId,
                AddresseeId = request.AddresseeId
            };

            FriendshipChange change = new FriendshipChange
            {
                Created = _dateProvider.UtcNow(),
                Status  = FriendshipStatus.Pending,
            };

            friendship.StatusChanges.Add(change);

            await _unitOfWork.Friendships.Add(friendship, cancellationToken);

            await _unitOfWork.CommitAsync(cancellationToken);

            FriendshipResource resource = _mapper.Map <Friendship, FriendshipResource>(friendship);

            return(resource);
        }
Example #2
0
            public async Task <Unit> Handle(UpdateFriendshipStatusCommand request, CancellationToken cancellationToken = default)
            {
                FriendshipChange newChange = new FriendshipChange
                {
                    FriendshipId = request.FriendshipId,
                    StatusId     = request.FriendshipStatusId,
                    Created      = _dateProvider.UtcNow()
                };

                await _unitOfWork.FriendshipChanges.Add(newChange, cancellationToken);

                await _unitOfWork.CommitAsync(cancellationToken);

                return(Unit.Value);
            }
Example #3
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);
    }
Example #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>()));
        }
 public async Task Add(FriendshipChange change, CancellationToken cancellationToken = default)
 {
     await Context.FriendshipChanges.AddAsync(change, cancellationToken);
 }