public void ShouldFailToCancelNonPendingFriendshipRequest()
        {
            FriendshipRequest friendshipRequest = GetFriendshipRequest();

            friendshipRequest.Cancel();
            friendshipRequest.Cancel();

            Assert.IsFalse(friendshipRequest.IsValid);
            Assert.AreEqual("Só é possível cancelar uma solicitação pendente.", friendshipRequest.GetNotifications().FirstOrDefault().Description);
        }
        public void ShouldCancelFriendshipRequest()
        {
            FriendshipRequest friendshipRequest = GetFriendshipRequest();

            friendshipRequest.Cancel();

            Assert.IsTrue(friendshipRequest.IsValid);
            Assert.IsTrue(friendshipRequest.IsCanceled);
        }
예제 #3
0
        public async Task <CommandResult> Handle(CancelFriendshipRequestCommand request, CancellationToken cancellationToken)
        {
            FriendshipRequest friendshipRequest = await _friendshipRequestRepository.GetByIdAsync(request.FriendshipRequestId);

            if (friendshipRequest == null || !friendshipRequest.IsRequester(_currentProfileId))
            {
                return(FailureDueToFriendshipNotFound());
            }

            friendshipRequest.Cancel();
            if (!friendshipRequest.IsValid)
            {
                return(FailureDueToEntityStateInconsistency(friendshipRequest));
            }

            await _friendshipRequestRepository.UpdateAsync(friendshipRequest);

            return(await CommitAndPublishDefaultAsync());
        }