Exemplo n.º 1
0
        public void BeyondCompareReportTest()
        {
            if (File.Exists("beyondExpected.txt"))
                File.Delete("beyondExpected.txt");

            if (File.Exists("beyondActual.txt"))
                File.Delete("beyondActual.txt");

            Movie beyondExpected = new Movie();
            beyondExpected.Name = "Oblivion";
            beyondExpected.PaymentForTomCruise = 2000000M;

            Movie beyondActual = new Movie();
            beyondActual.Name = "Edge of Tomorrow";
            beyondActual.PaymentForTomCruise = 3000000M;

            CompareLogic compareLogic = new CompareLogic();
            compareLogic.Config.MaxDifferences = Int32.MaxValue;
            ComparisonResult result = compareLogic.Compare(beyondExpected, beyondActual);

            BeyondCompareReport beyondCompare = new BeyondCompareReport();
            beyondCompare.OutputFiles(result.Differences, "beyondExpected.txt", "beyondActual.txt");

            Assert.IsTrue(File.Exists("beyondExpected.txt"));
            Assert.IsTrue(File.Exists("beyondActual.txt"));

            if (!string.IsNullOrEmpty(beyondCompare.FindBeyondCompare()))
                beyondCompare.LaunchApplication("beyondExpected.txt", "beyondActual.txt");
        }
Exemplo n.º 2
0
        public void WinMergeReportTest()
        {
            if (File.Exists("winMergeExpected.txt"))
                File.Delete("winMergeExpected.txt");

            if (File.Exists("winMergeActual.txt"))
                File.Delete("winMergeActual.txt");

            Movie winMergeExpected = new Movie();
            winMergeExpected.Name = "Oblivion";
            winMergeExpected.PaymentForTomCruise = 2000000M;

            Movie winMergeActual = new Movie();
            winMergeActual.Name = "Edge of Tomorrow";
            winMergeActual.PaymentForTomCruise = 3000000M;

            CompareLogic compareLogic = new CompareLogic();
            compareLogic.Config.MaxDifferences = Int32.MaxValue;
            ComparisonResult result = compareLogic.Compare(winMergeExpected, winMergeActual);

            WinMergeReport winMergeReport = new WinMergeReport();
            winMergeReport.OutputFiles(result.Differences, "winMergeExpected.txt", "winMergeActual.txt");

            Assert.IsTrue(File.Exists("winMergeExpected.txt"));
            Assert.IsTrue(File.Exists("winMergeActual.txt"));

            if (!string.IsNullOrEmpty(winMergeReport.FindWinMerge()))
                winMergeReport.LaunchApplication("winMergeExpected.txt", "winMergeActual.txt");
        }
 static IExceptionComparer CreateExceptionComparer() {
   var comparer = new CompareLogic();
   comparer.Config.MembersToIgnore.Add("Source");
   comparer.Config.MembersToIgnore.Add("StackTrace");
   comparer.Config.MembersToIgnore.Add("TargetSite");
   return new CompareNetObjectsBasedExceptionComparer(comparer);
 }
Exemplo n.º 4
0
 public void Clone()
 {
     var pFiller = new Filler<Identity>();
     var test = pFiller.Create();
     var clone = test.Clone();
     var compareLogic = new CompareLogic();
     var result = compareLogic.Compare(test, clone);
     Assert.True(result.AreEqual, result.DifferencesString);
 }
 private static CompareLogic CreateComparator()
 {
     CompareLogic compareLogic = new CompareLogic();
     compareLogic.Config.CompareStaticFields = false;
     compareLogic.Config.CompareStaticProperties = false;
     compareLogic.Config.MaxDifferences = int.MaxValue;
     compareLogic.Config.ShowBreadcrumb = true;
     compareLogic.Config.TreatStringEmptyAndNullTheSame = false;
     return compareLogic;
 }
Exemplo n.º 6
0
 protected override bool doMatch(ICollection actual)
 {
     foreach (object objA in actual)
     {
         var result = new CompareLogic().Compare(objA, _expected);
         if (result.AreEqual)
             return true;
     }
     return false;
 }
Exemplo n.º 7
0
 private static string CompareObjs(object o1, object o2)
 {
     var compareLogic = new CompareLogic();
     compareLogic.Config.MaxDifferences = 10;
     compareLogic.Config.CompareChildren = true;
     compareLogic.Config.ComparePrivateFields = true;
     compareLogic.Config.CompareFields = true;
     compareLogic.Config.MaxStructDepth = 10;
     var result = compareLogic.Compare(o1, o2);
     return result.DifferencesString;
 }
