Пример #1
0
        private static void ProcessBuildInstance(string build, PEUTEST002Entities dbc, BuildDefinition buildDefinition)
        {
            try
            {
                var      dateStr           = GetTestDateString(Directory.GetCreationTime(build));
                TestDate dbDate            = GetAddTestDate(dbc, dateStr);
                var      buildInstanceName = Path.GetFileName(build);

                var           buildDefnId   = buildDefinition.BuildDefinitionId;
                BuildInstance buildInstance = GetAddBuildInstance(dbc, buildDefnId, buildInstanceName, dateStr);

                //var resultsDir = Path.Combine(buildDefinition.ResultsShare, buildDefinition.BuildDefinitionName, build, buildDefinition.ResultsPath);
                foreach (string resultsDir in Directory.GetDirectories(build, buildDefinition.ResultsPath, SearchOption.TopDirectoryOnly))
                {
                    foreach (string xmlFile in Directory.GetFiles(resultsDir, "TestResult_*.xml", SearchOption.AllDirectories))
                    {
                        ProcessAssembly(dbc, xmlFile, buildInstance, resultsDir);
                    }
                }
                //var resultsDir = Path.Combine(build, buildDefinition.ResultsPath);
            }
            catch (Exception ex1Exception)
            {
                WriteException(ex1Exception);
                //Environment.Exit(-1);
            }
        }
Пример #2
0
        private static BuildInstance GetAddBuildInstance(PEUTEST002Entities dbc, int buildDefnId, string buildInstanceName, string dateStr)
        {
            var countBuildInstances = (from x in DatabaseInstance.BuildInstances
                                       where x.BuildDefinitionId == buildDefnId && x.BuildInstanceName == buildInstanceName
                                       select x).Count();

            if (countBuildInstances <= 0)
            {
                dbc.BuildInstances.Add(new BuildInstance
                {
                    BuildDefinitionId = buildDefnId,
                    BuildInstanceName = buildInstanceName,
                    DateId            = dateStr
                });
                dbc.SaveChanges();

                BuildInstance bi = (from x in dbc.BuildInstances
                                    where x.BuildDefinitionId == buildDefnId && x.BuildInstanceName == buildInstanceName
                                    select x).ToList()[0];
                Console.WriteLine($"Added Build Instance {bi.BuildDefinition.BuildDefinitionName} / {buildInstanceName}");
                DatabaseInstance.BuildInstances.Add(bi);
            }
            return((from x in DatabaseInstance.BuildInstances
                    where x.BuildDefinitionId == buildDefnId && x.BuildInstanceName == buildInstanceName
                    select x).ToList()[0]);
        }
Пример #3
0
        private static void UpdateTableAssembly(PEUTEST002Entities dbc)
        {
            DataTable dt_assembly = new DataTable();

            dt_assembly.Columns.Add(new DataColumn("AssemblyName", typeof(string)));
            dt_assembly.Columns.Add(new DataColumn("AssemblyRelativePath", typeof(string)));
            foreach (LocalAssembly assembly in LocalCollection.LocalAssemblies)
            {
                if (assembly.AssemblyName.Length <= 100 && assembly.AssemblyRelativePath.Length <= 100)
                {
                    DataRow dr = dt_assembly.NewRow();
                    dr["AssemblyName"]         = assembly.AssemblyName;
                    dr["AssemblyRelativePath"] = assembly.AssemblyRelativePath;
                    dt_assembly.Rows.Add(dr);
                }
            }


            string tempTableName = $"##TempAssembliesTable_{DateTime.UtcNow.Ticks}";
            string fields        = @"(
    [AssemblyName] [varchar](100) NOT NULL,
    [AssemblyRelativePath] [varchar](100) NOT NULL,
    [AssemblyId] [int] NULL
)";

            string queryInsert =
                $@"
