public async Task <SimpleResponse <Member> > Handle(GetMemberByEmailQuery request,
                                                            CancellationToken cancellationToken)
        {
            var member = await _memberService.GetMemberByEmail(request.Email);

            if (member == null)
            {
                throw new BusinessException("Cannot find member for email {email}",
                                            BusinessErrors.ResourceNotFound("member", "Email is not found"),
                                            request.Email);
            }
            return(SimpleResponse <Member> .Create(member));
        }
Example #2
0
        public async Task GivenGlobalExceptionHandler_WhenBusinessExceptionRaised_IfErrorIsResourceNotFound_ShouldSendResourceNotFound()
        {
            // assign
            var context    = new DefaultHttpContext();
            var parameters = new object[] { };
            var ex         = new BusinessException("Some Exception", BusinessErrors.ResourceNotFound("Not Found", "Not Found"), parameters);

            _requestDelegate.Invoke(Arg.Any <HttpContext>()).Returns(callInfo => throw ex);

            // act
            await _handler.Invoke(context);

            // assert
            AssertLogging(LogLevel.Warning, ex.Message, null);
            await AssertHttpResponse(context, HttpStatusCode.NotFound, ex.BusinessErrorMessage);
        }