private void InitializeDataStructures(string htmlCode)
        {
            KeywordMap = new Dictionary <List <string>, List <double> >();

            actual   = new List <UnitConverterResults>();
            expected = new List <UnitConverterResults>();

            texts = new List <double> {
                5, 25, 125
            };

            InchesToCentimetres = BackEndHelperFunctions.MakeConversion(texts, InToCm);
            MilesToKilometres   = BackEndHelperFunctions.MakeConversion(texts, MiToKm);
            YardsToMeters       = BackEndHelperFunctions.MakeConversion(texts, YdToMe);

            InToCmKeys = new List <string> {
                "inc", "in", "inch", "inches", "cm", "centimetres", "centimetre"
            };
            MiToKmKeys = new List <string> {
                "miles", "mi", "mile", "kilo", "kilometres", "kilometre"
            };
            YdToMeKeys = new List <string> {
                "yards", "yard", "yardstometers", "tometers"
            };

            actions = BackEndHelperFunctions.GetListOfActions(htmlCode, from, to);

            KeywordMap.Add(InToCmKeys, InchesToCentimetres);
            KeywordMap.Add(MiToKmKeys, MilesToKilometres);
            KeywordMap.Add(YdToMeKeys, YardsToMeters);

            InitializeExpectedValues();

            UnitConverterBoolResults = new List <bool>();
        }
        private void InitializeExpectedValues()
        {
            var ToBeAdded = new UnitConverterResults();

            for (var x = 0; x < texts.Count; x++)
            {
                for (var y = 0; y < actions.Count; y++)
                {
                    var OutputsForThisAction = BackEndHelperFunctions.CheckActions(actions[y], KeywordMap);

                    ToBeAdded.input  = texts[x];
                    ToBeAdded.action = actions[y];
                    ToBeAdded.output = OutputsForThisAction[x];

                    expected.Add(ToBeAdded);
                }
            }
        }
示例#3
0
        public Task <List <FeatureEvidence> > Execute()
        {
            return(projectRunnerTask.ContinueWith(task =>
            {
                BadInputCheckEvidence.Feature = Feature.BadInputCheck;
                BadInputCheckEvidence.HelperMessage = messages.BadInputCheck;

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

                var port = portTask.Result;

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

                try
                {
                    var fetcher = new HTMLFetcher(port);
                    var htmlCode = fetcher.GetHTMLCodeAsString();

                    actions = BackEndHelperFunctions.GetListOfActions(htmlCode, "value=\"", "\"");

                    badInputs = new Dictionary <string, string>
                    {
                        { "Empty input", " " },
                        { "Blank lines at the start", "\n10" },
                        { "Blank lines at the middle", "10 \n\n 10" },
                        { "Blank lines at the end", "10 \n\n" },
                        { "Not numbers", "Y..@" }
                    };

                    BadInputBoolResults = new List <bool>();

                    var badInputResults = fetcher.GetBadInputs(badInputs, actions[0]);

                    if (BadInputsAreFixed(badInputResults))
                    {
                        BadInputCheckEvidence.SetPassed(new SimpleEvidenceBuilder(badInputResultsOutput.ToString()));
                    }
                    else
                    {
                        BadInputCheckEvidence.SetFailed(new SimpleEvidenceBuilder(badInputResultsOutput.ToString()));
                    }

                    BadInputCheckEvidence.FeatureRating = GetBadInputCheckRating();
                }
                catch (Exception)
                {
                    BadInputCheckEvidence.SetInconclusive(new SimpleEvidenceBuilder(badInputResultsOutput.ToString()));
                }

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