private ProjectGraphWithPredictionsResult <string> BuildGraphAndDeserialize(IMsBuildAssemblyLoader assemblyLoader, string projectEntryPointContent = null)
        {
            string outputFile = Path.Combine(TemporaryDirectory, Guid.NewGuid().ToString());
            string entryPoint = Path.Combine(TemporaryDirectory, Guid.NewGuid().ToString());

            if (projectEntryPointContent != null)
            {
                File.WriteAllText(entryPoint, projectEntryPointContent);
            }

            using (var reporter = new GraphBuilderReporter(Guid.NewGuid().ToString()))
            {
                var arguments = new MSBuildGraphBuilderArguments(
                    TemporaryDirectory,
                    entryPoint,
                    outputFile,
                    globalProperties: null,
                    mSBuildSearchLocations: new string[] { TestDeploymentDir },
                    entryPointTargets: new string[0]);

                MsBuildGraphBuilder.BuildGraphAndSerializeForTesting(assemblyLoader, reporter, arguments);
            }

            // The serialized graph should exist
            Assert.True(File.Exists(outputFile));

            var projectGraphWithPredictionsResult = SimpleDeserializer.Instance.DeserializeGraph(outputFile);

            return(projectGraphWithPredictionsResult);
        }
        private ProjectGraphWithPredictionsResult <string> BuildGraphAndDeserialize(IMsBuildAssemblyLoader assemblyLoader, string projectEntryPointContent = null)
        {
            string outputFile = Path.Combine(TemporaryDirectory, Guid.NewGuid().ToString());
            string entryPoint = Path.Combine(TemporaryDirectory, Guid.NewGuid().ToString());

            if (projectEntryPointContent != null)
            {
                File.WriteAllText(entryPoint, projectEntryPointContent);
            }

            using (var reporter = new GraphBuilderReporter(Guid.NewGuid().ToString()))
            {
                var arguments = GetStandardBuilderArguments(
                    new[] { entryPoint },
                    outputFile,
                    globalProperties: GlobalProperties.Empty,
                    entryPointTargets: new string[0],
                    requestedQualifiers: new GlobalProperties[] { GlobalProperties.Empty },
                    allowProjectsWithoutTargetProtocol: false);

                MsBuildGraphBuilder.BuildGraphAndSerializeForTesting(assemblyLoader, reporter, arguments);
            }

            // The serialized graph should exist
            Assert.True(File.Exists(outputFile));

            var projectGraphWithPredictionsResult = SimpleDeserializer.Instance.DeserializeGraph(outputFile);

            return(projectGraphWithPredictionsResult);
        }
        public void ProblematicPredictorsAreHandled()
        {
            string outputFile = Path.Combine(TemporaryDirectory, Guid.NewGuid().ToString());
            // We don't bother creating content for the entry point project. The predictor is going to fail anyway.
            string entryPoint = Path.Combine(TemporaryDirectory, Guid.NewGuid().ToString());

            using (var reporter = new GraphBuilderReporter(Guid.NewGuid().ToString()))
            {
                var arguments = new MSBuildGraphBuilderArguments(
                    TestOutputDirectory,
                    entryPoint,
                    outputFile,
                    globalProperties: null,
                    mSBuildSearchLocations: new[] { TestDeploymentDir },
                    entryPointTargets: new string[0]);

                MsBuildGraphBuilder.BuildGraphAndSerializeForTesting(
                    MsBuildAssemblyLoader.Instance,
                    reporter,
                    arguments,
                    new IProjectStaticPredictor[] { new ThrowOnPredictionPredictor() });
            }

            var result = SimpleDeserializer.Instance.DeserializeGraph(outputFile);

            // The result should gracefully fail, with some error message.
            Assert.False(result.Succeeded);
            Assert.True(result.Failure.Message != null);
        }
Beispiel #4
0
        public void ProblematicPredictorsAreHandled()
        {
            string outputFile = Path.Combine(TemporaryDirectory, Guid.NewGuid().ToString());
            // We don't bother creating content for the entry point project. The predictor is going to fail anyway.
            string entryPoint = Path.Combine(TemporaryDirectory, Guid.NewGuid().ToString());

            using (var reporter = new GraphBuilderReporter(Guid.NewGuid().ToString()))
            {
                var arguments = GetStandardBuilderArguments(
                    new[] { entryPoint },
                    outputFile,
                    globalProperties: GlobalProperties.Empty,
                    entryPointTargets: new string[0],
                    requestedQualifiers: new GlobalProperties[] { GlobalProperties.Empty },
                    allowProjectsWithoutTargetProtocol: false);

                MsBuildGraphBuilder.BuildGraphAndSerializeForTesting(
                    AssemblyLoader,
                    reporter,
                    arguments,
                    new IProjectPredictor[] { new ThrowOnPredictionPredictor() });
            }

            var result = SimpleDeserializer.Instance.DeserializeGraph(outputFile);

            // The result should gracefully fail, with some error message.
            Assert.False(result.Succeeded);
            Assert.True(result.Failure.Message != null);
        }
