Exemplo n.º 1
0
 private void WriteLog(
     bool result,
     string question,
     string answers,
     ResultStatus closedQuestionsResultStatus,
     ResultStatus openQuestionsResultStatus,
     Dictionary <QuestionTypeEnum, Dictionary <string, AnswerRegister> > answersRegister)
 {
     if (AppSettings.Learning.SaveDebugLogs)
     {
         JsonSerializerOptions options = JsonService.GetJsonSerializerOptions(true, null);
         string logData = JsonSerializer.Serialize(
             new
         {
             Result   = result,
             Question = question,
             Answers  = answers,
             ClosedQuestionsProgress = closedQuestionsResultStatus.ToString(),
             OpenQuestionsProgress   = openQuestionsResultStatus.ToString(),
             AnswersRegister         = answersRegister
         },
             options
             );
         Logger.LogDebug(logData);
     }
 }
Exemplo n.º 2
0
        public override string ToString() // JSON format
        {
            StringWriter sw = new StringWriter();

            using (JsonWriter writer = new JsonTextWriter(sw))
            {
                writer.Formatting = Formatting.None;

                writer.WriteStartObject();
                writer.WritePropertyName("type");
                writer.WriteValue(Type);
                writer.WritePropertyName("key");
                writer.WriteValue(Key);
                writer.WritePropertyName("keyData");
                writer.WriteValue(KeyData);
                writer.WritePropertyName("sector");
                writer.WriteValue(Sector);
                writer.WritePropertyName("result");
                {
                    writer.WriteStartObject();
                    writer.WritePropertyName("status");
                    writer.WriteValue(ResultStatus.ToString());
                    writer.WriteEndObject();
                }
                //writer.WritePropertyName("expectedResult");
                //writer.WriteValue(true);
                writer.WriteEndObject();
            }
            return(sw.ToString());
        }
Exemplo n.º 3
0
        private void all_scenarios_with_status_other_than_STATUS_are_VISIBLE(ResultStatus status, [VisibleFormat] bool visible)
        {
            var elements = _driver.FindAllScenarios().Where(s => !s.HasClassName(status.ToString().ToLower())).ToArray();

            Assert.That(elements, Is.Not.Empty);
            Assert.That(elements.All(s => s.Displayed == visible));
        }
Exemplo n.º 4
0
 private static IHtmlNode GetStatus(ResultStatus status)
 {
     return(Html.Tag(HtmlTextWriterTag.Span)
            .Class("status " + GetStatusClass(status))
            .Content(status.ToString())
            .SpaceAfter());
 }
 public void NotifyScenarioFinished_should_print_notification_and_update_stats(ResultStatus status, int expectedFailures)
 {
     _subject.NotifyScenarioStart("name", "l");
     _console.Reset();
     _subject.NotifyScenarioFinished(CreateScenarioResult(status, "name"));
     Assert.That(_console.GetCapturedText(), Is.EqualTo(string.Format("Finished=1, Failed={0}, Pending=0: {1}: name\r\n", expectedFailures, status.ToString().ToUpperInvariant())));
 }
Exemplo n.º 6
0
        public override string ToString() // JSON format
        {
            StringWriter sw = new StringWriter();

            using (JsonWriter writer = new JsonTextWriter(sw))
            {
                writer.Formatting = Formatting.None;

                writer.WriteStartObject();
                writer.WritePropertyName("type");
                writer.WriteValue(Type);
                writer.WritePropertyName("block");
                writer.WriteValue(Block);
                writer.WritePropertyName("length");
                writer.WriteValue(Length);
                writer.WritePropertyName("result");
                {
                    writer.WriteStartObject();
                    writer.WritePropertyName("status");
                    writer.WriteValue(ResultStatus.ToString());
                    if (ResultStatus == ResultStatus.OK)
                    {
                        writer.WritePropertyName("data");
                        writer.WriteValue(Data);
                    }
                    writer.WriteEndObject();
                }
                //writer.WritePropertyName("expectedResult");
                //writer.WriteValue(true);
                writer.WriteEndObject();
            }
            return(sw.ToString());
        }
