예제 #1
0
        public void MergeExistingFilesTest()
        {
            var reports = LoadReport();

            var sanitizer = new ReportSanitizer(new NullLogger <ReportSanitizer>());

            sanitizer.Sanitize(reports);

            var logger       = new MessageLogger <ReportMerger>();
            var reportMerger = new ReportMerger(logger);
            var mergedReport = reportMerger.Merge(reports);

            Assert.NotNull(mergedReport);
            Assert.Null(mergedReport.Sources);

            Assert.Single(mergedReport.Packages.Package);
            var package = mergedReport.Packages.Package[0];

            Assert.Equal("DummyProject.Server", package.Name);

            Assert.Equal(2, package.Classes.Class.Count);

            var class0 = package.Classes.Class[0];

            Assert.Equal(3, class0.Methods.Method.Count);
            Assert.Contains(class0.Methods.Method, m => m.Name == "DummyMethod1");
            Assert.Contains(class0.Methods.Method, m => m.Name == "DummyMethod2");
            Assert.Contains(class0.Methods.Method, m => m.Name == "DummyMethod4");

            Assert.Equal(15, class0.Lines.Line.Count);

            var class1 = package.Classes.Class[1];

            Assert.Single(class1.Methods.Method);
            Assert.Equal(5, class1.Lines.Line.Count);
            Assert.Contains(class1.Methods.Method, m => m.Name == "DummyMethod3");

            Assert.Equal(2, logger.Messages.Count);
            Assert.Equal("Merging reports...", logger.Messages[0]);
            Assert.Equal("Making all file names absolute.", logger.Messages[1]);
        }
