Example #1
0
 public static HtmlTextWriter AddEnvironment(this HtmlTextWriter writer, string id = "")
 {
     writer.AddAttribute(HtmlTextWriterAttribute.Id, id.Equals("") ? "table-cell" : id);
     writer.AddStyleAttribute(HtmlTextWriterStyle.Padding, "20px");
     writer.RenderBeginTag(HtmlTextWriterTag.Div);
     writer.AddTag(HtmlTextWriterTag.B, "Environment information: ");
     writer.RenderBeginTag(HtmlTextWriterTag.P);
     writer.Write(Bullet.HtmlCode + "CLR version: " + Environment.Version);
     writer.RenderEndTag();
     writer.RenderBeginTag(HtmlTextWriterTag.P);
     writer.Write(Bullet.HtmlCode + "OS version: " + Environment.OSVersion.VersionString);
     writer.RenderEndTag();
     writer.RenderBeginTag(HtmlTextWriterTag.P);
     writer.Write(Bullet.HtmlCode + "Platform: " + Environment.OSVersion.Platform);
     writer.RenderEndTag();
     writer.RenderBeginTag(HtmlTextWriterTag.P);
     writer.Write(Bullet.HtmlCode + "Machine name: " + Environment.MachineName);
     writer.RenderEndTag();
     writer.RenderBeginTag(HtmlTextWriterTag.P);
     writer.Write(Bullet.HtmlCode + "User domain: " + Environment.UserDomainName);
     writer.RenderEndTag();
     writer.RenderBeginTag(HtmlTextWriterTag.P);
     writer.Write(Bullet.HtmlCode + "User: " + Environment.UserName);
     writer.RenderEndTag();
     writer.RenderEndTag();//DIV
     return(writer);
 }
Example #2
0
        public static HtmlTextWriter AddTestEvents(this HtmlTextWriter writer, TestInformations test, string id = "")
        {
            writer.AddAttribute(HtmlTextWriterAttribute.Id, id.Equals("") ? "table-cell" : id);
            writer.AddStyleAttribute(HtmlTextWriterStyle.Padding, "20px");
            writer.RenderBeginTag(HtmlTextWriterTag.Div);
            var events = test.Events.OrderBy(x => x.Started);

            foreach (var testEvent in events)
            {
                writer.RenderBeginTag(HtmlTextWriterTag.P);
                writer.AddTag(HtmlTextWriterTag.B, "Test event: ");
                writer.Write(testEvent.Name);
                writer.RenderEndTag(); //P

                writer.RenderBeginTag(HtmlTextWriterTag.P);
                writer.Write(Bullet.HtmlCode + "Started: " + testEvent.Started.ToString("dd.MM.yy HH:mm:ss.fff"));
                writer.RenderEndTag();
                writer.RenderBeginTag(HtmlTextWriterTag.P);
                writer.Write(Bullet.HtmlCode + "Finished: " + testEvent.Finished.ToString("dd.MM.yy HH:mm:ss.fff"));
                writer.RenderEndTag();
                writer.RenderBeginTag(HtmlTextWriterTag.P);
                writer.Write(Bullet.HtmlCode + "Duration: " + testEvent.DurationString);
                writer.RenderEndTag();
            }
            if (!events.Any())
            {
                writer.Write("There are no test events in this test");
            }
            writer.RenderEndTag();//DIV
            return(writer);
        }
        public static HtmlTextWriter AddTestResult(this HtmlTextWriter writer, TestInformations test, string id = "")
        {
            writer.AddAttribute(HtmlTextWriterAttribute.Id, id.Equals("") ? "table-cell" : id);
            writer.AddStyleAttribute(HtmlTextWriterStyle.Padding, "20px");
            writer.RenderBeginTag(HtmlTextWriterTag.Div);

            writer.RenderBeginTag(HtmlTextWriterTag.P);
            writer.AddTag(HtmlTextWriterTag.B, "Test full name: ");
            writer.Write(test.FullName);
            writer.RenderEndTag(); //P

            writer.RenderBeginTag(HtmlTextWriterTag.P);
            writer.AddTag(HtmlTextWriterTag.B, "Test name: ");
            writer.Write(test.Name);
            writer.RenderEndTag(); //P

            writer.RenderBeginTag(HtmlTextWriterTag.P);
            writer.AddTag(HtmlTextWriterTag.B, "Test duration: ");
            writer.Write(TimeSpan.FromSeconds(test.TestDuration).ToString(@"hh\:mm\:ss\:fff"));
            writer.RenderEndTag(); //P

            writer.RenderBeginTag(HtmlTextWriterTag.P);
            writer.AddTag(HtmlTextWriterTag.B, "Time period: ");
            var start = test.DateTimeStart.ToString("dd.MM.yy HH:mm:ss.fff");
            var end   = test.DateTimeFinish.ToString("dd.MM.yy HH:mm:ss.fff");

            writer.Write(start + " - " + end);
            writer.RenderEndTag(); //P

            writer.AddStyleAttribute(HtmlTextWriterStyle.BackgroundColor, test.GetColor());
            writer.RenderBeginTag(HtmlTextWriterTag.P);
            writer.RenderBeginTag(HtmlTextWriterTag.B);
            writer.Write("Test result: ");
            writer.RenderEndTag(); //B
            writer.Write(test.Result);
            writer.RenderEndTag(); //P

            writer.RenderEndTag(); //DIV
            return(writer);
        }
 public static HtmlTextWriter AddFailure(this HtmlTextWriter writer, TestInformations test, string id = "")
 {
     writer.AddAttribute(HtmlTextWriterAttribute.Id, id.Equals("") ? "table-cell" : id);
     writer.AddStyleAttribute(HtmlTextWriterStyle.Padding, "20px");
     writer.RenderBeginTag(HtmlTextWriterTag.Div);
     if (!test.IsSuccess())
     {
         writer.RenderBeginTag(HtmlTextWriterTag.P);
         writer.AddTag(HtmlTextWriterTag.B, "Message: ");
         writer.Write(NunitTestHtml.GenerateTxtView(test.TestMessage));
         writer.RenderEndTag(); //P
         writer.RenderBeginTag(HtmlTextWriterTag.P);
         writer.AddTag(HtmlTextWriterTag.B, "Stack trace: ");
         writer.Write(NunitTestHtml.GenerateTxtView(test.TestStackTrace));
         writer.RenderEndTag(); //P
     }
     else
     {
         writer.Write("Test was successful, there is no failure message");
     }
     writer.RenderEndTag();//DIV
     return(writer);
 }
