コード例 #1
0
        private bool OutputsAreEqual()
        {
            var ret = true;

            try
            {
                unitConverterResultsOutput.AppendLine(Environment.NewLine + string.Format(
                                                          $"{"Action",TitleColumnFormatter} {"Input",ValueColumnFormatter} {"Expected",ValueColumnFormatter} {"Actual",ValueColumnFormatter} {"Are equal\n",ValueColumnFormatter}"));

                unitConverterResultsOutput.AppendLine(messages.ParagraphDivider);

                foreach (var expectation in expected)
                {
                    var expectedOutput = expectation.output;
                    var actualOutput   = FindActualResultForExpectation(expectation, actual).output;

                    var x = string.Format($"{expectation.action,TitleColumnFormatter} {expectation.input,ValueColumnFormatter} {expectedOutput,ValueColumnFormatter} {actualOutput,ValueColumnFormatter} {actualOutput.ApproximatelyEquals(expectedOutput),ValueColumnFormatter} ");
                    unitConverterResultsOutput.AppendLine(x);

                    UnitConverterBoolResults.Add(actualOutput.ApproximatelyEquals(expectedOutput));

                    if (!actualOutput.ApproximatelyEquals(expectedOutput))
                    {
                        ret = false;
                    }
                }
            }
            catch (Exception)
            {
                UnitConverterCheckEvidence.SetInconclusive(new SimpleEvidenceBuilder("Unit converting has failed"));
                ret = false;
            }
            return(ret);
        }
コード例 #2
0
        public Task <List <FeatureEvidence> > Execute()
        {
            return(projectRunnerTask.ContinueWith(task =>
            {
                UnitConverterCheckEvidence.Feature = Feature.UnitConverterCheck;
                UnitConverterCheckEvidence.HelperMessage = messages.UnitConverterCheck;

                if (!task.Result.All(evidence => evidence.Passed))
                {
                    UnitConverterCheckEvidence.SetInconclusive(new SimpleEvidenceBuilder("Project failed to run, unable to perform check."));
                    return new List <FeatureEvidence> {
                        UnitConverterCheckEvidence
                    };
                }

                var port = this.portTask.Result;

                if (string.IsNullOrEmpty(port))
                {
                    UnitConverterCheckEvidence.SetInconclusive(new SimpleEvidenceBuilder(messages.BadPort));
                    return new List <FeatureEvidence> {
                        UnitConverterCheckEvidence
                    };
                }

                try
                {
                    var fetcher = new HTMLFetcher(port);

                    var htmlCode = fetcher.GetHTMLCodeAsString();
                    InitializeDataStructures(htmlCode);
                    actual = fetcher.GetActualValues(texts, actions);

                    if (actions.Count == 0)
                    {
                        UnitConverterCheckEvidence.SetInconclusive(new SimpleEvidenceBuilder("Couldn't execute the unit conversion because of UI changes"));
                    }

                    else
                    {
                        if (OutputsAreEqual())
                        {
                            UnitConverterCheckEvidence.SetPassed(new SimpleEvidenceBuilder(unitConverterResultsOutput.ToString()));
                        }
                        else
                        {
                            UnitConverterCheckEvidence.SetFailed(new SimpleEvidenceBuilder(unitConverterResultsOutput.ToString()));
                        }
                    }
                    UnitConverterCheckEvidence.FeatureRating = GetUnitConverterCheckRating();
                }
                catch (Exception)
                {
                    UnitConverterCheckEvidence.SetInconclusive(new SimpleEvidenceBuilder("Could not check this feature"));
                }

                return new List <FeatureEvidence> {
                    UnitConverterCheckEvidence
                };
            }, TaskContinuationOptions.OnlyOnRanToCompletion));
        }