Пример #1
0
        public async Task RickQuery_GetRickDetails()
        {
            var mapper = new Mock <IMapper>();

            var dbContext = new Mock <RickLocalizationContext>();

            var _mockSet = new Mock <DbSet <Domain.Entities.Rick> >();

            dbContext.Setup(c => c.Set <Domain.Entities.Rick>()).Returns(_mockSet.Object);

            var repository = new Mock <IRepository <Domain.Entities.Rick> >();

            mapper.Setup(x => x.Map(It.IsAny <Domain.Entities.Rick>(), It.IsAny <RickDetailsQueryResponse>())).Returns(new RickDetailsQueryResponse());

            var handler = new Mock <RickDetailsQueryHandle>(repository.Object, mapper.Object);

            RickDetailsQueryRequest query = new RickDetailsQueryRequest()
            {
                RickId = 1
            };

            var response = await handler.Object.Handle(query, default(CancellationToken));

            Assert.IsType <RickDetailsQueryResponse>(response);
        }
Пример #2
0
        public async Task <IActionResult> GetById(
            [FromServices] IMediator mediator,
            [FromServices] ILogger <RickController> _logger,
            int rickId)
        {
            try
            {
                _logger.LogInformation($"Get details by rickId: {rickId}");
                var command = new RickDetailsQueryRequest(rickId);
                var result  = await mediator.Send(command);

                return(Ok(result));
            }
            catch (Exception ex)
            {
                _logger.LogInformation(ex.Message);

                return(BadRequest(StatusCodes.Status400BadRequest));
            }
        }