Exemplo n.º 8
0
 public void Clone()
 {
     var pFiller = new Filler<Constraint>();
     var test = pFiller.Create();
     var clone = test.Clone();
     var config = new ComparisonConfig();
     config.MembersToIgnore.Add("Table"); //table should never be cloned
     var compareLogic = new CompareLogic(config);
     var result = compareLogic.Compare(test, clone);
     Assert.True(result.AreEqual, result.DifferencesString);
 }
        public void ChildPropertyTypeShouldBeIgnored()
        {
            var objeto = CreateSecao();
            var dto = CreateDtoSecao();
            var comparador = new CompareLogic();

            comparador.Config.MembersToIgnore.Add("Capacity");
            comparador.Config.IgnoreObjectTypes = true;
            var resultado = comparador.Compare(dto, objeto);
            Assert.IsTrue(resultado.AreEqual, resultado.DifferencesString);
        }
        public void CheckStringAssert()
        {
            AssertHelper.Wrapper(() =>
            {
                const string expected = "Joe";
                const string actual = "Chandler";

                var compareLogic = new CompareLogic();
                ComparisonResult result = compareLogic.Compare(expected, actual);

                Assert.IsTrue(result.AreEqual, result.DifferencesString);
            });
        }
        public void IntTypeTesting()
        {
            AssertHelper.Wrapper(()=>
            {
                const int expected = 5;
                const int actual = 6;

                var compareLogic = new CompareLogic();
                ComparisonResult result = compareLogic.Compare(expected, actual);

                Assert.IsTrue(result.AreEqual, result.DifferencesString);
            });
        }
        public bool Equal(object expected, object actual, out IEnumerable<IDifference> differences)
        {
            var compareLogic = new CompareLogic(new ComparisonConfig {MaxDifferences = 5});
            var compareResult = compareLogic.Compare(expected, actual);

            differences = compareResult.Differences.Select(d => new Difference
            {
                PropertyName = d.PropertyName,
                WhatIsCompared = d.GetWhatIsCompared(),
                ExpectedValue = d.Object1Value,
                ActualValue = d.Object2Value
            }).ToList<IDifference>();

            return compareResult.AreEqual;
        }
        public void Compare_IndexerCompareAndPropertyComparePositive()
        {
            var jane = new Person {Name = "Jane"};
            var mary = new Person {Name = "Mary"};
            var jack = new Person {Name = "Jack"};

            var nameList1 = new List<Person>() {jane, jack, mary};
            var nameList2 = new List<Person>() {jane, jack, mary};

            var class1 = new ListClass<Person>(nameList1);
            var class2 = new ListClass<Person>(nameList2);

            var compare = new CompareLogic();
            Assert.IsTrue(compare.Compare(class1, class2).AreEqual);
        }
        public void IndexFromSearchController()
        {
            // Arrange
            var person = TestHelper.GetSearchDetailsResult().PersonDetails[0];
            var expectedModel = Converter.SearchDetailsToSendModel(person);
            var controller = SendControllerWithMockedRequestContext(person);
            var compareLogic = new CompareLogic();

            // Act
            var result = controller.Index(null) as ViewResult;

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual("Index", result.ViewName);
            Assert.IsTrue(compareLogic.Compare(expectedModel, result.Model).AreEqual);
        }
        public void WhenBothEntitiesHaveLinqEnumeratorPropertyThenDetectsDifferences()
        {
            var a = new EnumerableTestEntity
            {
                Items = new[] { 1, 2, 3 }.Where(i => i < 5)
            };
            var b = new EnumerableTestEntity
            {
                Items = new[] { 1, 2, 4 }.Where(i => i < 5)
            };

            var oc = new CompareLogic();
            oc.Config.IgnoreObjectTypes = true;
            oc.Config.CompareChildren = true;

            var result = oc.Compare(a, b);
            Console.WriteLine(result.DifferencesString);
            Assert.IsFalse(result.AreEqual);
        }
        public void DocumentationTest()
        {
            //This is the comparison class
            CompareLogic compareLogic = new CompareLogic();

            //Create a couple objects to compare
            Person person1 = new Person();
            person1.DateCreated = DateTime.Now;
            person1.Name = "Greg";

            Person person2 = new Person();
            person2.Name = "John";
            person2.DateCreated = person1.DateCreated;

            //These will be different, write out the differences
            ComparisonResult result = compareLogic.Compare(person1, person2);
            if (!result.AreEqual)
                Console.WriteLine(result.DifferencesString);
        }
Exemplo n.º 17
0
        public void PropertyComparerFailsWithObjectNullException()
        {
            //This is the comparison class
            CompareLogic compareLogic = new CompareLogic();
            compareLogic.Config.SkipInvalidIndexers = true;

            //Create a couple objects to compare
            Person2 person1 = new Person2();
            person1.DateCreated = DateTime.Now;
            person1.Name = "Greg";

            Person2 person2 = new Person2();
            person2.Name = "John";
            person2.DateCreated = person1.DateCreated;

            //These will be different, write out the differences
            ComparisonResult result = compareLogic.Compare(person1, person2);
            if (!result.AreEqual)
                Console.WriteLine(result.DifferencesString);
        }
Exemplo n.º 18
0
        public static bool HasTheSameDataAs(this DataSet left, DataSet right)
        {
            var config = new ComparisonConfig();
            config.CustomComparers.Add(new NDbUnitDataSetComparer(RootComparerFactory.GetRootComparer()));
            config.CustomComparers.Add(new NDbUnitDataTableComparer(RootComparerFactory.GetRootComparer()));
            config.CustomComparers.Add(new NDbUnitDataRowCollectionComparer(RootComparerFactory.GetRootComparer()));

            config.MaxDifferences = MAX_DIFFERENCES_BEFORE_ABORT;

            var comparer = new CompareLogic(config);

            var result = comparer.Compare(left, right);

            if (!result.AreEqual)
            {
                Log(result.DifferencesString);
            }

            return result.AreEqual;
        }
Exemplo n.º 19
0
        public void TestXmlSerialization()
        {
            var serializer = new DefaultXmlSerialization();
            var gxExpected = TestBacking.GetGedcomxObjectForDeepCompare();

            byte[] bytes;

            using (var ms = new MemoryStream())
            {
                serializer.Serialize(gxExpected, ms);
                bytes = ms.ToArray();
            }

            var gxActual = serializer.Deserialize<Gx.Gedcomx>(new MemoryStream(bytes));

            var comparer = new CompareLogic();
            var differences = comparer.Compare(gxExpected, gxActual);

            Assert.AreEqual(0, differences.Differences.Count);
        }
