예제 #1
0
        public async Task <ActionResult> UserExists([FromQuery] UserExistsQueryParams queryParams, CancellationToken cancellationToken = default)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            // Check whether user name or e-mail exists
            UserNameOrEmailExistsQuery existsQuery = _mapper.Map <UserExistsQueryParams, UserNameOrEmailExistsQuery>(queryParams);

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

            if (exists)
            {
                return(Ok());
            }

            return(NotFound());
        }
예제 #2
0
        public async Task UserExists_ShouldReturnNotFoundResult_WhenUserDoesNotExist()
        {
            // Arrange
            UserExistsQueryParams queryParams = new UserExistsQueryParams
            {
                UserName = "******",
                Email    = "*****@*****.**"
            };

            _mediatorMock
            .Setup(m => m.Send(It.IsAny <UserNameOrEmailExistsQuery>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(false);

            UserController controller = new UserController(_mediatorMock.Object, _mapperMock);

            // Act
            ActionResult response = await controller.UserExists(queryParams);

            // Assert
            Assert.IsType <NotFoundResult>(response);
        }