Example #5
0
        public Tooltip(string tooltipText, string innerText, string backgroundColor, string id, double width, string href = "")
        {
            Style = GetStyle();

            var strWr = new StringWriter();

            using (var writer = new HtmlTextWriter(strWr))
            {
                writer.AddAttribute("data-tooltip", tooltipText);
                writer.AddAttribute(HtmlTextWriterAttribute.Class, "tooltip");
                writer.AddAttribute(HtmlTextWriterAttribute.Id, id);
                writer.AddStyleAttribute(HtmlTextWriterStyle.BackgroundColor, backgroundColor);
                writer.AddStyleAttribute(HtmlTextWriterStyle.Width, width.ToString("00.000", CultureInfo.InvariantCulture) + @"%");
                writer.RenderBeginTag(HtmlTextWriterTag.Div);

                if (!href.Equals(""))
                {
                    var button = new OpenButton("", href, backgroundColor);
                    writer.Write(button.ButtonHtml);
                }

                writer.AddStyleAttribute(HtmlTextWriterStyle.Display, "inline-block");
                writer.AddStyleAttribute(HtmlTextWriterStyle.Overflow, "hidden");
                writer.AddAttribute(HtmlTextWriterAttribute.Id, "tooltip-item-inner-text");
                writer.RenderBeginTag(HtmlTextWriterTag.A);
                if (innerText.Contains(Environment.NewLine))
                {
                    var lines = innerText.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
                    foreach (var line in lines)
                    {
                        writer.Write(line);
                        writer.AddTag(HtmlTextWriterTag.Br);
                    }
                }
                else
                {
                    writer.Write(innerText);
                }
                writer.RenderEndTag(); //A

                writer.RenderEndTag(); //DIV
            }

            HtmlCode = strWr.ToString();
        }
Example #6
0
 public static HtmlTextWriter AddOutput(this HtmlTextWriter writer, NunitGoTest nunitGoTest, string testOutput, string id = "")
 {
     writer.AddAttribute(HtmlTextWriterAttribute.Id, id.Equals("") ? "table-cell" : id);
     writer.AddStyleAttribute(HtmlTextWriterStyle.Padding, "20px");
     writer.RenderBeginTag(HtmlTextWriterTag.Div);
     if (nunitGoTest.HasOutput)
     {
         writer.RenderBeginTag(HtmlTextWriterTag.P);
         writer.AddTag(HtmlTextWriterTag.B, "Test output: ");
         writer.Write(NunitTestHtml.GenerateTxtView(testOutput));
         writer.RenderEndTag(); //P
     }
     else
     {
         writer.Write("Test output is empty");
     }
     writer.RenderEndTag();//DIV
     return(writer);
 }
