Пример #1
0
        private static void DrawObjectCollider(Graphics g, TmxMap tmxMap, TmxObject tmxObject, Color color)
        {
            using (Brush brush = TmxHelper.CreateObjectColliderBrush(color))
                using (Pen pen = new Pen(color))
                {
                    GraphicsState state = g.Save();

                    PointF xfPosition = TmxMath.ObjectPointFToMapSpace(tmxMap, tmxObject.Position);
                    g.TranslateTransform(xfPosition.X, xfPosition.Y);
                    g.RotateTransform(tmxObject.Rotation);

                    if (tmxObject.GetType() == typeof(TmxObjectPolygon))
                    {
                        DrawPolygon(g, pen, brush, tmxMap, tmxObject as TmxObjectPolygon);
                    }
                    else if (tmxObject.GetType() == typeof(TmxObjectRectangle))
                    {
                        if (tmxMap.Orientation == TmxMap.MapOrientation.Isometric)
                        {
                            TmxObjectPolygon tmxIsometricRectangle = TmxObjectPolygon.FromRectangle(tmxMap, tmxObject as TmxObjectRectangle);
                            DrawPolygon(g, pen, brush, tmxMap, tmxIsometricRectangle);
                        }
                        else
                        {
                            // Rectangles are polygons
                            DrawPolygon(g, pen, brush, tmxMap, tmxObject as TmxObjectPolygon);
                        }
                    }
                    else if (tmxObject.GetType() == typeof(TmxObjectEllipse))
                    {
                        DrawEllipse(g, pen, brush, tmxMap, tmxObject as TmxObjectEllipse);
                    }
                    else if (tmxObject.GetType() == typeof(TmxObjectPolyline))
                    {
                        DrawPolyline(g, pen, tmxMap, tmxObject as TmxObjectPolyline);
                    }
                    else if (tmxObject.GetType() == typeof(TmxObjectTile))
                    {
                        GraphicsState tileState = g.Save();

                        TmxObjectTile tmxObjectTile = tmxObject as TmxObjectTile;
                        PrepareTransformForTileObject(g, tmxMap, tmxObjectTile);

                        // Draw the collisions
                        // Temporarily set orienation to Orthogonal for tile colliders
                        TmxMap.MapOrientation restoreOrientation = tmxMap.Orientation;
                        tmxMap.Orientation = TmxMap.MapOrientation.Orthogonal;
                        {
                            // Make up for the fact that the bottom-left corner is the origin
                            g.TranslateTransform(0, -tmxObjectTile.Tile.TileSize.Height);
                            foreach (var obj in tmxObjectTile.Tile.ObjectGroup.Objects)
                            {
                                DrawObjectCollider(g, tmxMap, obj, Color.Gray);
                            }
                        }
                        tmxMap.Orientation = restoreOrientation;

                        g.Restore(tileState);
                    }
                    else
                    {
                        g.Restore(state);
                        Logger.WriteWarning("Unhandled object: {0}", tmxObject.GetNonEmptyName());
                    }

                    // Restore our state
                    g.Restore(state);
                }
        }
        protected override void BeginProcessing()
        {
            CheckCmdletParameters();

            var dataObject = new ImportExportCmdletBaseDataObject {
                As                                    = As,
                Descending                            = Descending,
                ExcludeAutomatic                      = ExcludeAutomatic,
                FilterAll                             = FilterAll,
                FilterDescriptionContains             = FilterDescriptionContains,
                FilterFailed                          = FilterFailed,
                FilterIdContains                      = FilterIdContains,
                FilterNameContains                    = FilterNameContains,
                FilterNone                            = FilterNone,
                FilterNotTested                       = FilterNotTested,
                FilterOutAutomaticAndTechnicalResults = FilterOutAutomaticAndTechnicalResults,
                FilterOutAutomaticResults             = FilterOutAutomaticResults,
                FilterPassed                          = FilterPassed,
                FilterPassedWithBadSmell              = FilterPassedWithBadSmell,
                Id                                    = Id,
                Name                                  = Name,
                OrderByDateTime                       = OrderByDateTime,
                OrderByFailRate                       = OrderByFailRate,
                OrderById                             = OrderById,
                OrderByName                           = OrderByName,
                OrderByPassRate                       = OrderByPassRate,
                OrderByTimeSpent                      = OrderByTimeSpent,
                Path                                  = Path
            };

            string reportFormat = As.ToUpper();

            switch (reportFormat)
            {
            case "XML":
                // 20141112
                // still the old way
                // 20141114
                // TmxHelper.ImportResultsFromXML(dataObject, Path);
                var testResultsImporter = new TestResultsImporter();
                // TestData.TestSuites.AddRange(testResultsImporter.ImportResultsFromXML(dataObject, Path));
                if (testResultsImporter.LoadDocument(dataObject, Path))
                {
                    testResultsImporter.MergeTestPlatforms(TestData.TestPlatforms, testResultsImporter.ImportTestPlatformFromXdocument(testResultsImporter.ImportedDocument));
                    testResultsImporter.MergeTestSuites(TestData.TestSuites, testResultsImporter.ImportTestResultsFromXdocument(testResultsImporter.ImportedDocument));
                }
//                    testResultsImporter.MergeTestPlatforms(TestData.TestPlatforms, testResultsImporter.ImportPlatformsFromXML(dataObject, Path));
//                    testResultsImporter.MergeTestSuites(TestData.TestSuites, testResultsImporter.ImportResultsFromXML(dataObject, Path));

                break;

            case "JUNIT":
            case "JUNITXML":
                TmxHelper.ImportResultsFromJUnitXML(dataObject, Path);
                break;

            case "HTML":

                ImportResultsFromHTML(this, Path);
                break;

            case "CSV":
                ImportResultsFromCSV(Path);
                break;

            case "TEXT":
                ImportResultsFromTEXT(Path);
                break;

            case "ZIP":
                ImportResultsFromZIP(Path);
                break;

            default:

                break;
            }
        }
