Exemplo n.º 1
0
        private void PrototypeApp_NewPageLoaded(ISutApp src, ISutPage page)
        {
            if (page == null)
            {
                return;
            }
            var symbols = FlowActionTagHelper.DesignerOnlySymbols;
            var content = page.Document.Body.InnerHtml;
            var errors  = new List <string>();

            foreach (var name in symbols)
            {
                if (content.Contains(name, StringComparison.InvariantCultureIgnoreCase))
                {
                    errors.Add($"Tag reserved symbol named: \"{name}\" should not be in the generated document");
                }
            }

            if (errors.Any())
            {
                Assert.Fail(string.Join(Environment.NewLine, errors));
            }
        }
Exemplo n.º 2
0
        public static bool IsInBlueFlow(this ISutPage src)
        {
            var flowPageId = "BlueFlowPage";

            return(src.IsInFlow(flowPageId));
        }
Exemplo n.º 3
0
 public static bool IsInFlow(this ISutPage src, string flowPageId)
 {
     return(src.Document.QuerySelector("body > div")?.Id == flowPageId);
 }
Exemplo n.º 4
0
        public static bool IsInModelTesterFlowPageFlow(this ISutPage src)
        {
            var flowPageId = "ModelTesterFlowPage";

            return(src.IsInFlow(flowPageId));
        }
Exemplo n.º 5
0
        public static bool IsInContainersFlow(this ISutPage src)
        {
            var flowPageId = "ContainersFlowPage";

            return(src.IsInFlow(flowPageId));
        }
Exemplo n.º 6
0
        public async Task <ISutPage> ResolvePage(HttpResponseMessage message)
        {
            using (App.Profiler.RecordStep($"{GetType().Name}.{nameof(ResolvePage)}"))
            {
                Assert.AreEqual(HttpStatusCode.OK, message.StatusCode);
                IHtmlDocument doc;
                using (App.Profiler.RecordStep($"{GetType().Name}.{nameof(HtmlDocumentExtensions.ParseDocumentAsync)}"))
                {
                    doc = await message.ParseDocumentAsync(App.Profiler);
                }

                using (App.Profiler.RecordStep("DoResolve"))
                {
                    ISutPage result = null;


                    result = Resolve(doc);
                    if (result == null)
                    {
                        throw new NotImplementedException(
                                  $"Missing parser for current page: {Environment.NewLine}{doc.Body.InnerHtml}");
                    }

                    return(result);
                }
            }

            ISutPage Resolve(IHtmlDocument htmlDocument)
            {
                // ReSharper disable once ConvertToLocalFunction
                Func <ISutPage, bool> predicate = x => x.TryParse(htmlDocument);
                ISutPage sutPage = null;

#if DEBUG
                var candidates = _pagesLazy.Value.Where(predicate).ToArray();
                if (candidates.Length == 1)
                {
                    sutPage = candidates.Single();
                }
                else if (candidates.Length > 1)
                {
                    var items = candidates.Where(x => x.IsContainer()).ToArray();
                    if (items.Length > 1)
                    {
                        throw new InvalidOperationException(
                                  $"found {candidates.Length} pages being containers {string.Join(',', items.Select(x => x.GetType().FullName))} container items on: {Environment.NewLine}{htmlDocument.Body.InnerHtml}");
                    }

                    if (items.Length == 0)
                    {
                        throw new InvalidOperationException(
                                  $"found {candidates.Length} pages but none of the is a container items on: {Environment.NewLine}{htmlDocument.Body.InnerHtml}");
                    }


                    sutPage = items.Single();
                }
#else
                sutPage = _pagesLazy.Value.FirstOrDefault(predicate);
#endif
                return(sutPage);
            }
        }