Exemplo n.º 20
0
        private void Get_Tax_Rates_Test(int year, int month, int day, TaxRateDb sut)
        {
            // Assign
            DateTime date = new DateTime(year,month,day);
            TaxBracket tb = new TaxBracket
            {
                BaseRate = 0.19m,
                BaseTax = 0M,
                MinSalaryValue = 18201,
                MaxSalaryValue = 37000,
                StartDate = new DateTime(2012, 7, 1)
            };
            sut.AddTaxRate(TestStubs.TaxBrackets()[0]);
            sut.AddTaxRate(tb);

            //Assign the expected
            List<TaxBracket> expected = new List<TaxBracket>();
            expected.Add(tb);
            expected.Add(TestStubs.TaxBrackets()[0]);

            // Adding rate outside range to test for
            sut.AddTaxRate(
                   new TaxBracket
                   {
                       BaseRate = 0.37m,
                       BaseTax = 17547m,
                       MinSalaryValue = 80001,
                       MaxSalaryValue = 180000,
                       StartDate = new DateTime(2013, 7, 1)
                   });

            //Act
            List<TaxBracket> actual = sut.GetRates(date).ToList();
            CompareLogic compareLogic = new CompareLogic();
            ComparisonResult result = compareLogic.Compare(expected, actual);

            // Assert tax to verify it works
            Assert.True(result.AreEqual);
        }
        void PayPeriod_GetPayPeriod_Test()
        {
            //Assign
            ProcessingPayLineVm ppl = new ProcessingPayLineVm
            {
                AnnualGrossSalary = "120000",
                FirstName = "DavidTest",
                LastName = "RuddTest",
                SuperAnnuationRate = "10%",
                StartDateTime = "01 March 2013-31 March 2013",

            };
            Customer cust = TestStubs.GetCustomer();

            //Act
            PayPeriod actual = ppl.GetPayPeriod();
            CompareLogic compareLogic = new CompareLogic();
            ComparisonResult result = compareLogic.Compare(cust.PayPeriod, actual);

            //Assert
            Assert.True(result.AreEqual);
        }
        private static ComparisonResult CompareObjects(Object expectedObj, Object actualObj, String[] ignoredMembers = null)
        {

            ComparisonConfig cfg = new ComparisonConfig()
            {
                IgnoreObjectTypes = true,
                IgnoreCollectionOrder = true,
                IgnoreUnknownObjectTypes = true,
                ComparePrivateFields = false,
                ComparePrivateProperties = false,
                MembersToIgnore = new List<string>() { "_entityWrapper" },
                CompareChildren = false,
                MaxStructDepth = 1,
                MaxDifferences = 20,
                TreatStringEmptyAndNullTheSame = true

            };
            if (ignoredMembers != null)
            {
                cfg.MembersToIgnore.AddRange(ignoredMembers);
            }
            //also add not mapped attributes
            if (actualObj.PropertiesWithAttribute<NotMappedAttribute>().Length > 0)
            {
                cfg.MembersToIgnore.AddRange(actualObj.PropertiesWithAttribute<NotMappedAttribute>());
            }

            //check on null objects
            CompareLogic cpl = new CompareLogic(cfg);


            var result = cpl.Compare(expectedObj, actualObj);


            return result;
        }
Exemplo n.º 23
0
 public CompareObjects(bool useAppConfigSettings)
 {
     _logic = new CompareLogic(useAppConfigSettings);
     _result = new ComparisonResult(_logic.Config);
 }
Exemplo n.º 24
0
 public CompareObjects()
 {
     _logic = new CompareLogic();
     _result = new ComparisonResult(_logic.Config);
 }
Exemplo n.º 25
0
 public void Cleanup()
 {
     _compare = null;
 }
