예제 #1
0
        public void ResetTest()
        {
            var dummyBasicFlow     = new Flow();
            var dummyGlobalFlows   = new List <Flow>();
            var dummySpecificFlows = new List <Flow>();
            var dummyBoundedFlows  = new List <Flow>();

            var dummy1 = new DummyRule(0);
            var dummy2 = new DummyRule(1);
            var dummy3 = new DummyRule(2);

            // Test validation with 3 rules and 3 errors
            var ruleList = new List <IRule> {
                dummy1, dummy2, dummy3
            };
            var rucmRuleValidator = new RucmRuleValidator(ruleList);
            var result            = rucmRuleValidator.Validate(dummyBasicFlow, dummyGlobalFlows, dummySpecificFlows, dummyBoundedFlows);

            Assert.IsFalse(result);
            Assert.IsTrue(rucmRuleValidator.GetErrorReport().GetErrorList.Count == 3);

            // Test the reset
            rucmRuleValidator.Reset();

            Assert.IsTrue(rucmRuleValidator.GetErrorReport().GetErrorList.Count == 0);

            // And validate again
            result = rucmRuleValidator.Validate(dummyBasicFlow, dummyGlobalFlows, dummySpecificFlows, dummyBoundedFlows);

            Assert.IsFalse(result);
            Assert.IsTrue(rucmRuleValidator.GetErrorReport().GetErrorList.Count == 3);
        }
예제 #2
0
        public void Should_be_able_to_execture_manipulate_rules_on_a_string()
        {
            var rule  = new DummyRule();
            var rules = new List <IManipulateTextRule> {
                rule
            };

            "test".Manipulate(rules);

            rule.TextIsManipualted.Should().BeTrue();
        }
예제 #3
0
            public void UpdateXmlTypeIfPossible_Candidates_True()
            {
                var oioReg = new RegistreringType1();

                var rule = new DummyRule <RegistreringType1> {
                    _AreCandidates = true, _GetObject = oioReg, _UpdateOioFromXmlType = (r1, r2) => r1.AttributListe = new AttributListeType()
                    {
                    }
                };
                var ret = rule.UpdateXmlTypeIfPossible(oioReg, oioReg);

                Assert.True(ret);
            }
예제 #4
0
            public void UpdateXmlTypeIfPossible_Candidates_MethodCall()
            {
                var oioReg = new RegistreringType1();
                var dbReg  = new PersonRegistration();

                dbReg.SetContents(oioReg);
                bool ff   = false;
                var  rule = new DummyRule <object> {
                    _AreCandidates = true, _GetObject = "", _UpdateOioFromXmlType = (r1, r2) => ff = true
                };
                var ret = rule.UpdateXmlTypeIfPossible(oioReg, oioReg);

                Assert.True(ff);
            }
예제 #5
0
            public void UpdateXmlTypeIfPossible_NoCandidates_False()
            {
                var oioReg0 = new RegistreringType1();
                var oioReg1 = new RegistreringType1();

                var rule = new DummyRule <RegistreringType1> {
                    _AreCandidates = false, _GetObject = null, _UpdateOioFromXmlType = (r1, r2) => r1.AttributListe = new AttributListeType()
                    {
                    }
                };
                var ret = rule.UpdateXmlTypeIfPossible(oioReg0, oioReg1);

                Assert.False(ret);
            }
예제 #6
0
        public void ConditionEndKeywordTest()
        {
            var dummyRule = new DummyRule(0);
            var testStr1  = "IF";
            var testStr2  = "ELSE";
            var testStr3  = "THEN";
            var testStr4  = "ELSEIF";
            var testStr5  = "ENDIF";
            var testStr6  = "Keins der Wörter";
            var testStr7  = "Keins der Wörter oder doch mit ELSE";
            var testStr8  = "Keins der Wörter oder doch mit kleinem else";
            var testStr9  = "IF blabla THEN";

            var result = dummyRule.ContainsConditionEndKeywordTest(testStr1);

            Assert.IsFalse(result);

            result = dummyRule.ContainsConditionEndKeywordTest(testStr2);

            Assert.IsTrue(result);

            result = dummyRule.ContainsConditionEndKeywordTest(testStr3);

            Assert.IsFalse(result);

            result = dummyRule.ContainsConditionEndKeywordTest(testStr4);

            Assert.IsTrue(result);

            result = dummyRule.ContainsConditionEndKeywordTest(testStr5);

            Assert.IsTrue(result);

            result = dummyRule.ContainsConditionEndKeywordTest(testStr6);

            Assert.IsFalse(result);

            result = dummyRule.ContainsConditionEndKeywordTest(testStr7);

            Assert.IsTrue(result);

            result = dummyRule.ContainsConditionEndKeywordTest(testStr8);

            Assert.IsFalse(result);

            result = dummyRule.ContainsConditionEndKeywordTest(testStr9);

            Assert.IsFalse(result);
        }
