public WeatherForecastController(ITestService service, ITestService service2, IUnitTest unitTest, ILoggerFactory _loggerFactory)
 {
     _service  = service;
     _service2 = service2;
     _unitTest = unitTest;
     _logger   = _loggerFactory.CreateLogger <WeatherForecastController>();
 }
示例#2
0
        public bool RunUnitTests(Command command)
        {
            bool success = true;
            int passCount = 0;
            int totalTests = 0;

            IUnitTest[] unitTests = new IUnitTest[] {
                new UnionFindUnionTest(_logger),
                new TypedFlagsUnitTest(_logger)
            };

            _logger.WriteLine("-Running Test Suite-");
            foreach (IUnitTest unitTest in unitTests)
            {
                if (unitTest.RunTest())
                {
                    _logger.WriteLine(string.Format(" {0} Passes", unitTest.GetTestName()));
                    passCount++;
                }
                else
                {
                    _logger.WriteLine(string.Format(" {0} FAILED!", unitTest.GetTestName()));
                    success = false;
                }

                totalTests++;
            }

            _logger.WriteLine("{0}/{1} Tests Passed", passCount, totalTests);
            _logger.WriteLine(success ? "ALL TESTS PASSED" : "ONE OR MORE TESTS FAILED!");

            return success;
        }
示例#3
0
        public GeneratorUnitTest(IUnitTest unitTest)
        {
            Operations = new List <IGeneratorTestingOperation>();

            foreach (ITestingOperation Operation in unitTest.Operations)
            {
                if (Operation is IClickOperation AsClick)
                {
                    Operations.Add(new GeneratorClickOperation(AsClick));
                }
                else if (Operation is IFillOperation AsFill)
                {
                    Operations.Add(new GeneratorFillOperation(AsFill));
                }
                else if (Operation is ISelectOperation AsSelect)
                {
                    Operations.Add(new GeneratorSelectOperation(AsSelect));
                }
                else if (Operation is IToggleOperation AsToggle)
                {
                    Operations.Add(new GeneratorToggleOperation(AsToggle));
                }
                else
                {
                    throw new InvalidOperationException();
                }
            }

            GeneratorUnitTestMap.Add(unitTest, this);
        }
        public bool RunUnitTests(Command command)
        {
            bool success    = true;
            int  passCount  = 0;
            int  totalTests = 0;

            IUnitTest[] unitTests = new IUnitTest[] {
                new UnionFindUnionTest(_logger),
                new TypedFlagsUnitTest(_logger)
            };

            _logger.WriteLine("-Running Test Suite-");
            foreach (IUnitTest unitTest in unitTests)
            {
                if (unitTest.RunTest())
                {
                    _logger.WriteLine(string.Format(" {0} Passes", unitTest.GetTestName()));
                    passCount++;
                }
                else
                {
                    _logger.WriteLine(string.Format(" {0} FAILED!", unitTest.GetTestName()));
                    success = false;
                }

                totalTests++;
            }

            _logger.WriteLine("{0}/{1} Tests Passed", passCount, totalTests);
            _logger.WriteLine(success ? "ALL TESTS PASSED" : "ONE OR MORE TESTS FAILED!");

            return(success);
        }
示例#5
0
        Duration Run(IUnitTest unit, string hostpath, MethodInfo test)
        {
            var exectime = Duration.Zero;
            var messages = new List <AppMsg>();
            var testName = $"{hostpath}/{test.DisplayName()}";

            try
            {
                messages.Add(AppMsg.Define($"{testName} executing", SeverityLevel.HiliteBL));
                var sw = stopwatch();
                test.Invoke(unit, null);
                exectime = snapshot(sw);
                messages.AddRange(unit.DequeueMessages());
                messages.Add(AppMsg.Define($"{testName} executed. {exectime.Ms}ms", SeverityLevel.Info));
            }
            catch (Exception e)
            {
                messages.AddRange(unit.DequeueMessages());

                if (e.InnerException is ClaimException claim)
                {
                    messages.Add(claim.Message);
                }
                else if (e.InnerException is AppException app)
                {
                    messages.Add(app.Message);
                }
                else
                {
                    messages.Add(ErrorMessages.Unanticipated(e ?? e.InnerException));
                }

                messages.Add(AppMsg.Define($"{testName} failed", SeverityLevel.Error));
            }
            finally
            {
                print(messages);
                if (PersistResults)
                {
                    log(messages, LogArea.Test);
                }
            }
            return(exectime);
        }
