Пример #1
0
        public void Validation001_ValidationCollectionEmptyAfterInit()
        {
            ConfigValidator.Reset();
            var cfg = new Config();

            Assert.IsTrue(cfg.ValidationCollection != null);
            Assert.IsTrue(cfg.ValidationCollection.Count == 0);
        }
Пример #2
0
        public void Validation007_Propagation()
        {
            ConfigValidator.Reset();
            var cfg = new Config();
            //cfg.SolutionPath = @"..\..\..\..\";

            string mes1 = "test error message";
            string mes2 = "test error message2";

            var gr = cfg.Model.GroupConstantGroups.AddGroupConstants("Gr");

            gr.NodeAddNewSubNode();
            ConstantValidator.Validator.RuleFor(x => x).Null().WithMessage(mes1).WithSeverity(Severity.Error).WithState(x => SeverityWeight.Normal);
            cfg.ValidateSubTreeFromNode(cfg.Model.GroupConstantGroups);
            Assert.IsTrue(cfg.Model.GroupConstantGroups.ListConstantGroups[0].ListConstants[0].ValidationCollection.Count == 1);
            Assert.IsTrue(cfg.Model.GroupConstantGroups.ListConstantGroups[0].ListConstants[0].CountErrors == 1);
            Assert.IsTrue(cfg.Model.GroupConstantGroups.ListConstantGroups[0].CountErrors == 1);
            Assert.IsTrue(cfg.Model.GroupConstantGroups.ValidationCollection.Count == 1);
            Assert.IsTrue(cfg.Model.GroupConstantGroups.CountErrors == 1);
            Assert.IsTrue(cfg.ValidationCollection.Count == 0);
            Assert.IsTrue(cfg.CountErrors == 1);
            Assert.IsTrue(cfg.CountInfos == 0);
            Assert.IsTrue(cfg.CountWarnings == 0);

            cfg.Model.GroupEnumerations.NodeAddNewSubNode();
            EnumerationValidator.Validator.RuleFor(x => x).Null().WithMessage(mes2).WithSeverity(Severity.Error).WithState(x => SeverityWeight.Low);
            cfg.ValidateSubTreeFromNode(cfg.Model.GroupEnumerations);
            Assert.IsTrue(cfg.Model.GroupEnumerations[0].ValidationCollection.Count == 1);
            Assert.IsTrue(cfg.Model.GroupEnumerations[0].CountErrors == 1);
            Assert.IsTrue(cfg.Model.GroupEnumerations.ValidationCollection.Count == 1);
            Assert.IsTrue(cfg.Model.GroupEnumerations.CountErrors == 1);
            Assert.IsTrue(cfg.ValidationCollection.Count == 0);
            Assert.IsTrue(cfg.CountErrors == 2);
            Assert.IsTrue(cfg.CountInfos == 0);
            Assert.IsTrue(cfg.CountWarnings == 0);

            cfg.ValidateSubTreeFromNode(cfg);
            Assert.IsTrue(cfg.ValidationCollection.Count == 2);
            Assert.IsTrue(cfg.CountErrors == 2);
            Assert.IsTrue(cfg.CountInfos == 0);
            Assert.IsTrue(cfg.CountWarnings == 0);
        }
Пример #3
0
        public void Validation003_AppProjectGeneratorValidationCollectionContainsValidationMessagesFromSubNodesForSelectedNode()
        {
            ConfigValidator.Reset();
            CatalogValidator.Reset();
            var cfg = new Config();

            cfg.CurrentCfgFolderPath = @".\";
            //cfg.SolutionPath = @"..\..\..\..\";

            var sol1 = cfg.GroupAppSolutions.AddAppSolution("sol1", "./");
            var prj1 = sol1.AddProject("prj1", "./");
            var gen1 = prj1.AddGenerator("gen1", null, null, "");

            string mes1  = "test error message";
            string mes2  = "test warning message";
            string mes22 = "test warning2 message";
            string mes3  = "test info message";

            //AppProjectGeneratorValidator.Validator.RuleFor(x => x).Null().WithMessage(mes22).WithSeverity(Severity.Warning).WithState(x => SeverityWeight.VeryHigh);
            //AppProjectGeneratorValidator.Validator.RuleFor(x => x).Null().WithMessage(mes1).WithSeverity(Severity.Error).WithState(x => SeverityWeight.VeryLow);
            //AppProjectGeneratorValidator.Validator.RuleFor(x => x).Null().WithMessage(mes3).WithSeverity(Severity.Info).WithState(x => SeverityWeight.VeryHigh);
            //AppProjectGeneratorValidator.Validator.RuleFor(x => x).Null().WithMessage(mes2).WithSeverity(Severity.Warning).WithState(x => SeverityWeight.VeryLow);

            cfg.Validate();

            cfg.ValidateSubTreeFromNode(sol1, _logger); // .ConfigureAwait(continueOnCapturedContext: false);

            Assert.IsTrue(cfg.ValidationCollection.Count == 0);
            Assert.IsTrue(sol1.ValidationCollection.Count == 5);
            //var p = sol1.ValidationCollection[0];
            //Assert.IsTrue(p.Severity == FluentValidation.Severity.Error);
            //Assert.IsTrue(p.Message == mes1);
            //Assert.IsTrue(p.Model == sol1);
            //p = sol1.ValidationCollection[1];
            //Assert.IsTrue(p.Severity == FluentValidation.Severity.Warning);
            //Assert.IsTrue(p.Message == mes22);
            //Assert.IsTrue(p.Model == sol1);
            //p = sol1.ValidationCollection[2];
            //Assert.IsTrue(p.Severity == FluentValidation.Severity.Warning);
            //Assert.IsTrue(p.Message == mes2);
            //Assert.IsTrue(p.Model == sol1);
            //p = sol1.ValidationCollection[3];
            //Assert.IsTrue(p.Severity == FluentValidation.Severity.Info);
            //Assert.IsTrue(p.Message == mes3);
            //Assert.IsTrue(p.Model == sol1);

            //Assert.AreEqual(1, sol1.CountErrors);
            //Assert.AreEqual(2, sol1.CountWarnings);
            //Assert.AreEqual(1, sol1.CountInfos);

            //Assert.AreEqual(1, cfg.Model.GroupCatalogs.CountErrors);
            //Assert.AreEqual(2, cfg.Model.GroupCatalogs.CountWarnings);
            //Assert.AreEqual(1, cfg.Model.GroupCatalogs.CountInfos);

            //Assert.AreEqual(1, cfg.CountErrors);
            //Assert.AreEqual(2, cfg.CountWarnings);
            //Assert.AreEqual(1, cfg.CountInfos);

            //cfg.ValidateSubTreeFromNode(cfg, _logger); // .ConfigureAwait(continueOnCapturedContext: false);
            //Assert.IsTrue(cfg.ValidationCollection.Count == 4);
        }