Exemplo n.º 7
0
        public static string ResultMsg(ResultStatus status)
        {
            var name  = status.ToString();
            var field = status.GetType().GetField(name);
            var att   = System.Attribute.GetCustomAttribute(field, typeof(DescriptionAttribute), false);

            return(att == null ? field.Name : ((DescriptionAttribute)att).Description);
        }
Exemplo n.º 8
0
    private static void SetStatus(TableRow row, ResultStatus status)
    {
        var c = new TableCell {
            Text = status.ToString()
        };

        row.Cells.Add(c);
    }
Exemplo n.º 9
0
        private void all_features_having_all_scenarios_of_status_are_VISIBLE(ResultStatus status, [VisibleFormat] bool visible)
        {
            var expected = new[] { "feature", status.ToString().ToLower() };
            var elements = _driver.FindFeatures().Where(f => f.GetClassNames().SequenceEqual(expected)).ToArray();

            Assert.That(elements, Is.Not.Empty);
            Assert.That(elements.All(s => s.Displayed == visible));
        }
Exemplo n.º 10
0
        public async Task WriteLogAsync(string jobName, string rowKey, string log, ResultStatus status, DateTimeOffset?finishAt)
        {
            var result = await FindResultAsync(jobName, rowKey);

            result.LogUri   = (await _blobs.UploadAsync(log, result.LogUri)).ToString();
            result.Status   = status.ToString();
            result.FinishAt = finishAt;

            await _results.UpdateAsync(result);
        }
Exemplo n.º 11
0
 public static DialogResult ErrorBox(ResultStatus op)
 {
     if (op != null)
     {
         return(MessageBox.Show(op.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error));
     }
     else
     {
         return(MessageBox.Show("Data is null at ErrorBox", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error));
     }
 }
Exemplo n.º 12
0
        public override void OnActionExecuting(ActionExecutingContext context)
        {
            MethodInfo method = (context.ActionDescriptor as ControllerActionDescriptor).MethodInfo;

            // 如果带有游客标记则不需要做验证判断
            if (method.HasAttribute <GuestAttribute>())
            {
                return;
            }

            //#1 从Http头中得到商户信息
            bool isSite = context.HttpContext.GetAuth(out string merchant, out string secretKey);

            if (!isSite)
            {
                context.Result = (ContentResult) new Result(false, ResultStatus.SecretKey.ToString());
                return;
            }
            int  siteId = merchant.GetValue <int>();
            Site site   = SiteAgent.Instance().GetSiteInfo(siteId);

            if (site == null || site.SecretKey != secretKey)
            {
                context.Result = (ContentResult) new Result(false, ResultStatus.SecretKey.ToString());
                return;
            }

            //#2 固定参数判断(自动在游戏中创建账户)
            string gameCode = context.HttpContext.Request.Form["GameCode"];
            string userName = context.HttpContext.Request.Form["UserName"];

            if (!string.IsNullOrEmpty(gameCode))
            {
                GameSetting game = GameAgent.Instance().GetGameSetting(gameCode);
                if (game == null)
                {
                    context.Result = (ContentResult) new Result(false, ResultStatus.NoGame.ToString());
                    return;
                }
                if (!string.IsNullOrEmpty(userName))
                {
                    ResultStatus registerStatus = APIAgent.Instance().Register(siteId, userName, game, out UserGame user);
                    if (registerStatus != ResultStatus.Success)
                    {
                        context.Result = (ContentResult) new Result(false, registerStatus.ToString());
                        return;
                    }
                    context.HttpContext.SetItem(user);
                }
                context.HttpContext.SetItem(game);
            }
            context.HttpContext.SetItem(site);
        }
Exemplo n.º 13
0
        private void UploadConfirmation_Load(object sender, EventArgs e)
        {
            ResultStatus cwd = this.Port.Cwd();

            if (cwd.Result == ResultStatus.Statuses.Success)
            {
                this.Path.Text = cwd.ToString().Replace("'", "");
                if (this.Path.Text == "")
                {
                    this.Path.Text = "/";
                }
            }
            else
            {
                Helpers.ErrorBox(cwd);
                return;
            }
        }
