/// <summary>
        /// Resolve for Gradle using a template .gradle file.
        /// </summary>
        /// <param name="gradleTemplate">Gradle template to use.</param>
        /// <param name="expectedAssetsDir">Directory that contains the assets expected from the
        /// resolution step.</param>
        /// <param name="testCase">Object executing this method.</param>
        /// <param name="testCaseComplete">Called with the test result.</param>
        /// <param name="otherExpectedFiles">Set of additional files that are expected in the
        /// project.</param>
        /// <param name="deleteGradleTemplate">Whether to delete the gradle template before
        /// testCaseComplete is called.</param>
        /// <param name="filesToIgnore">Set of files to relative to the generatedAssetsDir.</param>
        private static void ResolveWithGradleTemplate(
            string gradleTemplate,
            string expectedAssetsDir,
            IntegrationTester.TestCase testCase,
            Action <IntegrationTester.TestCaseResult> testCaseComplete,
            IEnumerable <string> otherExpectedFiles = null,
            bool deleteGradleTemplate          = true,
            ICollection <string> filesToIgnore = null)
        {
            var cleanUpFiles = new List <string>();

            if (deleteGradleTemplate)
            {
                cleanUpFiles.Add(GRADLE_TEMPLATE_ENABLED);
            }
            if (otherExpectedFiles != null)
            {
                cleanUpFiles.AddRange(otherExpectedFiles);
            }
            Action cleanUpTestCase = () => {
                GooglePlayServices.SettingsDialog.PatchMainTemplateGradle = false;
                foreach (var filename in cleanUpFiles)
                {
                    if (File.Exists(filename))
                    {
                        File.Delete(filename);
                    }
                }
            };

            try {
                GooglePlayServices.SettingsDialog.PatchMainTemplateGradle = true;
                File.Copy(gradleTemplate, GRADLE_TEMPLATE_ENABLED);
                Resolve("Gradle", false, expectedAssetsDir, null, filesToIgnore, testCase,
                        (IntegrationTester.TestCaseResult testCaseResult) => {
                    if (otherExpectedFiles != null)
                    {
                        foreach (var expectedFile in otherExpectedFiles)
                        {
                            if (!File.Exists(expectedFile))
                            {
                                testCaseResult.ErrorMessages.Add(String.Format("{0} not found",
                                                                               expectedFile));
                            }
                        }
                    }
                    cleanUpTestCase();
                    testCaseComplete(testCaseResult);
                }, synchronous: true);
            } catch (Exception ex) {
                var testCaseResult = new IntegrationTester.TestCaseResult(testCase);
                testCaseResult.ErrorMessages.Add(ex.ToString());
                cleanUpTestCase();
                testCaseComplete(testCaseResult);
            }
        }
 /// <summary>
 /// Make sure the Android platform is selected for testing.
 /// </summary>
 private static void ValidateAndroidTargetSelected(
     IntegrationTester.TestCase testCase,
     Action <IntegrationTester.TestCaseResult> testCaseComplete)
 {
     if (UnityEditor.EditorUserBuildSettings.activeBuildTarget !=
         UnityEditor.BuildTarget.Android)
     {
         IntegrationTester.Runner.LogTestCaseResult(
             new IntegrationTester.TestCaseResult(testCase)
         {
             ErrorMessages = new List <string>()
             {
                 "Target platform must be Android"
             }
         });
         IntegrationTester.Runner.LogSummaryAndExit();
     }
     // Also, set the internal Gradle version to a deterministic version number.  This controls
     // how gradle template snippets are generated by GradleTemplateResolver.
     PlayServicesResolver.GradleVersion = "2.14";
     testCaseComplete(new IntegrationTester.TestCaseResult(testCase));
 }
        /// <summary>
        /// Asynchronously run the Android Resolver and validate the result with
        /// ValidateAndroidResolution.
        /// </summary>
        /// <param name="androidBuildSystem">Android build system to select.</param>
        /// <param name="exportProject">Whether Android project export should be enabled.</param>
        /// <param name="expectedAssetsDir">Directory that contains the assets expected from the
        /// resolution step.</param>
        /// <param name="targetAbis">String of Android ABIs to target or null if the default ABIs
        /// should be selected.</param>
        /// <param name="filesToIgnore">Set of files to relative to the generatedAssetsDir.</param>
        /// <param name="testCase">Object executing this method.</param>
        /// <param name="testCaseComplete">Called with the test result.</param>
        /// <param name="synchronous">Whether the resolution should be executed synchronously.</param>
        private static void Resolve(string androidBuildSystem, bool exportProject,
                                    string expectedAssetsDir, string targetAbis,
                                    ICollection <string> filesToIgnore,
                                    IntegrationTester.TestCase testCase,
                                    Action <IntegrationTester.TestCaseResult> testCaseComplete,
                                    bool synchronous = false)
        {
            // Set the Android target ABIs.
            GooglePlayServices.AndroidAbis.CurrentString = targetAbis;
            // Try setting the build system if this version of Unity supports it.
            if (!GradleBuildSupported && androidBuildSystem == "Gradle")
            {
                testCaseComplete(new IntegrationTester.TestCaseResult(testCase)
                {
                    Skipped       = true,
                    ErrorMessages = new List <string> {
                        "Unity version does not support Gradle builds."
                    }
                });
                return;
            }
            if (!(SetEditorUserBuildSettingsProperty(
                      ANDROID_BUILD_SYSTEM, StringToAndroidBuildSystemValue(androidBuildSystem)) &&
                  GetEditorUserBuildSettingsProperty(
                      ANDROID_BUILD_SYSTEM, androidBuildSystem).ToString() == androidBuildSystem))
            {
                testCaseComplete(new IntegrationTester.TestCaseResult(testCase)
                {
                    ErrorMessages = new List <string> {
                        String.Format("Unable to set AndroidBuildSystem to {0}.",
                                      androidBuildSystem)
                    }
                });
                return;
            }
            // Configure project export setting.
            if (!(SetEditorUserBuildSettingsProperty(EXPORT_ANDROID_PROJECT, exportProject) &&
                  (bool)GetEditorUserBuildSettingsProperty(EXPORT_ANDROID_PROJECT,
                                                           exportProject) == exportProject))
            {
                testCaseComplete(new IntegrationTester.TestCaseResult(testCase)
                {
                    ErrorMessages = new List <string> {
                        String.Format("Unable to set Android export project to {0}.",
                                      exportProject)
                    }
                });
            }

            // Resolve dependencies.
            Action <bool> completeWithResult = (bool complete) => {
                IntegrationTester.Runner.ExecuteTestCase(
                    testCase,
                    () => {
                    testCaseComplete(new IntegrationTester.TestCaseResult(testCase)
                    {
                        ErrorMessages = ValidateAndroidResolution(expectedAssetsDir, complete,
                                                                  filesToIgnore)
                    });
                }, true);
            };

            if (synchronous)
            {
                bool success = PlayServicesResolver.ResolveSync(true);
                completeWithResult(success);
            }
            else
            {
                PlayServicesResolver.Resolve(resolutionCompleteWithResult: completeWithResult);
            }
        }
 /// <summary>
 /// Initialize the class.
 /// </summary>
 public TestCaseResult(TestCase testCase)
 {
     TestCaseName  = testCase.Name;
     ErrorMessages = new List <string>();
     Skipped       = false;
 }