Example #1
0
        public async Task ShouldDeleteFriend()
        {
            GenerateMock();

            var friendMock = new Mock <Friend>();

            _friendRepositoryMock
            .Setup(x => x.FindAsync(It.IsAny <Guid>(), It.IsAny <CancellationToken>())).ReturnsAsync(friendMock.Object);

            _friendRepositoryMock
            .Setup(x => x.Delete(It.IsAny <Friend>()));

            _friendRepositoryMock
            .Setup(x => x.UnitOfWork.SaveAsync(It.IsAny <CancellationToken>()));

            var handler = GetHandler();

            var command = new DeleteFriendCommand(Guid.NewGuid());

            await handler.Handle(command, default);

            _friendRepositoryMock
            .Verify(x => x.FindAsync(It.Is <Guid>(f => f.Equals(command.Id)), It.IsAny <CancellationToken>()));

            _friendRepositoryMock
            .Verify(x => x.Delete(It.Is <Friend>(f => f.Equals(friendMock.Object))));

            _friendRepositoryMock.Verify(x => x.UnitOfWork.SaveAsync(It.IsAny <CancellationToken>()));
        }
        public async Task <IActionResult> Delete(Guid id)
        {
            var command = new DeleteFriendCommand {
                Id = id
            };
            var result = _deleteHandler.Handle(command);

            return(await Response(result, _handler.Notifications));
        }
        public async Task <BodyResponse <NullBody> > Handle(DeleteFriendCommand request, CancellationToken cancellationToken)
        {
            using (var locker = _redis.Locker(KeyGenHelper.GenUserKey(request.Id, "FriendInfo")))
                using (var lockerFriend = _redis.Locker(KeyGenHelper.GenUserKey(request.FriendId, "FriendInfo")))
                {
                    await Task.WhenAll(_redis.DeleteFriend(request.Id, request.FriendId), _friendRepository.DeleteFriend(request.Id, request.FriendId));

                    return(new BodyResponse <NullBody>(StatusCodeDefines.Success));
                }
        }
Example #4
0
        public async Task ShouldDeleteFriend()
        {
            var entity = await FindAsync <IFriendRepository, Friend>(_entity.Id);

            entity.Should().NotBeNull();
            entity.Name.Should().Be("Bruce Wayne");

            var cmd = new DeleteFriendCommand(_entity.Id);

            await SendAsync(cmd);

            entity = await FindAsync <IFriendRepository, Friend>(_entity.Id);

            entity.Should().BeNull();
        }
Example #5
0
        public void ShouldThrowMessageFriendNotFound()
        {
            GenerateMock();

            _friendRepositoryMock
            .Setup(x => x.FindAsync(It.IsAny <Guid>(), It.IsAny <CancellationToken>()));

            var handler = GetHandler();

            var command = new DeleteFriendCommand(Guid.NewGuid());

            FluentActions.Invoking(async() => await handler.Handle(command, default))
            .Should()
            .Throw <NotFoundException>().WithMessage("Friend not found!");

            _friendRepositoryMock
            .Verify(x => x.FindAsync(It.Is <Guid>(f => f.Equals(command.Id)), It.IsAny <CancellationToken>()));
        }
Example #6
0
        public async Task <ValidationResult> Delete(Guid id)
        {
            var deleteCommand = new DeleteFriendCommand(id);

            return(await _mediator.SendCommand(deleteCommand));
        }