Exemplo n.º 14
0
        public override string ToString() // JSON format
        {
            StringWriter sw = new StringWriter();

            using (JsonWriter writer = new JsonTextWriter(sw))
            {
                writer.Formatting = Formatting.None;

                writer.WriteStartObject();
                writer.WritePropertyName("type");
                writer.WriteValue(Type);
                writer.WritePropertyName("mode");
                writer.WriteValue(Mode);
                writer.WritePropertyName("uid");
                writer.WriteValue(Uid);
                writer.WritePropertyName("result");
                {
                    writer.WriteStartObject();
                    writer.WritePropertyName("status");
                    writer.WriteValue(ResultStatus.ToString());
                    if (ResultStatus == ResultStatus.OK)
                    {
                        writer.WritePropertyName("uid");
                        writer.WriteValue(Uid);
                        writer.WritePropertyName("sak");
                        writer.WriteValue(Convert.ToBase64String(Util.HexStringToByteArray(Sak)));
                        writer.WritePropertyName("atqa");
                        writer.WriteValue(Convert.ToBase64String(Util.HexStringToByteArray(Atqa)));
                    }
                    //writer.WritePropertyName("expectedResult");
                    //writer.WriteValue(true);
                    writer.WriteEndObject();
                }
                writer.WriteEndObject();
            }
            return(sw.ToString());
        }
Exemplo n.º 15
0
 private static string GetStatusClass(ResultStatus status)
 {
     return(status.ToString().ToLowerInvariant());
 }
Exemplo n.º 16
0
 public void EndTask(string id, ResultStatus status)
 {
     var sql    = string.Format("Update FsFile set ConvertResult='{2}',ConvertTime='{1}' where ID = '{0}'", id, DateTime.Now, status.ToString());
     var db     = SqlHelper.Create(AppConfig.GetConnectionStrings("FileStore"));
     var reader = db.ExecuteNonQuery(sql);
 }
Exemplo n.º 17
0
 private static TagBuilder GetStatusFilter(ResultStatus value)
 {
     return(Html.Checkbox().Name("statusFilter").Attribute("data-filter-value", value.ToString().ToLower()).Checked().OnClick("applyFilter()").SpaceBefore());
 }