예제 #2
0
        public void SanitizeExistingFileTest()
        {
            var reports = LoadReport();

            var logger    = new MessageLogger <ReportSanitizer>();
            var sanitizer = new ReportSanitizer(logger);

            sanitizer.Sanitize(reports);

            var report1 = reports[0];

            Assert.NotNull(report1);

            var package1 = report1.Packages.Package[0];

            Assert.NotNull(package1);

            Assert.Equal(2, package1.Classes.Class.Count);

            var class10 = package1.Classes.Class[0];

            Assert.Equal(3, class10.Methods.Method.Count);
            Assert.Contains(class10.Methods.Method, m => m.Name == "DummyMethod1");
            Assert.Contains(class10.Methods.Method, m => m.Name == "DummyMethod2");
            Assert.Contains(class10.Methods.Method, m => m.Name == "DummyMethod4");

            var class11 = package1.Classes.Class[1];

            Assert.Single(class11.Methods.Method);
            Assert.Contains(class11.Methods.Method, m => m.Name == "DummyMethod3");

            var report2 = reports[1];

            Assert.NotNull(report2);

            var package2 = report2.Packages.Package[0];

            Assert.NotNull(package2);

            Assert.Equal(2, package2.Classes.Class.Count);

            var class20 = package2.Classes.Class[0];

            Assert.Equal(3, class20.Methods.Method.Count);
            Assert.Contains(class20.Methods.Method, m => m.Name == "DummyMethod1");
            Assert.Contains(class20.Methods.Method, m => m.Name == "DummyMethod2");
            Assert.Contains(class20.Methods.Method, m => m.Name == "DummyMethod4");

            var class21 = package2.Classes.Class[1];

            Assert.Single(class21.Methods.Method);
            Assert.Contains(class21.Methods.Method, m => m.Name == "DummyMethod3");

            Assert.Equal(7, logger.Messages.Count);
            Assert.Equal("Sanitizing reports...", logger.Messages[0]);
            Assert.Equal("Renamed class 'DummyProject.Server.Controllers.DummyController' to 'DummyProject.Server.Controllers.DummyController (0)' to prevent mixup in the coverge report.", logger.Messages[1]);
            Assert.Equal("Renamed class 'DummyProject.Server.Controllers.DummyController' to 'DummyProject.Server.Controllers.DummyController (1)' to prevent mixup in the coverge report.", logger.Messages[2]);
            Assert.Equal("Removed class 'DummyProject.Server.Controllers.DummyController/<DummyMethod4>d__12' which is really the method 'DummyMethod4' of class 'DummyProject.Server.Controllers.DummyController (0)'.", logger.Messages[3]);
            Assert.Equal("Renamed class 'DummyProject.Server.Controllers.DummyController' to 'DummyProject.Server.Controllers.DummyController (0)' to prevent mixup in the coverge report.", logger.Messages[4]);
            Assert.Equal("Renamed class 'DummyProject.Server.Controllers.DummyController' to 'DummyProject.Server.Controllers.DummyController (1)' to prevent mixup in the coverge report.", logger.Messages[5]);
            Assert.Equal("Removed class 'DummyProject.Server.Controllers.DummyController/<DummyMethod4>d__12' which is really the method 'DummyMethod4' of class 'DummyProject.Server.Controllers.DummyController (0)'.", logger.Messages[6]);
        }
        public void CalculateStatisticsTest()
        {
            var reports = LoadReport();

            var sanitizer = new ReportSanitizer(new NullLogger <ReportSanitizer>());

            sanitizer.Sanitize(reports);

            var reportMerger = new ReportMerger(new NullLogger <ReportMerger>());
            var mergedReport = reportMerger.Merge(reports);

            var logger           = new MessageLogger <ReportCalculator>();
            var reportCalculator = new ReportCalculator(logger);

            reportCalculator.CalculateStatistics(mergedReport);

            Assert.Single(mergedReport.Packages.Package);

            var package = mergedReport.Packages.Package[0];

            Assert.Equal("DummyProject.Server", package.Name);
            Assert.Equal(1, package.LineRate);
            Assert.Equal(1, package.BranchRate);
            Assert.Equal(0, package.Complexity);
            Assert.Equal(2, package.Classes.Class.Count);

            var class0 = package.Classes.Class[0];

            Assert.Equal("DummyProject.Server.Controllers.DummyController (0)", class0.Name);
            Assert.EndsWith(@"src\DummyProject.Server\Controllers\DummyController.cs", class0.Filename);
            Assert.Equal(1, class0.LineRate);
            Assert.Equal(1, class0.BranchRate);
            Assert.Equal(0, class0.Complexity);
            Assert.Equal(3, class0.Methods.Method.Count);
            Assert.Equal(15, class0.Lines.Line.Count);
            Assert.Contains(class0.Lines.Line, l => l.Number == 1 && l.Hits == 12 && l.ConditionCoverage == null);
            Assert.Contains(class0.Lines.Line, l => l.Number == 2 && l.Hits == 12 && l.ConditionCoverage == null);
            Assert.Contains(class0.Lines.Line, l => l.Number == 3 && l.Hits == 12 && l.ConditionCoverage == null);
            Assert.Contains(class0.Lines.Line, l => l.Number == 4 && l.Hits == 12 && l.ConditionCoverage == null);
            Assert.Contains(class0.Lines.Line, l => l.Number == 5 && l.Hits == 12 && l.ConditionCoverage == null);
            Assert.Contains(class0.Lines.Line, l => l.Number == 6 && l.Hits == 3 && l.ConditionCoverage == null);
            Assert.Contains(class0.Lines.Line, l => l.Number == 7 && l.Hits == 3 && l.ConditionCoverage == "100% (2/2)");
            Assert.Contains(class0.Lines.Line, l => l.Number == 8 && l.Hits == 3 && l.ConditionCoverage == null);
            Assert.Contains(class0.Lines.Line, l => l.Number == 9 && l.Hits == 3 && l.ConditionCoverage == null);
            Assert.Contains(class0.Lines.Line, l => l.Number == 10 && l.Hits == 3 && l.ConditionCoverage == null);
            Assert.Contains(class0.Lines.Line, l => l.Number == 11 && l.Hits == 6 && l.ConditionCoverage == null);
            Assert.Contains(class0.Lines.Line, l => l.Number == 12 && l.Hits == 6 && l.ConditionCoverage == null);
            Assert.Contains(class0.Lines.Line, l => l.Number == 13 && l.Hits == 6 && l.ConditionCoverage == null);
            Assert.Contains(class0.Lines.Line, l => l.Number == 14 && l.Hits == 6 && l.ConditionCoverage == null);
            Assert.Contains(class0.Lines.Line, l => l.Number == 15 && l.Hits == 6 && l.ConditionCoverage == null);

            var method01 = class0.Methods.Method[0];

            Assert.Equal("DummyMethod1", method01.Name);
            Assert.Equal(1, method01.LineRate);
            Assert.Equal(1, method01.BranchRate);
            Assert.Contains(method01.Lines.Line, l => l.Number == 1 && l.Hits == 12 && l.ConditionCoverage == null);
            Assert.Contains(method01.Lines.Line, l => l.Number == 2 && l.Hits == 12 && l.ConditionCoverage == null);
            Assert.Contains(method01.Lines.Line, l => l.Number == 3 && l.Hits == 12 && l.ConditionCoverage == null);
            Assert.Contains(method01.Lines.Line, l => l.Number == 4 && l.Hits == 12 && l.ConditionCoverage == null);
            Assert.Contains(method01.Lines.Line, l => l.Number == 5 && l.Hits == 12 && l.ConditionCoverage == null);

            var method02 = class0.Methods.Method[1];

            Assert.Equal("DummyMethod2", method02.Name);
            Assert.Equal(1, method02.LineRate);
            Assert.Equal(1, method02.BranchRate);
            Assert.Contains(method02.Lines.Line, l => l.Number == 6 && l.Hits == 3 && l.ConditionCoverage == null);
            Assert.Contains(method02.Lines.Line, l => l.Number == 7 && l.Hits == 3 && l.ConditionCoverage == "100% (2/2)");
            Assert.Contains(method02.Lines.Line, l => l.Number == 8 && l.Hits == 3 && l.ConditionCoverage == null);
            Assert.Contains(method02.Lines.Line, l => l.Number == 9 && l.Hits == 3 && l.ConditionCoverage == null);
            Assert.Contains(method02.Lines.Line, l => l.Number == 10 && l.Hits == 3 && l.ConditionCoverage == null);

            var method03 = class0.Methods.Method[2];

            Assert.Equal("DummyMethod4", method03.Name);
            Assert.Equal(1, method03.LineRate);
            Assert.Equal(1, method03.BranchRate);
            Assert.Contains(method03.Lines.Line, l => l.Number == 11 && l.Hits == 6 && l.ConditionCoverage == null);
            Assert.Contains(method03.Lines.Line, l => l.Number == 12 && l.Hits == 6 && l.ConditionCoverage == null);
            Assert.Contains(method03.Lines.Line, l => l.Number == 13 && l.Hits == 6 && l.ConditionCoverage == null);
            Assert.Contains(method03.Lines.Line, l => l.Number == 14 && l.Hits == 6 && l.ConditionCoverage == null);
            Assert.Contains(method03.Lines.Line, l => l.Number == 15 && l.Hits == 6 && l.ConditionCoverage == null);

            var class1 = package.Classes.Class[1];

            Assert.Equal("DummyProject.Server.Controllers.DummyController (1)", class1.Name);
            Assert.EndsWith(@"src\DummyProject.Server\Controllers\DummyControllerPartial.cs", class1.Filename);
            Assert.Equal(1, class1.LineRate);
            Assert.Equal(1, class1.BranchRate);
            Assert.Single(class1.Methods.Method);
            Assert.Equal(5, class1.Lines.Line.Count);
            Assert.Contains(class1.Lines.Line, l => l.Number == 1 && l.Hits == 24 && l.ConditionCoverage == null);
            Assert.Contains(class1.Lines.Line, l => l.Number == 2 && l.Hits == 24 && l.ConditionCoverage == null);
            Assert.Contains(class1.Lines.Line, l => l.Number == 3 && l.Hits == 24 && l.ConditionCoverage == null);
            Assert.Contains(class1.Lines.Line, l => l.Number == 4 && l.Hits == 24 && l.ConditionCoverage == null);
            Assert.Contains(class1.Lines.Line, l => l.Number == 5 && l.Hits == 24 && l.ConditionCoverage == null);

            var method11 = class1.Methods.Method[0];

            Assert.Equal("DummyMethod3", method11.Name);
            Assert.Equal(1, method11.LineRate);
            Assert.Equal(1, method11.BranchRate);
            Assert.Contains(method11.Lines.Line, l => l.Number == 1 && l.Hits == 24 && l.ConditionCoverage == null);
            Assert.Contains(method11.Lines.Line, l => l.Number == 2 && l.Hits == 24 && l.ConditionCoverage == null);
            Assert.Contains(method11.Lines.Line, l => l.Number == 3 && l.Hits == 24 && l.ConditionCoverage == null);
            Assert.Contains(method11.Lines.Line, l => l.Number == 4 && l.Hits == 24 && l.ConditionCoverage == null);
            Assert.Contains(method11.Lines.Line, l => l.Number == 5 && l.Hits == 24 && l.ConditionCoverage == null);

            Assert.Single(logger.Messages);
            Assert.Equal("Calculating the statistics of the merged report...", logger.Messages[0]);
        }