示例#6
0
        public Domain(string inputFolderName,
                      IFormCollection <IArea> areas,
                      IFormCollection <IDesign> designs,
                      IFormCollection <ILayout> layouts,
                      IFormCollection <IObject> objects,
                      IFormCollection <IPage> pages,
                      IFormCollection <IResource> resources,
                      IFormCollection <IBackground> backgrounds,
                      IFormCollection <IColorTheme> colorThemes,
                      IFormCollection <IFont> fonts,
                      IFormCollection <IDynamic> dynamics,
                      IFormCollection <IUnitTest> unitTests,
                      ITranslation translation,
                      IPreprocessorDefine preprocessorDefine,
                      IPage homePage,
                      IColorTheme selectedColorTheme,
                      IUnitTest selectedUnitTest)
        {
            InputFolderName    = inputFolderName;
            Areas              = areas;
            Designs            = designs;
            Layouts            = layouts;
            Objects            = objects;
            Pages              = pages;
            Resources          = resources;
            Backgrounds        = backgrounds;
            ColorThemes        = colorThemes;
            Fonts              = fonts;
            Dynamics           = dynamics;
            UnitTests          = unitTests;
            Translation        = translation;
            PreprocessorDefine = preprocessorDefine;
            HomePage           = homePage;
            SelectedColorTheme = selectedColorTheme;
            SelectedUnitTest   = selectedUnitTest;

            HomePage.SetIsReachable();
        }
