コード例 #1
0
        public async Task <ActionResult> UpdateFriendshipStatus([FromRoute] int friendshipId, [FromBody] UpdateFriendshipStatusBody model, CancellationToken cancellationToken = default)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            FriendshipExistsQuery existsQuery = new FriendshipExistsQuery {
                FriendshipId = friendshipId
            };

            bool exists = await _mediator.Send(existsQuery, cancellationToken);

            if (!exists)
            {
                return(NotFound(new ErrorResource
                {
                    StatusCode = StatusCodes.Status404NotFound,
                    Message = $"Friendship with ID '{friendshipId}' does not exist"
                }));
            }

            UpdateFriendshipStatusCommand updateCommand = new UpdateFriendshipStatusCommand
            {
                FriendshipId       = friendshipId,
                FriendshipStatusId = model.FriendshipStatusId
            };

            await _mediator.Send(updateCommand, cancellationToken);

            return(NoContent());
        }
コード例 #2
0
        public async Task FriendshipExistsQueryHandler_ShouldReturnFalse_WhenFriendshipDoesNotExist()
        {
            // Arrange
            FriendshipExistsQuery request = new FriendshipExistsQuery {
                FriendshipId = 6531
            };

            _unitOfWorkMock
            .Setup(m => m.Friendships.Exists(It.IsAny <int>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(false);

            FriendshipExistsQuery.Handler handler = new FriendshipExistsQuery.Handler(_unitOfWorkMock.Object);

            // Act
            bool exists = await handler.Handle(request);

            // Assert
            Assert.False(exists);
        }