Beispiel #5
0
        /// <nodoc/>
        public bool TryLoadMsBuildAssemblies(IEnumerable <string> searchLocations, GraphBuilderReporter reporter, out string failureReason, out IReadOnlyDictionary <string, string> locatedAssemblyPaths, out string locatedMsBuildExePath)
        {
            failureReason         = "This always fails";
            locatedAssemblyPaths  = new Dictionary <string, string>();
            locatedMsBuildExePath = string.Empty;

            return(false);
        }
Beispiel #6
0
 public void GraphConstructionSucceedsEvenWhenNoClientListensToProgress()
 {
     using (var reporter = new GraphBuilderReporter(Guid.NewGuid().ToString()))
     {
         var result = BuildAndReport(reporter, out var failure);
         Assert.True(result, failure);
     }
 }
Beispiel #7
0
        public void ProgressIsReported()
        {
            var pipeName = Guid.NewGuid().ToString();
            var task     = ConnectToServerPipeAndLogProgress(pipeName);

            using (var reporter = new GraphBuilderReporter(pipeName))
            {
                var result = BuildAndReport(reporter, out var failure);
                Assert.True(result, failure);
            }

            var progress = task.GetAwaiter().GetResult();

            Assert.True(!string.IsNullOrEmpty(progress));
        }
Beispiel #8
0
        public void NoClientListeningResultsInAReportedError()
        {
            GraphBuilderReporter reporter = null;

            try
            {
                reporter = new GraphBuilderReporter(Guid.NewGuid().ToString());
                BuildAndReport(reporter, out _);
            }
            finally
            {
                reporter.Dispose();
                Assert.True(reporter.Errors.Count > 0);
            }
        }
Beispiel #9
0
        public void NotFoundAssembliesGetReported()
        {
            using (var reporter = new GraphBuilderReporter(Guid.NewGuid().ToString()))
            {
                var succeed = AssemblyLoader.TryLoadMsBuildAssemblies(
                    // An empty location should result in not finding any of the required assemblies
                    new string[] {},
                    reporter,
                    out string failureReason,
                    out _,
                    out _);

                // We expect a failure
                Assert.False(succeed);
                // And a non-empty failure reason
                Assert.True(!string.IsNullOrEmpty(failureReason));
            }
        }
Beispiel #10
0
        public void CorrectAssembliesAreSuccessfullyLoaded()
        {
            using (var reporter = new GraphBuilderReporter(Guid.NewGuid().ToString()))
            {
                var succeed = AssemblyLoader.TryLoadMsBuildAssemblies(
                    // The test deployment dir should have all assemblies needed by the loader
                    new [] { TestDeploymentDir },
                    reporter,
                    out _,
                    out var locatedAssemblyPaths,
                    out var locatedMsBuildExePath);

                // We expect success
                Assert.True(succeed);

                // All located assemblies (and MSBuild.exe) should be the ones in the deployment directory
                XAssert.All(locatedAssemblyPaths.Values, locatedAssemblyPath => locatedAssemblyPath.StartsWith(TestDeploymentDir));
                Assert.True(locatedMsBuildExePath.StartsWith(TestDeploymentDir));
            }
        }
Beispiel #11
0
        private bool BuildAndReport(GraphBuilderReporter reporter, out string failure)
        {
            string outputFile = Path.Combine(TemporaryDirectory, Guid.NewGuid().ToString());
            var    arguments  = GetStandardBuilderArguments(
                new[] { m_entryPoint },
                outputFile,
                globalProperties: GlobalProperties.Empty,
                entryPointTargets: new string[0],
                requestedQualifiers: new GlobalProperties[] { GlobalProperties.Empty },
                allowProjectsWithoutTargetProtocol: false);

            MsBuildGraphBuilder.BuildGraphAndSerializeForTesting(AssemblyLoader, reporter, arguments);
            var result = SimpleDeserializer.Instance.DeserializeGraph(outputFile);

            failure = string.Empty;
            if (!result.Succeeded)
            {
                failure = result.Failure.Message;
            }

            return(result.Succeeded);
        }
Beispiel #12
0
        private bool BuildAndReport(GraphBuilderReporter reporter, out string failure)
        {
            string outputFile = Path.Combine(TemporaryDirectory, Guid.NewGuid().ToString());
            var    arguments  = new MSBuildGraphBuilderArguments(
                TestOutputDirectory,
                new[] { m_entryPoint },
                outputFile,
                globalProperties: null,
                mSBuildSearchLocations: new[] { TestDeploymentDir },
                entryPointTargets: new string[0]);

            MsBuildGraphBuilder.BuildGraphAndSerializeForTesting(MsBuildAssemblyLoader.Instance, reporter, arguments);
            var result = SimpleDeserializer.Instance.DeserializeGraph(outputFile);

            failure = string.Empty;
            if (!result.Succeeded)
            {
                failure = result.Failure.Message;
            }

            return(result.Succeeded);
        }