Пример #3
0
        protected override void WriteErrorMethod020SetTestResult(PSCmdletBase cmdlet, ErrorRecord errorRecord)
        {
            if (cmdlet == null)
            {
                return;
            }
            // write error to the test results collection
            // 20160116
            // TmxHelper.AddTestResultErrorDetail(errorRecord);
            TmxHelper.AddTestResultErrorDetail(errorRecord.Exception);

            // write test result label
            try {
                CurrentData.LastResult = null;

                string iInfo = string.Empty;
                if (!string.IsNullOrEmpty(((HasScriptBlockCmdletBase)cmdlet).TestResultName))
                {
                    TmxHelper.CloseTestResult(((HasScriptBlockCmdletBase)cmdlet).TestResultName,
                                              ((HasScriptBlockCmdletBase)cmdlet).TestResultId,
                                              false, // the only result: FAILED //((HasScriptBlockCmdletBase)cmdlet).TestPassed,
                                              false, // because of failure //((HasScriptBlockCmdletBase)cmdlet).KnownIssue,
                                                     // 20160116
                                                     // MyInvocation,
                                                     // 20160116
                                                     // errorRecord,
                                              errorRecord.Exception,
                                              string.Empty,
                                              TestResultOrigins.Automatic,
                                              false);
                }
                else
                {
                    if (!Preferences.EveryCmdletAsTestResult)
                    {
                        return;
                    }
                    ((HasScriptBlockCmdletBase)cmdlet).TestResultName =
                        GetGeneratedTestResultNameByPosition(
                            MyInvocation.Line,
                            MyInvocation.PipelinePosition);

                    ((HasScriptBlockCmdletBase)cmdlet).TestResultId = string.Empty;
                    ((HasScriptBlockCmdletBase)cmdlet).TestPassed   = false;

                    TmxHelper.CloseTestResult(((HasScriptBlockCmdletBase)cmdlet).TestResultName,
                                              string.Empty, //((HasScriptBlockCmdletBase)cmdlet).TestResultId, // empty, to be generated
                                              ((HasScriptBlockCmdletBase)cmdlet).TestPassed,
                                              false,        // isKnownIssue
                                                            // 20160116
                                                            // MyInvocation,
                                                            // 20160116
                                                            // errorRecord,
                                              errorRecord.Exception,
                                              string.Empty,
                                              TestResultOrigins.Automatic,
                                              false);
                }
            }
            catch {
                WriteVerbose(this, "for working with test results you need to import the TMX module");
            }
        }