示例#7
0
        public static IDomain Parse(string inputFolderName, string homePageName, string colorThemeName, string unitTestName, IDictionary <ConditionalDefine, bool> conditionalDefineTable)
        {
            if (inputFolderName == null)
            {
                throw new ArgumentNullException(nameof(inputFolderName));
            }
            if (homePageName == null)
            {
                throw new ArgumentNullException(nameof(homePageName));
            }

            if (!Directory.Exists(inputFolderName))
            {
                throw new ParsingException(1, inputFolderName, "Input folder not found.");
            }

            if (homePageName.Length == 0)
            {
                throw new ParsingException(2, inputFolderName, "Empty home page name.");
            }

            InitAttachedProperties();

            IFormParser FormParserAreas       = new ParserArea("area", "txt");
            IFormParser FormParserDesigns     = new ParserDesign("design", "xaml");
            IFormParser FormParserLayouts     = new ParserLayout("layout", "xaml");
            IFormParser FormParserObjects     = new ParserObject("object", "txt");
            IFormParser FormParserPages       = new ParserPage("page", "txt");
            IFormParser FormParserResources   = new ParserResource("resource", "png");
            IFormParser FormParserBackgrounds = new ParserBackground("background", "xaml");
            IFormParser FormParserColorThemes = new ParserColorTheme("color", "txt");
            IFormParser FormParserFonts       = new ParserFont("font", "ttf");
            IFormParser FormParserDynamics    = new ParserDynamic("dynamic", "txt");
            IFormParser FormParserUnitTest    = new ParserUnitTest("unit_test", "txt");

            IFormParserCollection FormParsers = new FormParserCollection()
            {
                FormParserAreas,
                FormParserDesigns,
                FormParserLayouts,
                FormParserObjects,
                FormParserPages,
                FormParserResources,
                FormParserBackgrounds,
                FormParserColorThemes,
                FormParserFonts,
                FormParserDynamics,
                FormParserUnitTest,
            };

            string[] FolderNames;
            try
            {
                FolderNames = Directory.GetDirectories(inputFolderName, "*.*");
            }
            catch (Exception e)
            {
                throw new ParsingException(3, inputFolderName, e.Message);
            }

            foreach (string FullFolderName in FolderNames)
            {
                bool   Parsed     = false;
                string FolderName = Path.GetFileName(FullFolderName);

                foreach (IFormParser FormParser in FormParsers)
                {
                    if (FolderName == FormParser.FolderName)
                    {
                        ParseForm(FormParser, Path.Combine(inputFolderName, FolderName), conditionalDefineTable);
                        Parsed = true;
                        break;
                    }
                }

                if (!Parsed)
                {
                    throw new ParsingException(4, FullFolderName, $"Unexpected folder '{FolderName}'.");
                }
            }

            foreach (IFormParser FormParser in FormParsers)
            {
                if (FormParser.ParsedResult == null)
                {
                    throw new ParsingException(5, inputFolderName, $"Missing folder '{FormParser.FolderName}'.");
                }
            }

            IFormCollection <IArea>       Areas       = (IFormCollection <IArea>)FormParserAreas.ParsedResult;
            IFormCollection <IDesign>     Designs     = (IFormCollection <IDesign>)FormParserDesigns.ParsedResult;
            IFormCollection <ILayout>     Layouts     = (IFormCollection <ILayout>)FormParserLayouts.ParsedResult;
            IFormCollection <IObject>     Objects     = (IFormCollection <IObject>)FormParserObjects.ParsedResult;
            IFormCollection <IPage>       Pages       = (IFormCollection <IPage>)FormParserPages.ParsedResult;
            IFormCollection <IResource>   Resources   = (IFormCollection <IResource>)FormParserResources.ParsedResult;
            IFormCollection <IBackground> Backgrounds = (IFormCollection <IBackground>)FormParserBackgrounds.ParsedResult;
            IFormCollection <IColorTheme> ColorThemes = (IFormCollection <IColorTheme>)FormParserColorThemes.ParsedResult;
            IFormCollection <IFont>       Fonts       = (IFormCollection <IFont>)FormParserFonts.ParsedResult;
            IFormCollection <IDynamic>    Dynamics    = (IFormCollection <IDynamic>)FormParserDynamics.ParsedResult;
            IFormCollection <IUnitTest>   UnitTests   = (IFormCollection <IUnitTest>)FormParserUnitTest.ParsedResult;

            string       TranslationFile = Path.Combine(inputFolderName, "translations.cvs");
            ITranslation Translation;

            if (File.Exists(TranslationFile))
            {
                Translation = new Translation(TranslationFile, '\t');
                Translation.Process(conditionalDefineTable);
            }
            else
            {
                Translation = null;
            }

            string PreprocessorDefineFile = Path.Combine(inputFolderName, "defines.txt");
            IPreprocessorDefine PreprocessorDefine;

            if (File.Exists(PreprocessorDefineFile))
            {
                PreprocessorDefine = new PreprocessorDefine(PreprocessorDefineFile);
                PreprocessorDefine.Process(conditionalDefineTable);
            }
            else
            {
                PreprocessorDefine = null;
            }

            IPage HomePage = null;

            foreach (IPage Page in Pages)
            {
                if (Page.Name == homePageName)
                {
                    HomePage = Page;
                    break;
                }
            }
            if (HomePage == null)
            {
                throw new ParsingException(6, inputFolderName, $"Home page '{homePageName}' not found.");
            }

            IColorTheme SelectedColorTheme = null;

            foreach (IColorTheme ColorTheme in ColorThemes)
            {
                if (ColorTheme.Name == colorThemeName)
                {
                    SelectedColorTheme = ColorTheme;
                    break;
                }
            }
            if (SelectedColorTheme == null)
            {
                throw new ParsingException(7, inputFolderName, $"Color theme '{colorThemeName}' not found.");
            }

            IUnitTest SelectedUnitTest = null;

            if (unitTestName != null)
            {
                foreach (IUnitTest UnitTest in UnitTests)
                {
                    if (UnitTest.Name == unitTestName)
                    {
                        SelectedUnitTest = UnitTest;
                        break;
                    }
                }
                if (SelectedUnitTest == null)
                {
                    throw new ParsingException(239, inputFolderName, $"Unit test '{unitTestName}' not found.");
                }
            }

            IDomain NewDomain = new Domain(inputFolderName,
                                           Areas,
                                           Designs,
                                           Layouts,
                                           Objects,
                                           Pages,
                                           Resources,
                                           Backgrounds,
                                           ColorThemes,
                                           Fonts,
                                           Dynamics,
                                           UnitTests,
                                           Translation,
                                           PreprocessorDefine,
                                           HomePage,
                                           SelectedColorTheme,
                                           SelectedUnitTest);

            bool IsConnected = true;

            for (int i = 0; i < 100 && IsConnected; i++)
            {
                IsConnected = false;

                foreach (IFormParser FormParser in FormParsers)
                {
                    foreach (IConnectable Connectable in FormParser.ParsedResult)
                    {
                        IsConnected |= Connectable.Connect(NewDomain);
                    }
                }

                if (Translation != null)
                {
                    IsConnected |= Translation.Connect(NewDomain);
                }
            }
            if (IsConnected)
            {
                throw new ParsingException(8, inputFolderName, $"Unexpected error during processing of the input folder.");
            }

            // Make sure areas used by other areas are first
            BubbleSort(Areas);

            // Remove all layouts and use their clone.
            //((List<ILayout>)Layouts).Clear();
            foreach (IPage Page in Pages)
            {
                foreach (KeyValuePair <IArea, ILayout> Entry in Page.AreaLayouts)
                {
                    Layouts.Add(Entry.Value);
                }
            }

            return(NewDomain);
        }