Exemplo n.º 26
0
 public void Initialize()
 {
     _compare = new CompareLogic();
 }
        public void A05_AsyncRegExCrawlerTwoExpressionMultipleResultTest()
        {
            // Read the content
            string content = File.ReadAllText("./Testdata/testdata.log");

            // build search term one
            var regExSearchTerm1 = new RegExSearchTerm()
            {
                Expression = @"(\d{4}-\d{2}-\d{2}).+(CatalogCacheUpdateJob perform)(.+)",
                ExpressionFriendlyName = "SearchTerm 1"
            };

            // build search term two
            var regExSearchTerm2 = new RegExSearchTerm()
            {
                Expression = @"2015-06-27 12:03:04,721  INFO   \[EJB default - 5\] RuleChangeCommand executeChange - Setting entry 00.2285 to MODIFY",
                ExpressionFriendlyName = "Ex1"
            };

            // fill the search term list
            var regExSearchList = new List<RegExSearchTerm>() { regExSearchTerm1, regExSearchTerm2 };

            // build the expected findigs
            // build finding one
            var expectedFinding1 = new Finding()
            {
                Expression = @"(\d{4}-\d{2}-\d{2}).+(CatalogCacheUpdateJob perform)(.+)",
                ExpressionFriendlyName = "SearchTerm 1",
                FileFolder = @"D:\WORK\RegExTractor\src\RegExTractor\RegExTractorTests\bin\Debug\Testdata",
                FileName = "testdata.log",
                Match = new List<RegExTractorMatchCollection>()
                {
                    // first match
                    new RegExTractorMatchCollection()
                    {
                        Id = 1,
                        MatchCollection = new List<RegExTractorMatch>()
                        {
                            new RegExTractorMatch()
                            {
                                Id = 1,
                                Match = "2015-06-27 13:00:00,005  INFO   [EJB default - 2] CatalogCacheUpdateJob perform - Performing scheduled reload of catalog cache...\r"
                            },
                            new RegExTractorMatch()
                            {
                                Id = 2,
                                Match = "2015-06-27"
                            },
                            new RegExTractorMatch()
                            {
                                Id = 3,
                                Match = "CatalogCacheUpdateJob perform"
                            },
                            new RegExTractorMatch()
                            {
                                Id = 4,
                                Match = " - Performing scheduled reload of catalog cache...\r"
                            }
                        }
                    },

                    // second match
                    new RegExTractorMatchCollection()
                    {
                        Id = 2,
                        MatchCollection = new List<RegExTractorMatch>()
                        {
                            new RegExTractorMatch()
                            {
                                Id = 1,
                                Match = "2015-06-27 13:01:30,110  INFO   [EJB default - 2] CatalogCacheUpdateJob perform - Scheduled catalog cache reload successfully completed.\r"
                            },
                            new RegExTractorMatch()
                            {
                                Id = 2,
                                Match = "2015-06-27"
                            },
                            new RegExTractorMatch()
                            {
                                Id = 3,
                                Match = "CatalogCacheUpdateJob perform"
                            },
                            new RegExTractorMatch()
                            {
                                Id = 4,
                                Match = " - Scheduled catalog cache reload successfully completed.\r"
                            }
                        }
                    },

                    // third match
                    new RegExTractorMatchCollection()
                    {
                        Id = 3,
                        MatchCollection = new List<RegExTractorMatch>()
                        {
                            new RegExTractorMatch()
                            {
                                Id = 1,
                                Match = "2015-06-28 01:00:00,006  INFO   [EJB default - 6] CatalogCacheUpdateJob perform - Performing scheduled reload of catalog cache...\r"
                            },
                            new RegExTractorMatch()
                            {
                                Id = 2,
                                Match = "2015-06-28"
                            },
                            new RegExTractorMatch()
                            {
                                Id = 3,
                                Match = "CatalogCacheUpdateJob perform"
                            },
                            new RegExTractorMatch()
                            {
                                Id = 4,
                                Match = " - Performing scheduled reload of catalog cache...\r"
                            }
                        }
                    },

                    // fourth match
                    new RegExTractorMatchCollection()
                    {
                        Id = 4,
                        MatchCollection = new List<RegExTractorMatch>()
                        {
                            new RegExTractorMatch()
                            {
                                Id = 1,
                                Match = "2015-06-28 01:01:29,226  INFO   [EJB default - 6] CatalogCacheUpdateJob perform - Scheduled catalog cache reload successfully completed.\r"
                            },
                            new RegExTractorMatch()
                            {
                                Id = 2,
                                Match = "2015-06-28"
                            },
                            new RegExTractorMatch()
                            {
                                Id = 3,
                                Match = "CatalogCacheUpdateJob perform"
                            },
                            new RegExTractorMatch()
                            {
                                Id = 4,
                                Match = " - Scheduled catalog cache reload successfully completed.\r"
                            }
                        }
                    }

                }
            };

            // build finding two
            var expectedFinding2 = new Finding()
            {
                Expression = @"2015-06-27 12:03:04,721  INFO   \[EJB default - 5\] RuleChangeCommand executeChange - Setting entry 00.2285 to MODIFY",
                ExpressionFriendlyName = "Ex1",
                FileFolder = @"D:\WORK\RegExTractor\src\RegExTractor\RegExTractorTests\bin\Debug\Testdata",
                FileName = "testdata.log",
                Match = new List<RegExTractorMatchCollection>()
                {
                   new RegExTractorMatchCollection()
                   {
                       Id = 1,
                       MatchCollection = new List<RegExTractorMatch>()
                       {
                           new RegExTractorMatch()
                           {
                               Id = 1,
                               Match = "2015-06-27 12:03:04,721  INFO   [EJB default - 5] RuleChangeCommand executeChange - Setting entry 00.2285 to MODIFY"
                           }
                       }
                   }
                }
            };

            // build expected findings list
            var expected = new List<Finding>() { expectedFinding1, expectedFinding2 };

            // do the magic and crawl!
            IRegExCrawler crawler = new AsyncRegExCrawler();
            var actual = crawler.Crawl(regExSearchList, content, expectedFinding1.FileName, expectedFinding1.FileFolder);

            var comparer = new CompareLogic();
            comparer.Config.IgnoreCollectionOrder = true;
            var compareResult = comparer.Compare(expected, actual);
            Assert.IsTrue(compareResult.AreEqual, compareResult.DifferencesString);

            Assert.AreEqual(expected.Count, actual.Count, "Another result set expected.");
        }
        public void A01_SimpleRexExCrawlerTest()
        {
            string content = File.ReadAllText("./Testdata/testdata.log");

            var regExSearchTerm1 = new RegExSearchTerm()
            {
                Expression = @"(\d{4}-\d{2}-\d{2}).+(CatalogCacheUpdateJob perform)(.+)",
                ExpressionFriendlyName = "SearchTerm 1"
            };

            var regExSearchList = new List<RegExSearchTerm>() { regExSearchTerm1 };

            var expectedFinding1 = new Finding()
            {
                Expression = @"(\d{4}-\d{2}-\d{2}).+(CatalogCacheUpdateJob perform)(.+)",
                ExpressionFriendlyName = "SearchTerm 1",
                FileFolder = @"D:\WORK\RegExTractor\src\RegExTractor\RegExTractorTests\bin\Debug\Testdata",
                FileName = "testdata.log",
                Match = new List<RegExTractorMatchCollection>()
                {
                    // first match
                    new RegExTractorMatchCollection()
                    {
                        Id = 1,
                        MatchCollection = new List<RegExTractorMatch>()
                        {
                            new RegExTractorMatch()
                            {
                                Id = 1,
                                Match = "2015-06-27 13:00:00,005  INFO   [EJB default - 2] CatalogCacheUpdateJob perform - Performing scheduled reload of catalog cache...\r"
                            },
                            new RegExTractorMatch()
                            {
                                Id = 2,
                                Match = "2015-06-27"
                            },
                            new RegExTractorMatch()
                            {
                                Id = 3,
                                Match = "CatalogCacheUpdateJob perform"
                            },
                            new RegExTractorMatch()
                            {
                                Id = 4,
                                Match = " - Performing scheduled reload of catalog cache...\r"
                            }
                        }
                    },

                    // second match
                    new RegExTractorMatchCollection()
                    {
                        Id = 2,
                        MatchCollection = new List<RegExTractorMatch>()
                        {
                            new RegExTractorMatch()
                            {
                                Id = 1,
                                Match = "2015-06-27 13:01:30,110  INFO   [EJB default - 2] CatalogCacheUpdateJob perform - Scheduled catalog cache reload successfully completed.\r"
                            },
                            new RegExTractorMatch()
                            {
                                Id = 2,
                                Match = "2015-06-27"
                            },
                            new RegExTractorMatch()
                            {
                                Id = 3,
                                Match = "CatalogCacheUpdateJob perform"
                            },
                            new RegExTractorMatch()
                            {
                                Id = 4,
                                Match = " - Scheduled catalog cache reload successfully completed.\r"
                            }
                        }
                    },

                    // third match
                    new RegExTractorMatchCollection()
                    {
                        Id = 3,
                        MatchCollection = new List<RegExTractorMatch>()
                        {
                            new RegExTractorMatch()
                            {
                                Id = 1,
                                Match = "2015-06-28 01:00:00,006  INFO   [EJB default - 6] CatalogCacheUpdateJob perform - Performing scheduled reload of catalog cache...\r"
                            },
                            new RegExTractorMatch()
                            {
                                Id = 2,
                                Match = "2015-06-28"
                            },
                            new RegExTractorMatch()
                            {
                                Id = 3,
                                Match = "CatalogCacheUpdateJob perform"
                            },
                            new RegExTractorMatch()
                            {
                                Id = 4,
                                Match = " - Performing scheduled reload of catalog cache...\r"
                            }
                        }
                    },

                    // fourth match
                    new RegExTractorMatchCollection()
                    {
                        Id = 4,
                        MatchCollection = new List<RegExTractorMatch>()
                        {
                            new RegExTractorMatch()
                            {
                                Id = 1,
                                Match = "2015-06-28 01:01:29,226  INFO   [EJB default - 6] CatalogCacheUpdateJob perform - Scheduled catalog cache reload successfully completed.\r"
                            },
                            new RegExTractorMatch()
                            {
                                Id = 2,
                                Match = "2015-06-28"
                            },
                            new RegExTractorMatch()
                            {
                                Id = 3,
                                Match = "CatalogCacheUpdateJob perform"
                            },
                            new RegExTractorMatch()
                            {
                                Id = 4,
                                Match = " - Scheduled catalog cache reload successfully completed.\r"
                            }
                        }
                    }

                }
            };

            var expected = new List<Finding>() { expectedFinding1 };

            IRegExCrawler crawler = new SimpleRegExCrawler();
            var actual = crawler.Crawl(regExSearchList, content, expected[0].FileName, expected[0].FileFolder);

            var comparer = new CompareLogic();
            var compareResult = comparer.Compare(expected, actual);
            Assert.IsTrue(compareResult.AreEqual);
        }
        public void A03_SimpleRegExCrawlerTwoExpressionMultipleResultTest()
        {
            // Read the content
            string content = File.ReadAllText("./Testdata/testdata.log");

            // build search term one
            var regExSearchTerm1 = new RegExSearchTerm()
            {
                Expression = @"(\d{4}-\d{2}-\d{2}).+(CatalogCacheUpdateJob perform)(.+)",
                ExpressionFriendlyName = "SearchTerm 1"
            };

            // build search term two
            var regExSearchTerm2 = new RegExSearchTerm()
            {
                Expression = @"2015-06-27 12:03:04,721  INFO   \[EJB default - 5\] RuleChangeCommand executeChange - Setting entry 00.2285 to MODIFY",
                ExpressionFriendlyName = "Ex1"
            };

            // fill the search term list
            var regExSearchList = new List<RegExSearchTerm>() { regExSearchTerm1, regExSearchTerm2 };

            // build the expected findigs
            // build finding one

            var expectedFinding1 = new Finding()
            {
                Expression = @"(\d{4}-\d{2}-\d{2}).+(CatalogCacheUpdateJob perform)(.+)",
                ExpressionFriendlyName = "SearchTerm 1",
                FileFolder = @"D:\WORK\RegExTractor\src\RegExTractor\RegExTractorTests\bin\Debug\Testdata",
                FileName = "testdata.log",
                Match = new List<RegExTractorMatchCollection>()
                {
                    // first match
                    new RegExTractorMatchCollection()
                    {
                        Id = 1,
                        MatchCollection = new List<RegExTractorMatch>()
                        {
                            new RegExTractorMatch()
                            {
                                Id = 1,
                                Match = "2015-06-27 13:00:00,005  INFO   [EJB default - 2] CatalogCacheUpdateJob perform - Performing scheduled reload of catalog cache...\r"
                            },
                            new RegExTractorMatch()
                            {
                                Id = 2,
                                Match = "2015-06-27"
                            },
                            new RegExTractorMatch()
                            {
                                Id = 3,
                                Match = "CatalogCacheUpdateJob perform"
                            },
                            new RegExTractorMatch()
                            {
                                Id = 4,
                                Match = " - Performing scheduled reload of catalog cache...\r"
                            }
                        }
                    },

                    // second match
                    new RegExTractorMatchCollection()
                    {
                        Id = 2,
                        MatchCollection = new List<RegExTractorMatch>()
                        {
                            new RegExTractorMatch()
                            {
                                Id = 1,
                                Match = "2015-06-27 13:01:30,110  INFO   [EJB default - 2] CatalogCacheUpdateJob perform - Scheduled catalog cache reload successfully completed.\r"
                            },
                            new RegExTractorMatch()
                            {
                                Id = 2,
                                Match = "2015-06-27"
                            },
                            new RegExTractorMatch()
                            {
                                Id = 3,
                                Match = "CatalogCacheUpdateJob perform"
                            },
                            new RegExTractorMatch()
                            {
                                Id = 4,
                                Match = " - Scheduled catalog cache reload successfully completed.\r"
                            }
                        }
                    },

                    // third match
                    new RegExTractorMatchCollection()
                    {
                        Id = 3,
                        MatchCollection = new List<RegExTractorMatch>()
                        {
                            new RegExTractorMatch()
                            {
                                Id = 1,
                                Match = "2015-06-28 01:00:00,006  INFO   [EJB default - 6] CatalogCacheUpdateJob perform - Performing scheduled reload of catalog cache...\r"
                            },
                            new RegExTractorMatch()
                            {
                                Id = 2,
                                Match = "2015-06-28"
                            },
                            new RegExTractorMatch()
                            {
                                Id = 3,
                                Match = "CatalogCacheUpdateJob perform"
                            },
                            new RegExTractorMatch()
                            {
                                Id = 4,
                                Match = " - Performing scheduled reload of catalog cache...\r"
                            }
                        }
                    },

                    // fourth match
                    new RegExTractorMatchCollection()
                    {
                        Id = 4,
                        MatchCollection = new List<RegExTractorMatch>()
                        {
                            new RegExTractorMatch()
                            {
                                Id = 1,
                                Match = "2015-06-28 01:01:29,226  INFO   [EJB default - 6] CatalogCacheUpdateJob perform - Scheduled catalog cache reload successfully completed.\r"
                            },
                            new RegExTractorMatch()
                            {
                                Id = 2,
                                Match = "2015-06-28"
                            },
                            new RegExTractorMatch()
                            {
                                Id = 3,
                                Match = "CatalogCacheUpdateJob perform"
                            },
                            new RegExTractorMatch()
                            {
                                Id = 4,
                                Match = " - Scheduled catalog cache reload successfully completed.\r"
                            }
                        }
                    }

                }
            };

            // build finding two
            var expectedFinding2 = new Finding()
            {
                Expression = @"2015-06-27 12:03:04,721  INFO   \[EJB default - 5\] RuleChangeCommand executeChange - Setting entry 00.2285 to MODIFY",
                ExpressionFriendlyName = "Ex1",
                FileFolder = @"D:\WORK\RegExTractor\src\RegExTractor\RegExTractorTests\bin\Debug\Testdata",
                FileName = "testdata.log",
                Match = new List<RegExTractorMatchCollection>()
                {
                   new RegExTractorMatchCollection()
                   {
                       Id = 1,
                       MatchCollection = new List<RegExTractorMatch>()
                       {
                           new RegExTractorMatch()
                           {
                               Id = 1,
                               Match = "2015-06-27 12:03:04,721  INFO   [EJB default - 5] RuleChangeCommand executeChange - Setting entry 00.2285 to MODIFY"
                           }
                       }
                   }
                }
            };

            // build expected findings list
            var expected = new List<Finding>() { expectedFinding1, expectedFinding2 };

            // do the magic and crawl!
            IRegExCrawler crawler = new SimpleRegExCrawler();
            var actual = crawler.Crawl(regExSearchList, content, expectedFinding1.FileName, expectedFinding1.FileFolder);

            KellermanSoftware.CompareNetObjects.CompareLogic l = new KellermanSoftware.CompareNetObjects.CompareLogic();
            var result = l.Compare(expected, actual);
            Assert.IsTrue(result.AreEqual);

            // check the results
            // result for finding one
            Assert.AreEqual(expected[0].Expression, actual[0].Expression);
            Assert.AreEqual(expected[0].ExpressionFriendlyName, actual[0].ExpressionFriendlyName);
            //Assert.AreEqual(expected.FirstOrDefault().FileFolder, actual.FirstOrDefault().FileFolder);
            //Assert.AreEqual(expected.FirstOrDefault().FileName, actual.FirstOrDefault().FileName);

            var matchCount = actual[0].Match.Count();
            Assert.AreEqual(4, matchCount);

            for (int i = 0; i <= matchCount; i++)
            {
                var expectedMatch = expected[0].Match[0];
                var actualMatch = actual[0].Match[0];

                Assert.AreEqual(expectedMatch.Id, actualMatch.Id);
                Assert.AreEqual(expectedMatch.MatchCollection[0].Id, actualMatch.MatchCollection[0].Id);
                Assert.AreEqual(expectedMatch.MatchCollection[1].Id, actualMatch.MatchCollection[1].Id);
                Assert.AreEqual(expectedMatch.MatchCollection[2].Id, actualMatch.MatchCollection[2].Id);
            }

            // result for finding two
            Assert.AreEqual(expected[1].Expression, actual[1].Expression);
            Assert.AreEqual(expected[1].ExpressionFriendlyName, actual[1].ExpressionFriendlyName);
            //Assert.AreEqual(expected.FirstOrDefault().FileFolder, actual.FirstOrDefault().FileFolder);
            //Assert.AreEqual(expected.FirstOrDefault().FileName, actual.FirstOrDefault().FileName);

            matchCount = actual[1].Match.Count();
            Assert.AreEqual(1, matchCount);

            for (int i = 0; i <= matchCount; i++)
            {
                var expectedMatch = expected[1].Match[0];
                var actualMatch = actual[1].Match[0];

                Assert.AreEqual(expectedMatch.Id, actualMatch.Id);
                Assert.AreEqual(expectedMatch.MatchCollection[0].Id, actualMatch.MatchCollection[0].Id);
            }
        }