Пример #4
0
        public void Validation002_CatalogValidationCollectionContainsValidationMessagesFromSubNodesForSelectedNode()
        {
            ConfigValidator.Reset();
            CatalogValidator.Reset();
            var cfg = new Config();
            //cfg.SolutionPath = @"..\..\..\..\";

            var c = cfg.Model.GroupCatalogs.AddCatalog("test");

            Assert.IsTrue(c.Parent == cfg.Model.GroupCatalogs);

            string mes1  = "test error message";
            string mes2  = "test warning message";
            string mes22 = "test warning2 message";
            string mes3  = "test info message";

            CatalogValidator.Validator.RuleFor(x => x).Null().WithMessage(mes22).WithSeverity(Severity.Warning).WithState(x => SeverityWeight.VeryHigh);
            CatalogValidator.Validator.RuleFor(x => x).Null().WithMessage(mes1).WithSeverity(Severity.Error).WithState(x => SeverityWeight.VeryLow);
            CatalogValidator.Validator.RuleFor(x => x).Null().WithMessage(mes3).WithSeverity(Severity.Info).WithState(x => SeverityWeight.VeryHigh);
            CatalogValidator.Validator.RuleFor(x => x).Null().WithMessage(mes2).WithSeverity(Severity.Warning).WithState(x => SeverityWeight.VeryLow);

            cfg.Validate();

            cfg.ValidateSubTreeFromNode(c, _logger);

            Assert.IsTrue(cfg.ValidationCollection.Count == 0);
            Assert.IsTrue(c.ValidationCollection.Count == 4);
            var p = c.ValidationCollection[0];

            Assert.IsTrue(p.Severity == FluentValidation.Severity.Error);
            Assert.IsTrue(p.Message == mes1);
            Assert.IsTrue(p.Model == c);
            p = c.ValidationCollection[1];
            Assert.IsTrue(p.Severity == FluentValidation.Severity.Warning);
            Assert.IsTrue(p.Message == mes22);
            Assert.IsTrue(p.Model == c);
            p = c.ValidationCollection[2];
            Assert.IsTrue(p.Severity == FluentValidation.Severity.Warning);
            Assert.IsTrue(p.Message == mes2);
            Assert.IsTrue(p.Model == c);
            p = c.ValidationCollection[3];
            Assert.IsTrue(p.Severity == FluentValidation.Severity.Info);
            Assert.IsTrue(p.Message == mes3);
            Assert.IsTrue(p.Model == c);

            Assert.AreEqual(1, c.CountErrors);
            Assert.AreEqual(2, c.CountWarnings);
            Assert.AreEqual(1, c.CountInfos);

            Assert.AreEqual(1, cfg.Model.GroupCatalogs.CountErrors);
            Assert.AreEqual(2, cfg.Model.GroupCatalogs.CountWarnings);
            Assert.AreEqual(1, cfg.Model.GroupCatalogs.CountInfos);

            Assert.AreEqual(1, cfg.CountErrors);
            Assert.AreEqual(2, cfg.CountWarnings);
            Assert.AreEqual(1, cfg.CountInfos);

            cfg.ValidateSubTreeFromNode(cfg, _logger); // .ConfigureAwait(continueOnCapturedContext: false);
            Assert.IsTrue(cfg.ValidationCollection.Count == 4);

            cfg.ValidateSubTreeFromNode(cfg, _logger);
            Assert.IsTrue(cfg.ValidationCollection.Count == 4);
        }