public void FindOrDefault_ShouldFind() { //Arrange ThermometerHandler th = new ThermometerHandler(new ThermometerQuestion("/abc"), question => "def?"); ThermometerRouteHandlerPool tp = new ThermometerRouteHandlerPool(); tp.Add(th); //Act //Assert Assert.AreEqual(th,tp.FindOrDefault("/abc")); Assert.IsNull(tp.FindOrDefault("/def")); }
public void FindOrDefault_ShouldFind() { //Arrange ThermometerHandler th = new ThermometerHandler(new ThermometerQuestion("/abc"), question => "def?"); ThermometerRouteHandlerPool tp = new ThermometerRouteHandlerPool(); tp.Add(th); //Act //Assert Assert.AreEqual(th, tp.FindOrDefault("/abc")); Assert.IsNull(tp.FindOrDefault("/def")); }
public override async Task Invoke(IOwinContext context) { var handler = _handlerSet.FindOrDefault(context.Request.Path.ToString()); if (handler != null) { try { var result = handler.Handler(context.Request.ToThermometerQuestion()) ?? new { }; context.Response.WriteAsJson(result); await Next.Invoke(context); } catch (Exception e) { context.Response.StatusCode = (int)HttpStatusCode.InternalServerError; var result = new { exception = e.ToString() }; context.Response.WriteAsJson(result); } } else { // Returns 404 context.Response.StatusCode = (int)HttpStatusCode.NotFound; } }