public Result Get(string url) { if (string.IsNullOrWhiteSpace(url)) { return(null); } if (_cache.TryGetValue(url, out Result result)) { result.CacheHit = true; return(result); } Article article = Reader.ParseArticle(url); if (article == null) { return(null); } result = ResultMaker.FromArticle(article); _cache.Set(url, result, _cacheEntryOptions); return(result); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } ResultMaker.Init(); app.UseDefaultFiles(); app.UseStaticFiles(); app.UseStatusCodePages(); app.Run(async(context) => { if (context.Request.Path == "/result.html" && context.Request.Method == "POST") { TagBuilder page = new TagBuilder("html"); TagBuilder body = new TagBuilder("body"); string source = context.Request.Form["source"]; string test = context.Request.Form["test"]; ResultMaker rm = new ResultMaker(source, test); if (!rm.isInitSuccess) { body.InnerHtml.Append(rm.InitFailLog); } else { rm.runProgram(); foreach (string line in rm.getMemoryLog().Split('\n')) { body.InnerHtml.Append(line); body.InnerHtml.AppendHtmlLine("<br />"); } } page.InnerHtml.AppendHtml(body); using (StringWriter writer = new StringWriter()) { page.WriteTo(writer, HtmlEncoder.Default); await context.Response.WriteAsync(writer.ToString()); } } else { context.Response.StatusCode = 404; } }); }
public void GettingCalculatedData() { //Arrange IResultMaker resultMaker = new ResultMaker(); //Act var simpledict = new Dictionary <string, decimal>() { { "Adam_Igor", 1.10m }, { "Heniek_Tomek", 3.20m } }; var result = resultMaker.PrepareResult(simpledict); //Assert Assert.IsNotNull(result); Assert.Contains("Adam should return Igor 1,10zł.", result); Assert.Contains("Heniek should return Tomek 3,20zł.", result); }