예제 #7
0
            public void UpdateXmlTypeIfPossible_CandidatesWithOneNullObject_False([Values(0, 1)] int callNumber)
            {
                var oioReg  = new RegistreringType1();
                var oioReg2 = new RegistreringType1();
                var oioRegs = new RegistreringType1[] { oioReg, oioReg2 };

                var rule = new DummyRule <RegistreringType1> {
                    _AreCandidates = true, _GetObjectM = (o) => o == oioRegs[callNumber] ? null : o, _UpdateOioFromXmlType = (r1, r2) => r1.AttributListe = new AttributListeType()
                    {
                    }
                };
                var ret = rule.UpdateXmlTypeIfPossible(oioReg, oioReg2);

                Assert.False(ret);
            }
예제 #8
0
        public void Should_not_return_a_violation_when_the_message_has_been_suppressed_at_the_same_level()
        {
            const string clazz = @"
                public class Test
                {
                    [System.Diagnostics.CodeAnalysis.SuppressMessage(""category"", ""checkId"")]
                    private string Field1;
                }";

            var tree = SyntaxTree.ParseText(clazz);
            var rule = new DummyRule();

            var results = Execute(tree, rule);

            results.Should().BeEmpty();
        }
예제 #9
0
            public void UpdateXmlTypeIfPossible_CandidatesWithNullObjects_SameData()
            {
                var oioReg0 = new RegistreringType1();
                var oioReg1 = new RegistreringType1();
                var xml1    = Strings.SerializeObject(oioReg0);

                var rule = new DummyRule <RegistreringType1> {
                    _AreCandidates = true, _GetObject = null, _UpdateOioFromXmlType = (r1, r2) => r1.AttributListe = new AttributListeType()
                    {
                    }
                };
                var ret  = rule.UpdateXmlTypeIfPossible(oioReg0, oioReg1);
                var xml2 = Strings.SerializeObject(oioReg0);

                Assert.AreEqual(xml1, xml2);
            }
예제 #10
0
            public void UpdateXmlTypeIfPossible_CandidatesWithNullObjects_False()
            {
                var oioReg = new RegistreringType1();
                var dbReg  = new PersonRegistration();

                dbReg.SetContents(oioReg);

                var rule = new DummyRule <RegistreringType1> {
                    _AreCandidates = true, _GetObject = null, _UpdateOioFromXmlType = (r1, r2) => r1.AttributListe = new AttributListeType()
                    {
                    }
                };
                var ret = rule.UpdateXmlTypeIfPossible(oioReg, oioReg);

                Assert.False(ret);
            }
예제 #11
0
            public void UpdateXmlTypeIfPossible_NoCandidates_NoChanges()
            {
                var oioReg = new RegistreringType1();
                var dbReg  = new PersonRegistration();

                dbReg.SetContents(oioReg);
                var xml1 = Strings.SerializeObject(dbReg);

                var rule = new DummyRule <RegistreringType1> {
                    _AreCandidates = false, _GetObject = null, _UpdateOioFromXmlType = (r1, r2) => r1.AttributListe = new AttributListeType()
                    {
                    }
                };
                var ret  = rule.UpdateXmlTypeIfPossible(oioReg, oioReg);
                var xml2 = Strings.SerializeObject(dbReg);

                Assert.AreEqual(xml1, xml2);
            }
