private static HttpResponseMessage ExecProductServiceFunc(Func <ProductService, HttpResponseMessage> func, TraceWriter log) { try { return(func.Invoke(new ProductService(new ResourceService()))); } catch (CannotGetResourceException e) { log.Error(e.Message, e); return(HttpResponseBuilder <string> .Build(HttpStatusCode.ServiceUnavailable, e.Message)); } catch (System.Exception e) { log.Error(e.Message, e); return(HttpResponseBuilder <string> .Build(HttpStatusCode.InternalServerError, e.Message)); } }
public static IHttpClientWrapper MockHttpClientWrapper() { var httpClientWrapper = new Mock <IHttpClientWrapper>(); httpClientWrapper .Setup(x => x.GetAsync(It.IsRegex("competitions$"))) .Returns(() => Task.FromResult(HttpResponseBuilder.Build(ServiceResponses.Competitions.All147Competitions))); httpClientWrapper .Setup(x => x.GetAsync(It.IsRegex("\\/teams"))) .Returns(() => Task.FromResult(HttpResponseBuilder.Build(ServiceResponses.Competitions.CompetitionTeams))); httpClientWrapper .Setup(x => x.GetAsync(It.IsRegex("teams\\/"))) .Returns(() => Task.FromResult(HttpResponseBuilder.Build(ServiceResponses.Teams.TeamDetail))); return(httpClientWrapper.Object); }
public static HttpResponseMessage TrolleyCalculator2([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = RouteTrolleyCalculator2)] HttpRequestMessage req, TraceWriter log) { log.Verbose($"HTTP trigger {RouteTrolleyCalculator} function processed a request."); return(ExecProductServiceFunc(service => HttpResponseBuilder <decimal> .Build(service.GetMinPriceAsDecimal(RequestUtil.GetEntity <TrolleyCalculatorInput>(req))), log)); }
public static HttpResponseMessage GetProducts([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = RouteProducts)] HttpRequestMessage req, TraceWriter log) { log.Verbose($"HTTP trigger {RouteProducts} function processed a request."); return(ExecProductServiceFunc(service => HttpResponseBuilder <List <Product> > .Build(service.GetProducts(RequestUtil.GetSortOption(req))), log)); }
public static HttpResponseMessage GetUser([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = RouteAnswersUser)] HttpRequestMessage req, TraceWriter log) { log.Verbose($"HTTP trigger {RouteAnswersUser} function processed a request."); return(HttpResponseBuilder <User> .Build(new UserService().GetUser())); }