Example #7
0
        public static string GetMailBody(NunitGoTest nunitGoTest, bool addLinks,
                                         bool isEventEmail = false, string eventName = "", TestEvent previousRunEvent = null)
        {
            var strWr = new StringWriter();

            using (var writer = new HtmlTextWriter(strWr))
            {
                writer.Write("<!DOCTYPE html>");
                writer.Write(Environment.NewLine);
                writer.RenderBeginTag(HtmlTextWriterTag.Head);
                writer.Tag(HtmlTextWriterTag.Meta, new Dictionary <string, string>
                {
                    { "http-equiv", "X-UA-Compatible" },
                    { "content", @"IE=edge" },
                    { "charset", "utf-8" }
                });
                writer.Tag(HtmlTextWriterTag.Title, "NUnitGo Email");
                writer.Tag(HtmlTextWriterTag.Style, new Dictionary <HtmlTextWriterAttribute, string>
                {
                    { HtmlTextWriterAttribute.Type, @"text/css" }
                });
                writer.Tag(HtmlTextWriterTag.Link, new Dictionary <HtmlTextWriterAttribute, string>
                {
                    { HtmlTextWriterAttribute.Rel, @"stylesheet" },
                    { HtmlTextWriterAttribute.Type, @"text/css" }
                });
                writer.RenderEndTag(); //HEAD

                writer.AddStyleAttribute(HtmlTextWriterStyle.BackgroundColor, Colors.White);
                writer.AddStyleAttribute(HtmlTextWriterStyle.Padding, "10px");
                writer.AddStyleAttribute("border", "10px solid " + Colors.TestBorderColor);
                writer.AddStyleAttribute(HtmlTextWriterStyle.Margin, "0px");
                writer.AddStyleAttribute(HtmlTextWriterStyle.Height, "100%");
                writer.AddStyleAttribute(HtmlTextWriterStyle.FontFamily, "Tahoma,Verdana,Segoe,sans-serif");
                writer.RenderBeginTag(HtmlTextWriterTag.Body);

                writer.AddStyleAttribute("box-sizing", "border-box");
                writer.AddStyleAttribute(HtmlTextWriterStyle.Overflow, "auto");
                writer.AddStyleAttribute(HtmlTextWriterStyle.Top, "0%");
                writer.AddStyleAttribute(HtmlTextWriterStyle.Height, "100%");
                writer.AddStyleAttribute(HtmlTextWriterStyle.Padding, "10px");
                writer.AddAttribute(HtmlTextWriterAttribute.Class, "test-window");
                writer.AddAttribute(HtmlTextWriterAttribute.Title, "Test");
                writer.RenderBeginTag(HtmlTextWriterTag.Div);

                writer.AddStyleAttribute(HtmlTextWriterStyle.Padding, "10px");
                writer.AddAttribute(HtmlTextWriterAttribute.Id, nunitGoTest.Guid.ToString());
                writer.RenderBeginTag(HtmlTextWriterTag.Div);

                writer.RenderBeginTag(HtmlTextWriterTag.P);
                writer.AddTag(HtmlTextWriterTag.B, "Test full name: ");
                writer.Write(nunitGoTest.FullName);
                writer.RenderEndTag(); //P

                writer.RenderBeginTag(HtmlTextWriterTag.P);
                writer.AddTag(HtmlTextWriterTag.B, "Test name: ");
                writer.Write(nunitGoTest.Name);
                writer.RenderEndTag(); //P

                if (isEventEmail && previousRunEvent != null)
                {
                    var currentEvent = nunitGoTest.Events.First(x => x.Name.Equals(eventName));
                    writer.RenderBeginTag(HtmlTextWriterTag.P);
                    writer.AddTag(HtmlTextWriterTag.B, "Event name: ");
                    writer.Write(currentEvent.Name);
                    writer.RenderEndTag(); //P
                    writer.RenderBeginTag(HtmlTextWriterTag.P);
                    writer.AddTag(HtmlTextWriterTag.B, string.Format("Current duration (event finished at {0}): ", currentEvent.Finished));
                    writer.Write(TimeSpan.FromSeconds(currentEvent.Duration).ToString(@"hh\:mm\:ss\:fff"));
                    writer.RenderEndTag(); //P
                    writer.RenderBeginTag(HtmlTextWriterTag.P);
                    writer.AddTag(HtmlTextWriterTag.B, string.Format("Previous duration (event finished at {0}): ", previousRunEvent.Finished));
                    writer.Write(TimeSpan.FromSeconds(previousRunEvent.Duration).ToString(@"hh\:mm\:ss\:fff"));
                    writer.RenderEndTag(); //P
                    writer.RenderBeginTag(HtmlTextWriterTag.P);
                    writer.AddTag(HtmlTextWriterTag.B, "Difference: ");
                    writer.Write(TimeSpan.FromSeconds(currentEvent.Duration - previousRunEvent.Duration).ToString(@"hh\:mm\:ss\:fff"));
                    writer.RenderEndTag(); //P
                }

                writer.AddStyleAttribute(HtmlTextWriterStyle.BackgroundColor, nunitGoTest.GetColor());
                writer.RenderBeginTag(HtmlTextWriterTag.P);
                writer.RenderBeginTag(HtmlTextWriterTag.B);
                writer.Write("Test result: ");
                writer.RenderEndTag(); //B
                writer.Write(nunitGoTest.Result);
                writer.RenderEndTag(); //P

                writer.RenderBeginTag(HtmlTextWriterTag.P);
                writer.AddTag(HtmlTextWriterTag.B, "Test duration: ");
                writer.Write(TimeSpan.FromSeconds(nunitGoTest.TestDuration).ToString(@"hh\:mm\:ss\:fff"));
                writer.RenderEndTag(); //P

                writer.RenderBeginTag(HtmlTextWriterTag.P);
                writer.AddTag(HtmlTextWriterTag.B, "Time period: ");
                var start = nunitGoTest.DateTimeStart.ToString("dd.MM.yy HH:mm:ss.fff");
                var end   = nunitGoTest.DateTimeFinish.ToString("dd.MM.yy HH:mm:ss.fff");
                writer.Write(start + " - " + end);
                writer.RenderEndTag(); //P

                writer.RenderBeginTag(HtmlTextWriterTag.P);
                writer.AddTag(HtmlTextWriterTag.B, "Screenshots: ");
                writer.Write(nunitGoTest.Screenshots.Count);
                writer.RenderEndTag(); //P

                var screens = nunitGoTest.Screenshots.OrderBy(x => x.Date);
                foreach (var screenshot in screens)
                {
                    writer.Write("Screenshot (Date: " + screenshot.Date.ToString("dd.MM.yy HH:mm:ss.fff") + "):");
                    writer.RenderBeginTag(HtmlTextWriterTag.Div);
                    writer.AddStyleAttribute(HtmlTextWriterStyle.Width, "inherited");
                    writer.AddAttribute(HtmlTextWriterAttribute.Src, @"cid:" + screenshot.Name);
                    writer.AddAttribute(HtmlTextWriterAttribute.Alt, screenshot.Name);
                    writer.RenderBeginTag(HtmlTextWriterTag.Img);
                    writer.RenderEndTag(); //IMG
                    writer.RenderEndTag(); //DIV
                }

                if (!nunitGoTest.IsSuccess())
                {
                    writer.RenderBeginTag(HtmlTextWriterTag.P);
                    writer.AddTag(HtmlTextWriterTag.B, "Stack trace: ");
                    writer.Write(NunitTestHtml.GenerateTxtView(nunitGoTest.TestStackTrace));
                    writer.RenderEndTag(); //P
                    writer.RenderBeginTag(HtmlTextWriterTag.P);
                    writer.AddTag(HtmlTextWriterTag.B, "Message: ");
                    writer.Write(NunitTestHtml.GenerateTxtView(nunitGoTest.TestMessage));
                    writer.RenderEndTag(); //P
                }

                if (addLinks)
                {
                    writer.RenderBeginTag(HtmlTextWriterTag.P);
                    writer.AddTag(HtmlTextWriterTag.B, "Test page: ");
                    writer.AddStyleAttribute("background", Colors.OpenLogsButtonBackground);
                    writer.AddStyleAttribute(HtmlTextWriterStyle.Width, "100%");
                    writer.AddStyleAttribute(HtmlTextWriterStyle.Color, "black");
                    writer.AddStyleAttribute(HtmlTextWriterStyle.TextDecoration, "none !important");
                    writer.AddAttribute(HtmlTextWriterAttribute.Href, nunitGoTest.TestHrefAbsolute);
                    writer.RenderBeginTag(HtmlTextWriterTag.A);
                    writer.Write(Environment.NewLine + "View on site");
                    writer.RenderEndTag(); //A
                    writer.RenderEndTag(); //P
                }

                writer.RenderEndTag(); //DIV
                writer.RenderEndTag(); //DIV

                writer.RenderEndTag(); //BODY

                writer.Write(Environment.NewLine);
                writer.Write("</html>");
                writer.Write(Environment.NewLine);
            }

            return(strWr.ToString());
        }