INSERT INTO [PEUTEST002].[dbo].[Assembly] 
(
AssemblyName, 
AssemblyRelativePath
)
(
SELECT DISTINCT B.AssemblyName, B.AssemblyRelativePath
FROM  [PEUTEST002].[dbo].[Assembly] A
RIGHT JOIN [PEUTEST002].[dbo].[{tempTableName}] B
ON 
    A.AssemblyName	 = B.AssemblyName
AND A.AssemblyRelativePath		 = B.AssemblyRelativePath
WHERE A.AssemblyId IS NULL
)";
            string queryUpdate =
                $@"UPDATE    [PEUTEST002].[dbo].[Assembly] 
SET
AssemblyName         = B.AssemblyName, 
AssemblyRelativePath = B.AssemblyRelativePath
FROM         [PEUTEST002].[dbo].[Assembly]  A
INNER JOIN   [PEUTEST002].[dbo].[{tempTableName}] B
ON A.AssemblyName = B.AssemblyName 
AND A.AssemblyRelativePath = B.AssemblyRelativePath";

            RunSqlQueries(dt_assembly, tempTableName, fields, queryInsert, queryUpdate);

            UpdateIds(dbc);
        }
Пример #4
0
        private static void UpdateTableTestcase(PEUTEST002Entities dbc)
        {
            DataTable dt_testcase = new DataTable();

            dt_testcase.Columns.Add(new DataColumn("FixtureId", typeof(int)));
            dt_testcase.Columns.Add(new DataColumn("TestcaseName", typeof(string)));
            dt_testcase.Columns.Add(new DataColumn("TestcaseFullName", typeof(string)));


            foreach (LocalTestcase testcase in LocalCollection.AllLocalTestcases)
            {
                if (testcase.TestcaseName.Length <= 800 && testcase.TestcaseFullName.Length <= 1100 && testcase.FixtureId != 0)
                {
                    DataRow dr = dt_testcase.NewRow();
                    dr["FixtureId"]        = testcase.FixtureId;
                    dr["TestcaseName"]     = testcase.TestcaseName;
                    dr["TestcaseFullName"] = testcase.TestcaseFullName;
                    dt_testcase.Rows.Add(dr);
                }
            }
            string tempTableName = $"##TempTestcaseTable_{DateTime.UtcNow.Ticks}";
            string fields        = @"(
    [TestcaseId] [int]  NULL,
    [FixtureId] [int] NOT NULL,
    [TestcaseName] [varchar](800) NOT NULL,
    [TestcaseFullName] [varchar](1100) NULL
)";

            string queryInsert =
                $@"
INSERT INTO [PEUTEST002].[dbo].[Testcase] 
(
TestcaseName, 
TestcaseFullName,
FixtureId
)
(
SELECT DISTINCT  B.TestcaseName, B.TestcaseFullName, B.FixtureId
FROM  [PEUTEST002].[dbo].[Testcase] A
RIGHT JOIN [PEUTEST002].[dbo].[{tempTableName}] B
ON 
    A.FixtureId	     = B.FixtureId
AND A.TestcaseFullName	 = B.TestcaseFullName
AND A.TestcaseName		 = B.TestcaseName
WHERE A.TestcaseId IS NULL
)";
            string queryUpdate =
                $@"--noop";

            RunSqlQueries(dt_testcase, tempTableName, fields, queryInsert, queryUpdate);

            UpdateIds(dbc);
        }