Пример #4
0
        /// <summary>
        /// This example demonstrates how to generate test results and
        /// store them to a database and to an XML file.
        /// </summary>
        /// <param name="args"></param>
        public static void Main(string[] args)
        {
            // these are our collections: test suites plus test results
            var stories = new System.Collections.ArrayList();
            var results = new System.Collections.ArrayList();

            Console.WriteLine("generating test data");
            // generating test data
            stories.Add(new TestStory("01", "story01"));
            results.Add(new TestResult("001", "test result 01", "bla-bla-bla", "01", "PASSED"));
            results.Add(new TestResult("002", "test result 02", "bla-bla-bla", "01", "PASSED"));
            results.Add(new TestResult("003", "test result 03", "bla-bla-bla", "01", "PASSED"));
            stories.Add(new TestStory("02", "story01"));
            results.Add(new TestResult("123", "test result 123", "bla-bla-bla", "02", "PASSED"));
            results.Add(new TestResult("456", "test result 456", "bla-bla-bla", "02", "PASSED"));
            results.Add(new TestResult("789", "test result 789", "bla-bla-bla", "02", "FAILED"));
            stories.Add(new TestStory("03", "story01"));
            results.Add(new TestResult("abc", "test result abc", "bla-bla-bla", "03", "FAILED"));
            results.Add(new TestResult("def", "test result def", "bla-bla-bla", "03", "FAILED"));
            results.Add(new TestResult("xyz", "test result xyz", "bla-bla-bla", "03", "PASSED"));
            Console.WriteLine("test data have been generated");

            Console.WriteLine("writing test data to library");

            // generating test scenarios for previously generated suites and test results
            foreach (TestStory story in stories)
            {
                // creating a new test suite == user story
                TmxHelper.NewTestSuite(
                    story.Name,
                    story.Id,
                    // 20141114
                    // "platform",
                    Guid.NewGuid(),
                    "description",
                    null,
                    null);

                foreach (TestResult result in results)
                {
                    if (result.StoryId == story.Id)
                    {
                        var cmdlet = new AddScenarioCmdletBase {
                            Id          = result.Id,
                            Name        = result.Name,
                            Description = "description"
                        };

                        // adding a new test scenario to the test suite
                        // test scenario == name and id of th corresponding test result
                        // 20140721
                        var dataObject = new AddScenarioCmdletBaseDataObject {
                            // 20141211
                            // AfterTest = cmdlet.AfterTest,
                            // BeforeTest = cmdlet.BeforeTest,
                            AfterTest = cmdlet.AfterTest.Select(scriptblock => new CodeBlock {
                                Code = scriptblock.ToString()
                            }).ToArray(),
                            BeforeTest = cmdlet.BeforeTest.Select(scriptblock => new CodeBlock {
                                Code = scriptblock.ToString()
                            }).ToArray(),
                            Description    = cmdlet.Description,
                            Id             = cmdlet.Id,
                            InputObject    = cmdlet.InputObject,
                            Name           = cmdlet.Name,
                            TestPlatformId = cmdlet.TestPlatformId,
                            TestSuiteId    = cmdlet.TestSuiteId,
                            TestSuiteName  = cmdlet.TestSuiteName
                        };

                        // TmxHelper.AddTestScenario(cmdlet);
                        TmxHelper.AddTestScenario(dataObject);

                        // create a test result with the same name and id as the test scenario has
                        TmxHelper.CloseTestResult(
                            result.Name,
                            result.Id,
                            true,  // Passed
                            false, // not a KnownIssue
                            // 20160116
                            // null,
                            null,
                            "description",
                            // 20130322
                            //false);
                            // 20130626
                            //false,
                            TestResultOrigins.Logical,
                            true);
                    }
                }
            }
            Console.WriteLine("test data are ready");

            // blocked due to the need to remove dependency on SQLite
//            // creating a database
//            Console.WriteLine("creating DB");
//            SQLiteHelper.CreateDatabase(
//                new Tmx.DatabaseFileCmdletBase(),
//                @"c:\1\1.db3",
//                false,
//                false,
//                true);
//            Console.WriteLine("DB created");
//
//            // export test results to the DB
//            Console.WriteLine("exporting test data to the DB");
//            SQLiteHelper.BackupTestResults(
//                new CommonCmdletBase(),
//                TestData.CurrentResultsDB.Name);
//
//            // closing the database
//            Console.WriteLine("closing the DB");
//            SQLiteHelper.CloseDatabase(
//                new CommonCmdletBase(),
//                TestData.CurrentTestResult.Name);
//
//            // export data to an XML sheet
//            Console.WriteLine("export to XML");
//
//            // 20140721
//            var dataObject2 = new SearchCmdletBaseDataObject {
//                // FilterAll = AddScenarioCmdletBase.
//            };
//
//            TmxHelper.ExportResultsToXML(
//                // (new ImportExportCmdletBase()),
//                dataObject2,
//                @"C:\1\export_file.xml");
//
//            Console.Write("Press any key to continue . . . ");
//            Console.ReadKey(true);
        }
