コード例 #1
0
        public async Task <IActionResult> GetRecommendations(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = "outreachRecommendations")] HttpRequest req,
            ILogger log)
        {
            log.LogInformation($"GetOutreachRecommendationsFunc triggered at {DateTime.UtcNow}");

            var zipCodes = req.Query["zipCodes"] as IEnumerable <string>;
            var cities   = req.Query["cities"] as IEnumerable <string>;

            var query = new GetOutreachRecommendations.Query
            {
                Cities   = cities,
                ZipCodes = zipCodes
            };

            // TODO - Define custom exceptions or result messages; Error model
            try
            {
                var result = await mediator.Send(query);

                return(new OkObjectResult(result));
            }
            catch (Exception exception)
            {
                log.LogError($"Exception: {exception.StackTrace}");
                return(new BadRequestObjectResult(exception.Message));
            }
        }
コード例 #2
0
        public async Task Handle_Returns_Recommendations_ByZip()
        {
            // Arrange
            var existingRecommendations = OutreachRecommendationsBuilder
                                          .Randomized()
                                          .BuildAsList();

            var query = new GetOutreachRecommendations.Query
            {
                ZipCodes = new List <string> {
                    "54022", "55401"
                },
                Cities = new List <string> {
                    "River Falls", "Minneapolis"
                }
            };

            mockOutreachRecommendationsRepository
            .Setup(r => r.Get(query.ZipCodes, query.Cities))
            .ReturnsAsync(existingRecommendations);

            // Act
            var returnedRecommendations = await handler.Handle(query, CancellationToken.None);

            // Assert
            Assert.Equal(existingRecommendations, returnedRecommendations);
            mockOutreachRecommendationsRepository.Verify();
        }
コード例 #3
0
        public async Task Handle_ThrowsArgumentException_NoSearchCriteria()
        {
            // Arrange
            var query = new GetOutreachRecommendations.Query
            {
                ZipCodes = Enumerable.Empty <string>(),
                Cities   = Enumerable.Empty <string>()
            };

            // Act
            var exception = await Assert.ThrowsAsync <ArgumentException>(async()
                                                                         => await handler.Handle(query, CancellationToken.None));

            // Assert
            Assert.Equal("Must provide at least one city or zipCode", exception.Message);
        }