Beispiel #1
0
        public void Setup()
        {
            var testReport = new[] { "1721", "979", "366", "299", "675", "1456" };

            var mockPuzzleInput = new Mock <IPuzzleInput>();

            mockPuzzleInput.Setup(p => p.GetPuzzleInputAsArray(It.IsAny <string>())).Returns(testReport);

            _reportAnalyser = new ReportAnalyser(mockPuzzleInput.Object);
        }
        private static string CompareReport(HttpContext context)
        {
            string       ret      = string.Empty;
            Guid         id       = MiniProfiler.Settings.Storage.List(1).FirstOrDefault();
            MiniProfiler profiler = MiniProfiler.Settings.Storage.Load(id);

            if (profiler != null)
            {
                List <ReportAnalyser.SavedTimingsData> data = ReportAnalyser.CompareTimings(profiler.Root);
                ret = CompareResultPage(context, data);
            }

            return(ret);
        }
Beispiel #3
0
 public void Then_the_correct_answer_is_found()
 {
     Assert.That(ReportAnalyser.MultiplyReportValues(_reportAnalyser.FindThreeValuesTotalling(2020)),
                 Is.EqualTo(241861950));
 }
        /// <summary>
        /// Handles rendering a previous MiniProfiler session, identified by its "?id=GUID" on the query.
        /// </summary>
        private static string Results(HttpContext context, bool saveReport = false)
        {
            // when we're rendering as a button/popup in the corner, we'll pass ?popup=1
            // if it's absent, we're rendering results as a full page for sharing
            var isPopup = !string.IsNullOrWhiteSpace(context.Request["popup"]);

            // this guid is the MiniProfiler.Id property
            // if this guid is not supplied, the last set of results needs to be
            // displayed. The home page doesn't have profiling otherwise.
            Guid id;

            if (!Guid.TryParse(context.Request["id"], out id))
            {
                id = MiniProfiler.Settings.Storage.List(1).FirstOrDefault();
            }

            if (id == default(Guid))
            {
                return(isPopup ? NotFound(context) : NotFound(context, "text/plain", "No Guid id specified on the query string"));
            }

            MiniProfiler.Settings.EnsureStorageStrategy();
            var profiler = MiniProfiler.Settings.Storage.Load(id);

            var    provider = WebRequestProfilerProvider.Settings.UserProvider;
            string user     = null;

            if (provider != null)
            {
                user = provider.GetUser(context.Request);
            }

            MiniProfiler.Settings.Storage.SetViewed(user, id);

            if (profiler == null)
            {
                return(isPopup ? NotFound(context) : NotFound(context, "text/plain", "No MiniProfiler results found with Id=" + id.ToString()));
            }

            bool needsSave = false;

            if (profiler.ClientTimings == null)
            {
                profiler.ClientTimings = ClientTimings.FromRequest(context.Request);
                if (profiler.ClientTimings != null)
                {
                    needsSave = true;
                }
            }

            if (profiler.HasUserViewed == false)
            {
                profiler.HasUserViewed = true;
                needsSave = true;
            }

            if (needsSave)
            {
                MiniProfiler.Settings.Storage.Save(profiler);
            }


            var authorize = MiniProfiler.Settings.Results_Authorize;


            if (authorize != null && !authorize(context.Request))
            {
                context.Response.ContentType = "application/json";
                return("hidden".ToJson());
            }

            if (saveReport)
            {
                ReportAnalyser.SaveCurrentTimings(profiler.Root);
            }

            return(isPopup ? ResultsJson(context, profiler) : ResultsFullPage(context, profiler));
        }