Пример #5
0
        private static void UpdateIds(PEUTEST002Entities dbc)
        {
            var smallList = (from x in dbc.Assemblies
                             select x).ToList();

            foreach (Assembly assembly in smallList)
            {
                //Console.WriteLine($"{assembly.AssemblyName} / {assembly.AssemblyRelativePath}");
            }
            //foreach (Assembly assembly in smallList)
            foreach (LocalAssembly la in LocalCollection.LocalAssemblies)
            {
                //Console.WriteLine($"Checking {la.AssemblyName} / {la.AssemblyRelativePath}");
                //LocalAssembly laa = new LocalAssembly(assembly.AssemblyName, assembly.AssemblyRelativePath);
                Assembly assembly = (from x in smallList
                                     where x.AssemblyName.Equals(la.AssemblyName) && x.AssemblyRelativePath.Equals(la.AssemblyRelativePath)
                                     select x).ToList().First();
                //LocalAssembly la = (from x in LocalCollection.LocalAssemblies
                //                   where x.Equals(laa)
                //                   select x).ToList().First();
                la.AssemblyId = assembly.AssemblyId;
                foreach (LocalFixture lf in la.LocalFixtures)
                {
                    foreach (Fixture fixx in (from x in assembly.Fixtures
                                              where x.FixtureName == lf.FixtureName && x.FixtureFullName == lf.FixtureFullName && lf.AssemblyId == x.AssemblyId
                                              select x))
                    {
                        lf.FixtureId = fixx.FixtureId;
                        foreach (LocalTestcase lt in lf.LocalTestcases)
                        {
                            foreach (Testcase tcc in (from x in fixx.Testcases
                                                      where x.TestcaseName == lt.TestcaseName && x.TestcaseFullName == lt.TestcaseFullName && x.FixtureId == lt.FixtureId
                                                      select x))
                            {
                                lt.TestcaseId = tcc.TestcaseId;
                                break;
                            }
                        }
                        break;
                    }
                }
            }
        }
Пример #6
0
        private static TestDate GetAddTestDate(PEUTEST002Entities dbc, string TestDateStr)
        {
            var count = (from u in DatabaseInstance.TestDates
                         where u.DateId == TestDateStr
                         select u).Count();

            if (count <= 0)
            {
                dbc.TestDates.Add(new TestDate {
                    DateId = TestDateStr
                });
                dbc.SaveChanges();
                TestDate td = (from u in dbc.TestDates
                               where u.DateId == TestDateStr
                               select u).ToList()[0];
                DatabaseInstance.TestDates.Add(td);
            }
            return((from u in DatabaseInstance.TestDates
                    where u.DateId == TestDateStr
                    select u).ToList()[0]);
        }
Пример #7
0
        private static void UpdateTableTestReport(PEUTEST002Entities dbc)
        {
            DataTable dt_reports = new DataTable();

            dt_reports.Columns.Add(new DataColumn("BuildInstanceId", typeof(int)));
            dt_reports.Columns.Add(new DataColumn("MachineName", typeof(string)));
            dt_reports.Columns.Add(new DataColumn("Success", typeof(bool)));
            dt_reports.Columns.Add(new DataColumn("Executed", typeof(bool)));
            dt_reports.Columns.Add(new DataColumn("Time", typeof(int)));
            dt_reports.Columns.Add(new DataColumn("Message", typeof(string)));
            dt_reports.Columns.Add(new DataColumn("StackTrace", typeof(string)));
            dt_reports.Columns.Add(new DataColumn("TestcaseId", typeof(int)));

            foreach (LocalReport rpt in LocalCollection.AllLocalReports)
            {
                if (rpt.MachineName.Length > 150)
                {
                    rpt.MachineName = rpt.MachineName.Substring(0, 150);
                }
                DataRow dr = dt_reports.NewRow();
                dr["BuildInstanceId"] = rpt.BuildInstanceId;
                if (rpt.MachineName != null)
                {
                    dr["MachineName"] = rpt.MachineName;
                }
                dr["Success"]  = rpt.Success;
                dr["Executed"] = rpt.Executed;
                dr["Time"]     = rpt.Time;
                if (rpt.Message != null)
                {
                    dr["Message"] = rpt.Message; // == null ? DBNull.Value : rpt.Message;
                }
                if (rpt.StackTrace != null)
                {
                    dr["StackTrace"] = rpt.StackTrace; // == null ? DBNull.Value : (object)rpt.StackTrace;
                }
                dr["TestcaseId"] = rpt.TestcaseId;
                dt_reports.Rows.Add(dr);
            }
            string tempTableName = $"TempReportTable_{DateTime.UtcNow.Ticks}";
            string fields        = @"(
    [ReportId] [int] NULL,
    [BuildInstanceId] [int] NOT NULL,
    [MachineName] [varchar](150) NULL,
    [Success] [bit] NOT NULL,
    [Executed] [bit] NOT NULL,
    [Time] [int] NOT NULL,
    [Message] [varchar](max) NULL,
    [StackTrace] [varchar](max) NULL,
    [TestcaseId] [int] NOT NULL
)";
            string queryInsert   =
                $@"