Exemplo n.º 18
0
        public void PresentQuestion(
            ModeEnum mode,
            Question question,
            ResultStatus closedQuestionsResultStatus,
            ResultStatus openQuestionsResultStatus,
            ResultStatus currentQuestionResultStatus,
            string answer           = "",
            bool beforeVerification = true)
        {
            int lineAfterRendering = 0;

            switch (mode)
            {
            case ModeEnum.Spelling:
                lineAfterRendering = 6;
                break;

            case ModeEnum.OnlyOpen:
                lineAfterRendering = 6;
                break;

            case ModeEnum.Full:
                lineAfterRendering = 7;
                break;
            }
            Console.SetCursorPosition(0, 0);
            if (beforeVerification)
            {
                Console.Write(" (Enter) Answer".PadRight(80));
            }
            else
            {
                Console.Write(" (Enter) Next question;");
                Console.Write(" o Override;");
                Console.Write(" r Restart;");
                Console.Write(" c Close;");
            }
            Console.WriteLine();
            Console.WriteLine();
            switch (mode)
            {
            case ModeEnum.Full:
                Console.Write($"  Closed questions result: ".PadRight(27));
                Console.WriteLine(closedQuestionsResultStatus.ToString(leftPad: 4).PadRight(80));
                Console.Write($"  Open questions result: ".PadRight(27));
                Console.WriteLine(openQuestionsResultStatus.ToString(leftPad: 4).PadRight(80));
                break;

            default:
                Console.Write($"  Result: ".PadRight(27));
                Console.WriteLine(openQuestionsResultStatus.ToString(leftPad: 4).PadRight(80));
                break;
            }
            Console.Write($"  Current question result: ".PadRight(27));
            Console.WriteLine(currentQuestionResultStatus.ToString(leftPad: 4).PadRight(80));
            Console.WriteLine();
            if (mode != ModeEnum.Spelling)
            {
                var previousForegroundColor = Console.ForegroundColor;
                Console.ForegroundColor = ConsoleColor.Blue;
                lineAfterRendering     += ShowMultilineText(
                    question.Content,
                    firstLineLeftIndendation: 2,
                    nextLinesLeftIndendation: 2,
                    maxNumOfChars: 78
                    );
                Console.ForegroundColor = previousForegroundColor;
            }
            if (question.PossibleAnswers != null && question.PossibleAnswers.Count > 0)
            {
                for (int i = 0; i < question.PossibleAnswers.Count; i++)
                {
                    Console.Write($"  {i + 1}. ");
                    lineAfterRendering += ShowMultilineText(
                        question.PossibleAnswers[i],
                        firstLineLeftIndendation: 0,
                        nextLinesLeftIndendation: 5,
                        maxNumOfChars: 75
                        );
                }
            }
            Console.WriteLine("  ".PadRight(80, '-'));
            Console.Write("  # ".PadRight(80));
            if (answer.Length > 0)
            {
                Console.SetCursorPosition(4, lineAfterRendering);
                Console.Write(answer);
            }
            Console.WriteLine();
            for (int i = 0; i < 12; i++)
            {
                Console.WriteLine(" ".PadRight(80));
            }
            Console.SetCursorPosition(4, lineAfterRendering);
        }
        public static void Execute()
        {
            IList <string> testPlans;
            var            stopWatch     = new Stopwatch();
            ResultStatus   lastRunStatus = ResultStatus.Inconclusive;

            Log.Block("Marathon Engine", "Opened");
            Log.Block("Verify UFT Heart Beat", "Opened");
            Launch();
            Log.Block("Verify UFT Heart Beat", "Closed");
            Log.Block("Set Project WorkSpace", "Opened");
            Utilities.SetProjectWorkSpace();
            Log.Block("Set Project WorkSpace", "Closed");
            Log.Block("Get Test Plans", "Opened");
            if (File.Exists(TestConfiguration.TestDataDrivenFile))
            {
                testPlans = Utilities.GetTestListPlans(true);
            }
            else
            {
                testPlans = Utilities.GetTestListPlans();
            }
            Log.Block("Get Test Plans", "Closed");
            Log.Block("Create Test Run Session Folder", "Opened");
            Utilities.CreateTestRunFolders();
            Utilities.CreateTestRunSessionFolder();
            Log.Block("Create Test Run Session Folder", "Closed");
            if (testPlans.Count > 0)
            {
                Log.Block("Test Run Session", "Opened");
                Log.Normal("Duration      Status                Test Name");
                Log.Normal("---------------------------------------------");
                foreach (var testPlan in testPlans)
                {
                    var activeTestPlan = testPlan;
                    Parallel.Invoke
                    (
                        () =>
                    {
                        stopWatch.Start();
                        TestConfiguration.ActiveReportStack.Add(testPlan);
                        lastRunStatus = Run(activeTestPlan);
                        stopWatch.Stop();
                    },
                        () =>
                    {
                        var currentSessionReportPath = Path.Combine(TestConfiguration.TestRunSessionPath, activeTestPlan, TestConfiguration.ReportFolderName);
                        TestMonitor.WatchExecution(currentSessionReportPath);
                    }
                    );

                    var timeStamp = Utilities.GetFormattedTimeStamp(stopWatch.ElapsedMilliseconds);
                    Utilities.PrintTestRunReport(activeTestPlan, lastRunStatus.ToString(), timeStamp);
                    stopWatch.Reset();
                    if ((TestConfiguration.ConsecutiveFailureCheck.Contains("Active")) && (TestConfiguration.ConsecutiveFailureCounter == TestConfiguration.ConsecutiveMaximumFailure))
                    {
                        break;
                    }
                    ResetAutomationTool();
                }
                Log.Block("Test Run Session", "Closed");
                Log.Block("Test Report Session", "Opened");
                Utilities.PublishCrashReport();
                Utilities.GenerateTestReports(testPlans);
                Utilities.SendReportMail();
                Log.Block("Test Report Session", "Closed");
            }
            else
            {
                Log.Error("No valid test(s) found in the list. Please check your properties file.");
            }
            Log.Block("Marathon Engine", "Closed");
        }