예제 #12
0
        public void EndKeywordTest()
        {
            var dummyRule = new DummyRule(0);
            var testStr1  = "ABORT";
            var testStr2  = "RESUME STEP 1";
            var testStr3  = "Nichts con beiden";

            var result = dummyRule.ContainsEndKeywordTest(testStr1);

            Assert.IsTrue(result);

            result = dummyRule.ContainsEndKeywordTest(testStr2);

            Assert.IsTrue(result);

            result = dummyRule.ContainsEndKeywordTest(testStr3);

            Assert.IsFalse(result);
        }
예제 #13
0
        public void ExportTest()
        {
            // Erfolgreicher Export ohne Mängel
            var tempPath          = this.GetTempFile();
            var ruleList          = new List <IRule>();
            var rucmRuleValidator = new RucmRuleValidator(ruleList);
            var exportResult      = rucmRuleValidator.Export(tempPath);

            try
            {
                Assert.IsTrue(exportResult);
                Assert.IsTrue(File.Exists(tempPath));
                Assert.IsTrue(File.ReadAllText(tempPath) == ErrorReport.ExportHeader + ErrorReport.EmptyErrorExportMessage);
            }
            finally
            {
                File.Delete(tempPath);
            }

            // Erfolgreicher Export mit externen Mängeln
            tempPath = this.GetTempFile();
            var fehlermeldung = "Das ist ein Fehler";

            rucmRuleValidator.AddExternalError(fehlermeldung);
            exportResult = rucmRuleValidator.Export(tempPath);

            try
            {
                Assert.IsTrue(exportResult);
                Assert.IsTrue(File.Exists(tempPath));
                Assert.IsTrue(File.ReadAllText(tempPath) == ErrorReport.ExportHeader + ErrorReport.GeneralErrorHeader + fehlermeldung + "\r\n");
            }
            finally
            {
                File.Delete(tempPath);
            }

            // Erfolgreicher Export mit Validierungsmängel
            tempPath = this.GetTempFile();
            var dummy              = new DummyRule(2, 2, 2);
            var dummyBasicFlow     = new Flow();
            var dummyGlobalFlows   = new List <Flow>();
            var dummySpecificFlows = new List <Flow>();
            var dummyBoundedFlows  = new List <Flow>();

            ruleList = new List <IRule> {
                dummy
            };
            rucmRuleValidator = new RucmRuleValidator(ruleList);
            rucmRuleValidator.Validate(dummyBasicFlow, dummyGlobalFlows, dummySpecificFlows, dummyBoundedFlows);
            exportResult = rucmRuleValidator.Export(tempPath);

            try
            {
                Assert.IsTrue(exportResult);
                Assert.IsTrue(File.Exists(tempPath));
                var expectedText = ErrorReport.ExportHeader + ErrorReport.GeneralErrorHeader + "Error #1\r\nError #2\r\n" +
                                   ErrorReport.FlowErrorHeader + "Fehler in Flow 1: Error #0\tLösung zu: 0\r\n" + "Fehler in Flow 2: Error #1\tLösung zu: 1\r\n" +
                                   ErrorReport.StepErrorHeader + "Fehler in Step 1: Error #1\tLösung zu: 1\r\n" + "Fehler in Step 2: Error #2\tLösung zu: 2\r\n";
                Assert.IsTrue(File.ReadAllText(tempPath) == expectedText);
            }
            finally
            {
                File.Delete(tempPath);
            }

            // Erfolgreicher Export mit Dateiersetzung
            tempPath = this.GetTempFile();
            dummy    = new DummyRule(2);
            ruleList = new List <IRule> {
                dummy
            };
            rucmRuleValidator = new RucmRuleValidator(ruleList);
            rucmRuleValidator.Validate(dummyBasicFlow, dummyGlobalFlows, dummySpecificFlows, dummyBoundedFlows);
            File.WriteAllText(tempPath, "Test");
            exportResult = rucmRuleValidator.Export(tempPath);

            try
            {
                Assert.IsTrue(exportResult);
                Assert.IsTrue(File.Exists(tempPath));
                Assert.IsTrue(File.ReadAllText(tempPath) == ErrorReport.ExportHeader + ErrorReport.GeneralErrorHeader + "Error #1\r\nError #2\r\n");
            }
            finally
            {
                File.Delete(tempPath);
            }

            // Fehlerhafter Export
            var invalidPath = "ABC:\\Invalid\\test.txt";

            exportResult = rucmRuleValidator.Export(invalidPath);

            Assert.IsFalse(exportResult);
        }