Exemplo n.º 30
0
        static CompareLogic createQSCompareLogic()
        {
            var logic = new CompareLogic ();
            //Должно стоять в true иначе не работает сравнение на винде Dictionary, так как в KeyValuePair поля со значением canWrite = false
            logic.Config.CompareReadOnly = true;
            logic.Config.CompareStaticFields = false;
            logic.Config.CompareStaticProperties = false;
            logic.Config.IgnoreCollectionOrder = true;
            logic.Config.MaxDifferences = 10000;
            logic.Config.MaxStructDepth = 10;
            logic.Config.CustomComparers.Add (new DomainObjectComparer(RootComparerFactory.GetRootComparer()));
            logic.Config.AttributesToIgnore.Add (typeof(IgnoreHistoryTraceAttribute));

            return logic;
        }
Exemplo n.º 31
0
        public void A03_SimpleRegExCrawlerTwoExpressionMultipleResultTest()
        {
            // Read the content
            string content = File.ReadAllText("./Testdata/testdata.log");

            // build search term one
            var regExSearchTerm1 = new RegExSearchTerm()
            {
                Expression             = @"(\d{4}-\d{2}-\d{2}).+(CatalogCacheUpdateJob perform)(.+)",
                ExpressionFriendlyName = "SearchTerm 1"
            };

            // build search term two
            var regExSearchTerm2 = new RegExSearchTerm()
            {
                Expression             = @"2015-06-27 12:03:04,721  INFO   \[EJB default - 5\] RuleChangeCommand executeChange - Setting entry 00.2285 to MODIFY",
                ExpressionFriendlyName = "Ex1"
            };

            // fill the search term list
            var regExSearchList = new List <RegExSearchTerm>()
            {
                regExSearchTerm1, regExSearchTerm2
            };

            // build the expected findigs
            // build finding one

            var expectedFinding1 = new Finding()
            {
                Expression             = @"(\d{4}-\d{2}-\d{2}).+(CatalogCacheUpdateJob perform)(.+)",
                ExpressionFriendlyName = "SearchTerm 1",
                FileFolder             = @"D:\WORK\RegExTractor\src\RegExTractor\RegExTractorTests\bin\Debug\Testdata",
                FileName = "testdata.log",
                Match    = new List <RegExTractorMatchCollection>()
                {
                    // first match
                    new RegExTractorMatchCollection()
                    {
                        Id = 1,
                        MatchCollection = new List <RegExTractorMatch>()
                        {
                            new RegExTractorMatch()
                            {
                                Id    = 1,
                                Match = "2015-06-27 13:00:00,005  INFO   [EJB default - 2] CatalogCacheUpdateJob perform - Performing scheduled reload of catalog cache...\r"
                            },
                            new RegExTractorMatch()
                            {
                                Id    = 2,
                                Match = "2015-06-27"
                            },
                            new RegExTractorMatch()
                            {
                                Id    = 3,
                                Match = "CatalogCacheUpdateJob perform"
                            },
                            new RegExTractorMatch()
                            {
                                Id    = 4,
                                Match = " - Performing scheduled reload of catalog cache...\r"
                            }
                        }
                    },

                    // second match
                    new RegExTractorMatchCollection()
                    {
                        Id = 2,
                        MatchCollection = new List <RegExTractorMatch>()
                        {
                            new RegExTractorMatch()
                            {
                                Id    = 1,
                                Match = "2015-06-27 13:01:30,110  INFO   [EJB default - 2] CatalogCacheUpdateJob perform - Scheduled catalog cache reload successfully completed.\r"
                            },
                            new RegExTractorMatch()
                            {
                                Id    = 2,
                                Match = "2015-06-27"
                            },
                            new RegExTractorMatch()
                            {
                                Id    = 3,
                                Match = "CatalogCacheUpdateJob perform"
                            },
                            new RegExTractorMatch()
                            {
                                Id    = 4,
                                Match = " - Scheduled catalog cache reload successfully completed.\r"
                            }
                        }
                    },

                    // third match
                    new RegExTractorMatchCollection()
                    {
                        Id = 3,
                        MatchCollection = new List <RegExTractorMatch>()
                        {
                            new RegExTractorMatch()
                            {
                                Id    = 1,
                                Match = "2015-06-28 01:00:00,006  INFO   [EJB default - 6] CatalogCacheUpdateJob perform - Performing scheduled reload of catalog cache...\r"
                            },
                            new RegExTractorMatch()
                            {
                                Id    = 2,
                                Match = "2015-06-28"
                            },
                            new RegExTractorMatch()
                            {
                                Id    = 3,
                                Match = "CatalogCacheUpdateJob perform"
                            },
                            new RegExTractorMatch()
                            {
                                Id    = 4,
                                Match = " - Performing scheduled reload of catalog cache...\r"
                            }
                        }
                    },

                    // fourth match
                    new RegExTractorMatchCollection()
                    {
                        Id = 4,
                        MatchCollection = new List <RegExTractorMatch>()
                        {
                            new RegExTractorMatch()
                            {
                                Id    = 1,
                                Match = "2015-06-28 01:01:29,226  INFO   [EJB default - 6] CatalogCacheUpdateJob perform - Scheduled catalog cache reload successfully completed.\r"
                            },
                            new RegExTractorMatch()
                            {
                                Id    = 2,
                                Match = "2015-06-28"
                            },
                            new RegExTractorMatch()
                            {
                                Id    = 3,
                                Match = "CatalogCacheUpdateJob perform"
                            },
                            new RegExTractorMatch()
                            {
                                Id    = 4,
                                Match = " - Scheduled catalog cache reload successfully completed.\r"
                            }
                        }
                    }
                }
            };

            // build finding two
            var expectedFinding2 = new Finding()
            {
                Expression             = @"2015-06-27 12:03:04,721  INFO   \[EJB default - 5\] RuleChangeCommand executeChange - Setting entry 00.2285 to MODIFY",
                ExpressionFriendlyName = "Ex1",
                FileFolder             = @"D:\WORK\RegExTractor\src\RegExTractor\RegExTractorTests\bin\Debug\Testdata",
                FileName = "testdata.log",
                Match    = new List <RegExTractorMatchCollection>()
                {
                    new RegExTractorMatchCollection()
                    {
                        Id = 1,
                        MatchCollection = new List <RegExTractorMatch>()
                        {
                            new RegExTractorMatch()
                            {
                                Id    = 1,
                                Match = "2015-06-27 12:03:04,721  INFO   [EJB default - 5] RuleChangeCommand executeChange - Setting entry 00.2285 to MODIFY"
                            }
                        }
                    }
                }
            };

            // build expected findings list
            var expected = new List <Finding>()
            {
                expectedFinding1, expectedFinding2
            };

            // do the magic and crawl!
            IRegExCrawler crawler = new SimpleRegExCrawler();
            var           actual  = crawler.Crawl(regExSearchList, content, expectedFinding1.FileName, expectedFinding1.FileFolder);

            KellermanSoftware.CompareNetObjects.CompareLogic l = new KellermanSoftware.CompareNetObjects.CompareLogic();
            var result = l.Compare(expected, actual);

            Assert.IsTrue(result.AreEqual);

            // check the results
            // result for finding one
            Assert.AreEqual(expected[0].Expression, actual[0].Expression);
            Assert.AreEqual(expected[0].ExpressionFriendlyName, actual[0].ExpressionFriendlyName);
            //Assert.AreEqual(expected.FirstOrDefault().FileFolder, actual.FirstOrDefault().FileFolder);
            //Assert.AreEqual(expected.FirstOrDefault().FileName, actual.FirstOrDefault().FileName);

            var matchCount = actual[0].Match.Count();

            Assert.AreEqual(4, matchCount);


            for (int i = 0; i <= matchCount; i++)
            {
                var expectedMatch = expected[0].Match[0];
                var actualMatch   = actual[0].Match[0];

                Assert.AreEqual(expectedMatch.Id, actualMatch.Id);
                Assert.AreEqual(expectedMatch.MatchCollection[0].Id, actualMatch.MatchCollection[0].Id);
                Assert.AreEqual(expectedMatch.MatchCollection[1].Id, actualMatch.MatchCollection[1].Id);
                Assert.AreEqual(expectedMatch.MatchCollection[2].Id, actualMatch.MatchCollection[2].Id);
            }


            // result for finding two
            Assert.AreEqual(expected[1].Expression, actual[1].Expression);
            Assert.AreEqual(expected[1].ExpressionFriendlyName, actual[1].ExpressionFriendlyName);
            //Assert.AreEqual(expected.FirstOrDefault().FileFolder, actual.FirstOrDefault().FileFolder);
            //Assert.AreEqual(expected.FirstOrDefault().FileName, actual.FirstOrDefault().FileName);

            matchCount = actual[1].Match.Count();
            Assert.AreEqual(1, matchCount);


            for (int i = 0; i <= matchCount; i++)
            {
                var expectedMatch = expected[1].Match[0];
                var actualMatch   = actual[1].Match[0];

                Assert.AreEqual(expectedMatch.Id, actualMatch.Id);
                Assert.AreEqual(expectedMatch.MatchCollection[0].Id, actualMatch.MatchCollection[0].Id);
            }
        }