Пример #1
0
        public void CreateAndBuildTemplate(TemplateInfo info)
        {
            if (!info.ValidateSuccessfulBuild)
            {
                return;
            }

            Configuration.IgnoreIfIgnoredPlatform(info.Platform);
            var tmpDir = Cache.CreateTemporaryDirectory();

            Configuration.CopyDotNetSupportingFiles(tmpDir);
            var outputDir = Path.Combine(tmpDir, info.Template);

            DotNet.AssertNew(outputDir, info.Template);
            var csproj   = Path.Combine(outputDir, info.Template + ".csproj");
            var rv       = DotNet.AssertBuild(csproj);
            var warnings = BinLog.GetBuildLogWarnings(rv.BinLogPath).Select(v => v.Message);

            Assert.That(warnings, Is.Empty, $"Build warnings:\n\t{string.Join ("\n\t", warnings)}");

            if (info.Execute)
            {
                var platform           = info.Platform;
                var runtimeIdentifiers = GetDefaultRuntimeIdentifier(platform);

                Assert.IsTrue(CanExecute(info.Platform, runtimeIdentifiers), "Must be executable to execute!");

                // First add some code to exit the template if it launches successfully.
                var mainFile              = Path.Combine(outputDir, "Main.cs");
                var mainContents          = File.ReadAllText(mainFile);
                var exitSampleWithSuccess = @"NSTimer.CreateScheduledTimer (1, (v) => {
	Console.WriteLine (Environment.GetEnvironmentVariable (""MAGIC_WORD""));
	Environment.Exit (0);
			});
			"            ;
                var modifiedMainContents  = mainContents.Replace("// This is the main entry point of the application.", exitSampleWithSuccess);
                Assert.AreNotEqual(modifiedMainContents, mainContents, "Failed to modify the main content");
                File.WriteAllText(mainFile, modifiedMainContents);

                // Build the sample
                rv = DotNet.AssertBuild(csproj);

                // There should still not be any warnings
                warnings = BinLog.GetBuildLogWarnings(rv.BinLogPath).Select(v => v.Message);
                Assert.That(warnings, Is.Empty, $"Build warnings (2):\n\t{string.Join ("\n\t", warnings)}");

                var appPath       = GetAppPath(csproj, platform, runtimeIdentifiers);
                var appExecutable = GetNativeExecutable(platform, appPath);
                ExecuteWithMagicWordAndAssert(appExecutable);
            }
        }
Пример #2
0
        public void CreateAndBuildTemplate(string platform, string template)
        {
            Configuration.IgnoreIfIgnoredPlatform(platform);
            var tmpDir = Cache.CreateTemporaryDirectory();

            Configuration.CopyDotNetSupportingFiles(tmpDir);
            var outputDir = Path.Combine(tmpDir, template);

            DotNet.AssertNew(outputDir, template);
            var csproj   = Path.Combine(outputDir, template + ".csproj");
            var rv       = DotNet.AssertBuild(csproj);
            var warnings = BinLog.GetBuildLogWarnings(rv.BinLogPath).Select(v => v.Message);

            Assert.That(warnings, Is.Empty, $"Build warnings:\n\t{string.Join ("\n\t", warnings)}");
        }