INSERT INTO [PEUTEST002].[dbo].[TestReport] 
(
     BuildInstanceId,
     MachineName,
     Success,
     Executed,
     Time,
     Message,
     StackTrace,
     TestcaseId
)
(
SELECT DISTINCT       
     B.BuildInstanceId,
     B.MachineName,
     B.Success,
     B.Executed,
     B.Time,
     B.Message,
     B.StackTrace,
     B.TestcaseId
FROM  [PEUTEST002].[dbo].[TestReport] A
RIGHT JOIN [PEUTEST002].[dbo].[{tempTableName}] B
ON 
    A.BuildInstanceId	     = B.BuildInstanceId
AND A.TestcaseId	 = B.TestcaseId
WHERE A.ReportId IS NULL AND B.TestcaseId <> 0
)";

            string queryUpdate =
                $@"--noop";

            RunSqlQueries(dt_reports, tempTableName, fields, queryInsert, queryUpdate);
        }
Пример #8
0
        private static void ProcessAssembly(PEUTEST002Entities dbc, string xmlFile, BuildInstance buildInstance, string resultsDir)
        {
            try
            {
                var         share = buildInstance.BuildDefinition.ResultsShare;
                XmlDocument xdoc  = new XmlDocument();
                xdoc.Load(CopyLocal(share, xmlFile));

                if (!CheckIfValidNUnitXml(xdoc))
                {
                    return;
                }

                Console.WriteLine($"Loaded file {xmlFile} {buildInstance.BuildInstanceName}");

                //var asemblyname = GetAssemblyName(xdoc);
                var    vmName          = GetVmName(xdoc);
                string assemblyName    = GetAssemblyName(xdoc);
                string xmlRelativePath = Path.GetDirectoryName(xmlFile).Replace($"{resultsDir}\\", string.Empty);
                //Assembly assembly = GetAddAssembly(dbc, assemblyName, xmlRelativePath);
                AddAssembly(assemblyName, xmlRelativePath);


                foreach (XmlNode testcaseNode in xdoc.GetElementsByTagName("test-case"))
                {
                    try
                    {
                        XmlNode fixtureNode     = GetFixtureNode(testcaseNode);
                        var     fixtureName     = FormatChars(fixtureNode.Attributes["name"].Value);
                        var     fixtureFullName = GetFixtureFullNamespacePath(fixtureNode);

                        var testcaseFullName = FormatChars(testcaseNode.Attributes["name"].Value).Trim('.');
                        var testcaseName     = testcaseFullName.Replace($"{fixtureFullName}.", string.Empty);

                        bool   executed, success;
                        int    time;
                        string message, stacktrace;
                        GetValues(testcaseNode, out executed, out success, out time, out message, out stacktrace);


                        if (testcaseName == testcaseFullName)
                        {
                            testcaseName = GetTestcaseNameFromFullName(testcaseFullName);
                        }
                        if (testcaseName == testcaseFullName)
                        {
                            throw new Exception($"Unable to find testcase correct name: TestcaseName:{testcaseFullName}");
                        }
                        //testcaseFullName.Replace($"{fixtureFullName}.", string.Empty);

                        if (!testcaseFullName.Contains(fixtureFullName))
                        {
                            // Console.WriteLine($"#### Fixture <> Testcasename : Fixturename={fixtureFullName} / Testcasename={testcaseFullName}");
                            //fixtureFullName = testcaseFullName.Substring(0, testcaseFullName.LastIndexOf("."));
                            //throw new Exception($"Unable to find testcase/fixture correct name: Fixname:{fixtureNameFull}, TestcaseName:{testcaseFullName}");
                        }
                        if (!fixtureFullName.Contains(fixtureName))
                        {
                            //fixtureNameFull = testcaseFullName.Substring(0, testcaseFullName.LastIndexOf("."));
                            throw new Exception($"Unable to find fixture correct name: Fixname:{fixtureFullName} / FixtureName:{fixtureName} / TestcaseName:{testcaseFullName}");
                        }
                        //Fixture fixture = GetAddFixture(dbc, fixtureFullName, fixtureName, assembly.AssemblyId);
                        AddFixture(fixtureFullName, fixtureName);
                        try
                        {
                            //var fixtureId = fixture.FixtureId;
                            if (testcaseName == testcaseFullName)
                            {
                                throw new Exception($"Unable to find testcase/fixture correct name: Fixname:{fixtureFullName}, TestcaseName:{testcaseFullName}");
                            }
                            //Testcase testcase = GetAddTestcase(dbc, testcaseName, testcaseFullName, fixtureId);
                            AddTestcase(testcaseName, testcaseFullName);
                            try
                            {
                                AddReport(buildInstance.BuildInstanceId, time, vmName, executed, success, message, stacktrace);
                            }
                            catch (Exception eeee)
                            {
                                WriteException(eeee);
                            }
                        }
                        catch (Exception eee)
                        {
                            WriteException(eee);
                        }
                    }
                    catch (Exception exception)
                    {
                        WriteException(exception);
                        //Environment.Exit(-1);
                    }
                }
                //foreach (XmlNode testcaseNode in xdoc.GetElementsByTagName("test-case"))
                //{
                //    ProcessFixture(dbc, testcaseNode, assembly);
                //}
            }
            catch (Exception ex2Exception)
            {
                WriteException(ex2Exception);
                //Environment.Exit(-1);
            }
        }