Пример #5
0
        protected override void BeginProcessing()
        {
            CheckCmdletParameters();

            var dataObject = new ImportExportCmdletBaseDataObject {
                As                                    = As,
                Descending                            = Descending,
                ExcludeAutomatic                      = ExcludeAutomatic,
                FilterAll                             = FilterAll,
                FilterDescriptionContains             = FilterDescriptionContains,
                FilterFailed                          = FilterFailed,
                FilterIdContains                      = FilterIdContains,
                FilterNameContains                    = FilterNameContains,
                FilterNone                            = FilterNone,
                FilterNotTested                       = FilterNotTested,
                FilterOutAutomaticAndTechnicalResults = FilterOutAutomaticAndTechnicalResults,
                FilterOutAutomaticResults             = FilterOutAutomaticResults,
                FilterPassed                          = FilterPassed,
                FilterPassedWithBadSmell              = FilterPassedWithBadSmell,
                Id                                    = Id,
                Name                                  = Name,
                OrderByDateTime                       = OrderByDateTime,
                OrderByFailRate                       = OrderByFailRate,
                OrderById                             = OrderById,
                OrderByName                           = OrderByName,
                OrderByPassRate                       = OrderByPassRate,
                OrderByTimeSpent                      = OrderByTimeSpent,
                Path                                  = Path
            };

            string reportFormat = As.ToUpper();

            switch (reportFormat)
            {
            case "XML":
                // 20141114
                // TmxHelper.ExportResultsToXML(dataObject, Path);
                var testResultsExporter = new TestResultsExporter();
                testResultsExporter.ExportResultsToXml(dataObject, Path, TestData.TestSuites, TestData.TestPlatforms);
                break;

            case "JUNIT":
            case "JUNITXML":
                TmxHelper.ExportResultsToJUnitXML(dataObject, Path);
                break;

            case "HTML":
                ExportResultsToHTML(this, Path);
                break;

            case "CSV":
                ExportResultsToCSV(Path);
                break;

            case "TEXT":
                ExportResultsToTEXT(Path);
                break;

            case "ZIP":
                ExportResultsToZIP(Path);
                break;

            default:

                break;
            }
        }