예제 #1
0
        private async void HTMLViewControl_Load(object sender, EventArgs e)
        {
            try
            {
                var htmlProcessor = new HTMLProcessor(pageUri);
                var titleTagText  = await htmlProcessor.GetTitleTag();

                var anchorTagsText = string.Join("\n\n", await htmlProcessor.GetAnchorTags());
                var scriptTagsText = string.Join("\n\n", await htmlProcessor.GetScriptTags());

                if ((new[] { titleTagText, anchorTagsText, scriptTagsText }).All(string.IsNullOrEmpty))
                {
                    errorMsgLabel.Text = $"I genuinely believe \"{pageUri}\" isn't a web page";
                    SwitchState(WebCodeViewState.Error);
                }
                else
                {
                    titleHtmlTextBox.SetHTML(titleTagText);
                    linksHtmlTextBox.SetHTML(anchorTagsText);
                    scriptsHtmlTextBox.SetHTML(scriptTagsText);
                    SwitchState(WebCodeViewState.PageAvailable);
                }
            }
            catch (InvalidOperationException)
            {
                errorMsgLabel.Text = "An invalid request URI was provided.The request URI must be an absolute URI.\n e.g http://google.com";
                SwitchState(WebCodeViewState.Error);
            }
            catch (Exception ex)
            {
                errorMsgLabel.Text = ex.Message;
                SwitchState(WebCodeViewState.Error);
            }
        }
예제 #2
0
        public void ShouldFormatWhenNullObjectIsPassed()
        {
            string expected = "<html><body>data missing...</body></html>";
            CatNamesByOwnerGender viewModel = new CatNamesByOwnerGender();

            viewModel = null;
            string actual = HTMLProcessor.FormatHTML(viewModel);

            Assert.AreEqual(expected, actual);
        }
예제 #3
0
        private string ProcessResults(List <PetOwner> owners)
        {
            owners = PetProcessor.RemoveOwnersWithoutPets(owners);
            owners = PetProcessor.GetOwnersByPetType(owners, Pets.cat);

            CatNamesByOwnerGender catNamesViewModel = CatProcessor.LoadCatNamesByOwnerGender(owners);

            catNamesViewModel = CatProcessor.SortCatNames(catNamesViewModel);

            return(HTMLProcessor.FormatHTML(catNamesViewModel));
        }
예제 #4
0
        public void ShouldFormatWhenNonNullObjectIsPassed()
        {
            string expected = "<html><body><h5>a</h5><ul><li>apple</li><li>apricots</li></ul></body></html>";
            CatNamesByOwnerGender viewModel = new CatNamesByOwnerGender();

            viewModel.Add("a", new List <string> {
                "apple", "apricots"
            });
            string actual = HTMLProcessor.FormatHTML(viewModel);

            Assert.AreEqual(expected, actual);
        }