Пример #9
0
        static void Main(string[] args)
        {
            try
            {
                //DriveSettings.MapNetworkDrive(@"D:\JDOCS\IC007161\Documents\Visual Studio 2015\Projects\GitHub\Repos\GitHubJessRepos001\UpdateTestReports\UpdateTestsReports\bin\Debug");

                //throw new Exception("hats off");

                using (PEUTEST002Entities dbc = new PEUTEST002Entities())
                {
                    //Dictionary<int, string> dictBuildDefinitions = (from x in dbc.BuildDefinitions
                    //    select x).ToDictionary(y => y.BuildDefinitionId, x => x.BuildDefinitionName);

                    //Dictionary<int, string> dictBuildInstances = (from x in dbc.BuildInstances
                    //    select x).ToDictionary(x => x.BuildInstanceId, y => y.BuildInstanceName);

                    DatabaseInstance.BuildInstances = (from x in dbc.BuildInstances
                                                       select x).ToList();

                    DatabaseInstance.TestDates = (from x in dbc.TestDates
                                                  select x).ToList();

                    //DatabaseInstance.Assemblies = (from x in dbc.Assemblies
                    //    select x).ToList();

                    //DatabaseInstance.TestReports = (from x in dbc.TestReports
                    //    select x).ToList();


                    foreach (TiaVersion tiaVersion in dbc.TiaVersions.ToList())
                    {
                        foreach (BuildDefinition buildDefinition in (from x in dbc.BuildDefinitions
                                                                     where x.VersionName == tiaVersion.VersionName
                                                                     select x).ToList())
                        {
                            //var resultpath = Path.Combine(buildDefinition.ResultsShare, buildDefinition.BuildDefinitionName);
                            int count = 0;
                            foreach (string build in Directory.GetDirectories(buildDefinition.ResultsShare, buildDefinition.BuildDefinitionPattern, SearchOption.TopDirectoryOnly).Reverse())
                            {
                                ProcessBuildInstance(build, dbc, buildDefinition);
                                if (++count >= 2)
                                {
                                    break;
                                }
                            }
                        }
                    }


                    UpdateIds(dbc);

                    UpdateTableAssembly(dbc);
                    UpdateTableFixture(dbc);
                    UpdateTableTestcase(dbc);
                    UpdateTableTestReport(dbc);
                }
            }
            catch (Exception exception)
            {
                WriteException(exception);
            }
        }