internal static bool RunAssetStoreValidationSuite(string packageName, string packageVersion, string packagePath, string previousPackagePath = null)
        {
            if (string.IsNullOrEmpty(packageName))
            {
                throw new ArgumentNullException(packageName);
            }

            if (string.IsNullOrEmpty(packageVersion))
            {
                throw new ArgumentNullException(packageVersion);
            }

            if (string.IsNullOrEmpty(packagePath))
            {
                throw new ArgumentNullException(packageName);
            }

            var report = new ValidationSuiteReport(packageName + "@" + packageVersion, packageName, packageVersion, packagePath);

            try
            {
                var context   = VettingContext.CreateAssetStoreContext(packageName, packageVersion, packagePath, previousPackagePath);
                var testSuite = new ValidationSuite(SingleTestCompletedDelegate, AllTestsCompletedDelegate, context, report);
                testSuite.RunSync();
                return(testSuite.testSuiteState == TestState.Succeeded);
            }
            catch (Exception e)
            {
                report.OutputErrorReport(string.Format("\r\nTest Setup Error: \"{0}\"\r\n", e));
                return(false);
            }
        }
コード例 #2
0
 public void GenerateReport(ValidationSuite suite)
 {
     SaveTestResult(suite, TestState.Failed);
     SaveTestResult(suite, TestState.Succeeded);
     SaveTestResult(suite, TestState.NotRun);
     SaveTestResult(suite, TestState.NotImplementedYet);
     PrintExceptions(suite.context); // make sure to print this at the end, when all exceptions were verified
 }
        public void GenerateJsonReport(ValidationSuite suite)
        {
            var testLists = BuildReport(suite);
            var span      = suite.EndTime - suite.StartTime;

            ReportData = new ValidationSuiteReportData
            {
                Type       = suite.context.ValidationType,
                TestResult = suite.testSuiteState,
                StartTime  = suite.StartTime.ToString(),
                EndTime    = suite.EndTime.ToString(),
                Elapsed    = span.TotalMilliseconds > 1 ? (int)(span.TotalMilliseconds) : 1,
                Tests      = testLists.ToList()
            };

            File.WriteAllText(jsonReportPath, JsonUtility.ToJson(ReportData));
        }
コード例 #4
0
        void SaveTestResult(ValidationSuite suite, TestState testState)
        {
            if (suite.ValidationTests == null)
            {
                return;
            }

            foreach (var testResult in suite.ValidationTests.Where(t => t.TestState == testState))
            {
                Append(string.Format("\n{0} - \"{1}\"\n    ", testResult.TestState, testResult.TestName));
                foreach (var testOutput in testResult.TestOutput)
                {
                    Append(testOutput.ToString());
                    Append("\n\n    ");

                    // If test caused a failure show how to except it
                    if (m_PackageVersion != null && testState == TestState.Failed &&
                        testResult.CanUseValidationExceptions && testOutput.Type == TestOutputType.Error)
                    {
                        var validationExceptions = new ValidationExceptions
                        {
                            ErrorExceptions = new[]
                            {
                                new ValidationException
                                {
                                    ValidationTest   = testResult.ValidationTest.TestName,
                                    ExceptionMessage = testOutput.Output,
                                    PackageVersion   = m_PackageVersion,
                                },
                            },
                        };

                        Append("The above error can be excepted with the following ValidationExceptions.json contents:\n");
                        Append(JsonUtility.ToJson(validationExceptions, true));
                        Append("\n\n    ");
                    }
                }
            }
        }
        private ValidationTestReport[] BuildReport(ValidationSuite suite)
        {
            var testReports = new ValidationTestReport[suite.ValidationTests.Count()];
            var i           = 0;

            foreach (var validationTest in suite.ValidationTests)
            {
                testReports[i]                 = new ValidationTestReport();
                testReports[i].TestName        = validationTest.TestName;
                testReports[i].TestDescription = validationTest.TestDescription;
                testReports[i].TestResult      = validationTest.TestState.ToString();
                testReports[i].TestState       = validationTest.TestState;
                testReports[i].TestOutput      = validationTest.TestOutput.ToArray();
                testReports[i].StartTime       = validationTest.StartTime.ToString();
                testReports[i].EndTime         = validationTest.EndTime.ToString();
                var span = validationTest.EndTime - validationTest.StartTime;
                testReports[i].Elapsed = span.TotalMilliseconds > 1 ? (int)(span.TotalMilliseconds) : 1;
                i++;
            }

            return(testReports);
        }
        public static bool ValidatePackage(VettingContext context, out ValidationSuiteReport report)
        {
            Profiler.BeginSample("ValidatePackage");

            report = new ValidationSuiteReport(context.ProjectPackageInfo.Id, context.ProjectPackageInfo.name, context.ProjectPackageInfo.version, context.ProjectPackageInfo.path);

            try
            {
                // publish locally for embedded and local packages
                var testSuite = new ValidationSuite(SingleTestCompletedDelegate, AllTestsCompletedDelegate, context, report);

                report.Initialize(testSuite.context);
                testSuite.RunSync();
                Profiler.EndSample();
                return(testSuite.testSuiteState == TestState.Succeeded);
            }
            catch (Exception e)
            {
                report.OutputErrorReport(string.Format("Test Setup Error: \"{0}\"\r\n", e));
                Profiler.EndSample();
                return(false);
            }
        }
 public void GenerateTextReport(ValidationSuite suite)
 {
     TextReport?.GenerateReport(suite);
 }
 public void GenerateVettingReport(ValidationSuite suite)
 {
     VettingReport?.GenerateReport(suite);
 }
 static void AllTestsCompletedDelegate(ValidationSuite suite, TestState testRunState)
 {
     suite.report.GenerateTextReport(suite);
     suite.report.GenerateJsonReport(suite);
     suite.report.GenerateVettingReport(suite);
 }
コード例 #10
0
 public void GenerateReport(ValidationSuite suite)
 {
 }