Exemplo n.º 20
0
        public static void logResult(ResultStatus result, List <string> testSteps, string logs = null, AppiumDriver driver = null, string testCompletionTime = null)
        {
            System.IO.TextWriter writer = null;
            //  DirectoryInfo currentDirectory = new DirectoryInfo(Environment.CurrentDirectory);
            //  string  htmlPath = currentDirectory.Parent.FullName + "\\_output\\ResultFolder\\New_Result.html";
            try
            {
                string tcName       = Gallio.Framework.TestContext.CurrentContext.Test.Name;
                string updateString = "";
                //string[] testName = tcName.Split('-');
                string ssName = null;
                if (result.ToString().Equals("Fail"))
                {
                    ssName = CaptureScreenshot(driver, tcName);
                    ssName = ssName.Replace(@"\", @"\\");
                }

                writer = new System.IO.StreamWriter(FrameGlobals.htmlPath, true);
                writer.WriteLine("<TABLE id = \"outer_table\" align = \"Center\" style= \"border-color: black; border-style: solid;\"" +
                                 "border=\"1\" width=\"700\" face=\"Trebuchet MS\"><tr><td width = \"80%\">" +
                                 "<a href=\"JavaScript:doMenu('" + tcName + "');\" id=\"x" + tcName + "\">[+]</a><b>" + tcName + "</b></td>");

                if (result.ToString().Equals("Pass"))
                {
                    updateString = updateString + "<td bgcolor=\"Green\" width = \"10%\">" + result.ToString() + "</td>" + "<td bgcolor=\"Green\" width = \"10%\">" + testCompletionTime.ToString() + "</td>";
                }
                else
                {
                    updateString = updateString + "<td bgcolor=\"Red\" width = \"10%\"><a href=\"JavaScript:dispLog('" + tcName + "','" + ssName + "','" + logs + "');\">Fail</a></td>" + "<td bgcolor=\"Green\" width = \"10%\">" + testCompletionTime.ToString() + "</td>";
                }

                writer.WriteLine(updateString + "<tr><td>" +
                                 "<div id=\"" + tcName + "\" style=\"margin-left:1em; display:none\">" +
                                 "<!--Inner table-->" +
                                 "<TABLE align = \"Center\" style= \"border-color: black; border-style: solid;\"   border=\"1\" width=\"500\" face=\"Trebuchet MS\">");
                updateString = "";
                int len = testSteps.Count;
                if (result.ToString().Equals("Fail"))
                {
                    len = len - 1;
                }
                for (int iCount = 0; iCount < len; iCount++)
                {
                    updateString = updateString + "<tr><td>" + testSteps[iCount] + "</td><td bgcolor=\"Green\" width = \"20%\">Pass</td></tr>";
                }

                if (result.ToString().Equals("Fail"))
                {
                    updateString = updateString + "<tr><td>" + testSteps[testSteps.Count - 1] + "</td><td bgcolor=\"Red\" width = \"20%\"><a href=\"JavaScript:dispLog('" + tcName + "','" + ssName + "','" + logs + "');\">Fail</a></td></tr>";
                }

                writer.WriteLine(updateString + "</TABLE><!--Inner Table-->");
                writer.WriteLine("</div></tr></td></Table>");
                writer.WriteLine("</tr>");
                if (result.ToString().Equals("Fail"))
                {
                    writer.WriteLine("\n<Div id=" + tcName + ">\n<H3>\n<Pre>");
                    writer.WriteLine("**********" + tcName + "**********" + "<BR> \n <font size=\"2\" face=\"arial\" >");
                    writer.WriteLine(logString);
                    writer.WriteLine("\n</font>\n</Pre>\n</H3>\n</Div>");
                }
                writer.Flush();
                writer.Close();
            }
            catch (Exception ex)
            {
                writer.Flush();
                writer.Close();
                //Assert.Fail(ex.Message);
                //Console.WriteLine("Test case end");
            }
        }
Exemplo n.º 21
0
 public void NotifyScenarioFinished_should_print_notification_and_update_stats(ResultStatus status, int expectedFailures)
 {
     _subject.NotifyScenarioStart("name", "l");
     _console.Reset();
     _subject.NotifyScenarioFinished(CreateScenarioResult(status, "name"));
     Assert.That(_console.GetCapturedText(), Is.EqualTo(string.Format("Finished=1, Failed={0}, Pending=0: {1}: name\r\n", expectedFailures, status.ToString().ToUpperInvariant())));
 }
 public static string StatusToString(ResultStatus status)
 {
     return(status.ToString());
 }
Exemplo n.º 23
0
 public status(ResultStatus stat) : this()
 {
     _code       = stat;
     description = stat.ToString();
 }
Exemplo n.º 24
0
 public Result(ResultStatus status)
 {
     Status     = status;
     StatusText = Status.ToString();
 }
Exemplo n.º 25
0
 private void the_link_to_details_of_STATUS_scenarios_is_clicked(ResultStatus status)
 {
     _driver.FindElementsByTagName("table").First(t => t.HasClassName("summary"))
     .FindElements(By.TagName("td")).First(td => td.FindElements(By.TagName("span")).Any(span => span.HasClassName(status.ToString().ToLower() + "Alert")))
     .FindElements(By.TagName("a")).First().ClickWithWait();
 }
Exemplo n.º 26
0
        private void Fill()
        {
            this.listView1.Items.Clear();

            if (this.Port != null && this.Port.IsOpen)
            {
                ListViewItem item = new ListViewItem();
                ResultStatus cwd  = this.Port.Cwd();
                if (cwd.Result == ResultStatus.Statuses.Success)
                {
                    this.Path.Text = cwd.ToString().Replace("'", "");
                    if (Path.Text == "")
                    {
                        this.Path.Text = "/";
                    }
                }
                else
                {
                    Helpers.ErrorBox(cwd);
                    return;
                }

                ResultStatus df = this.Port.StatVfs();
                if (df.Result == ResultStatus.Statuses.Success && df.Data is StatVfs)
                {
                    StatVfs fs = df.Data as StatVfs;
                    this.labTotal.Text = fs.TotalMegaBytes.ToString("0.00 MB");
                    this.lFree.Text    = fs.FreeMegaBytes.ToString("0.00 MB");
                    this.lUsage.Text   = fs.Usage.ToString("0.00 %");
                }
                else
                {
                    this.labTotal.Text       =
                        this.lFree.Text      =
                            this.lUsage.Text = "NaN";
                }

                ResultStatus files = this.Port.Ls();

                if (files.Result == ResultStatus.Statuses.Success)
                {
                    if (this.Path.Text != "/")
                    {
                        item.Text = "..";
                        item.SubItems.Add("");
                        item.ImageIndex = 0;
                        listView1.Items.Add(item);
                    }


                    this.Files = files.Data as List <PyFile>;
                    foreach (PyFile f in this.Files)
                    {
                        item = new ListViewItem();

                        item.Text = f.FileName;

                        if (f.IsDir)
                        {
                            item.ImageIndex = 2;
                            item.SubItems.Add("Folder");
                        }
                        else if (f.IsFile)
                        {
                            item.ImageIndex = 3;
                            item.SubItems.Add(f.FileSize.ToString());
                        }

                        this.listView1.Items.Add(item);
                        item.Tag = f;
                    }

                    if (listView1.Items.Count > 0)
                    {
                        this.listView1.Items[0].Selected = true;
                        this.listView1.Items[0].Focused  = true;
                    }
                    //this.listView1.Columns[1].Width = -2;
                }
                else
                {
                    Helpers.ErrorBox(files);
                }
            }
        }
Exemplo n.º 27
0
 private static void WriteStatus(HtmlTextWriter writer, ResultStatus status)
 {
     WriteTag(writer, HtmlTextWriterTag.Div, "status " + status.ToString().ToLowerInvariant(), status.ToString());
 }