<commit_before>﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml.Linq;
using Microsoft.Build.Evaluation;
using Microsoft.Build.Execution;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using NUnit.Framework;
using PS.Build.Tasks.Extensions;
using PS.Build.Tasks.Tests.Common;

namespace PS.Build.Tasks.Tests.Tasks
{
    [TestFixture]
    class PreBuildAdaptationExecutionTaskTests
    {
        [Test]
        public void Test()
        {
            var targetDirectory = AppDomain.CurrentDomain.BaseDirectory;

            var solutionDirectory = Path.Combine(targetDirectory, @"TestReferences\Projects\GenericProject\");
            var definitionProjectPath = Path.Combine(solutionDirectory, @"DefinitionLibrary\DefinitionLibrary.csproj");
            var usageProjectPath = Path.Combine(solutionDirectory, @"UsageLibrary\UsageLibrary.csproj");
            var usageProjectDirectory = Path.GetDirectoryName(usageProjectPath);
            Assert.IsNotNull(usageProjectDirectory);

            var configuration = "Release";
            var platform = "AnyCPU";

            var xProject = XDocument.Load(usageProjectPath);
            Assert.IsNotNull(xProject);

            var msbuildNS = "http://schemas.microsoft.com/developer/msbuild/2003";
            var outputPath = xProject.Descendants(XName.Get("OutputPath", msbuildNS))
                                     .FirstOrDefault(e => e.Parent?.Attributes().Any(a => a.Value.Contains(configuration)) == true)?.Value;

            Assert.IsNotNull(outputPath);

            var pc = new ProjectCollection();
            pc.SetGlobalProperty("Configuration", configuration);
            pc.SetGlobalProperty("Platform", "Any CPU");
            var target = "Rebuild";
            var result = BuildManager.DefaultBuildManager.Build(new BuildParameters(pc),
                                                                new BuildRequestData(new ProjectInstance(definitionProjectPath),
                                                                                     new[] { target }));
            TargetResult buildResult;
            Assert.IsTrue(result.ResultsByTarget.TryGetValue(target, out buildResult));
            Assert.AreEqual(TargetResultCode.Success, buildResult.ResultCode);<commit_msg>- Unit test logging was improved<commit_after>﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml.Linq;
using Microsoft.Build.Evaluation;
using Microsoft.Build.Execution;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using NUnit.Framework;
using PS.Build.Tasks.Extensions;
using PS.Build.Tasks.Tests.Common;

namespace PS.Build.Tasks.Tests.Tasks
{
    [TestFixture]
    class PreBuildAdaptationExecutionTaskTests
    {
        [Test]
        public void Test()
        {
            var targetDirectory = AppDomain.CurrentDomain.BaseDirectory;

            var solutionDirectory = Path.Combine(targetDirectory, @"TestReferences\Projects\GenericProject\");
            var definitionProjectPath = Path.Combine(solutionDirectory, @"DefinitionLibrary\DefinitionLibrary.csproj");
            var usageProjectPath = Path.Combine(solutionDirectory, @"UsageLibrary\UsageLibrary.csproj");
            var usageProjectDirectory = Path.GetDirectoryName(usageProjectPath);
            Assert.IsNotNull(usageProjectDirectory, $"{nameof(usageProjectDirectory)} is invalid");

            var configuration = "Release";
            var platform = "AnyCPU";

            var xProject = XDocument.Load(usageProjectPath);
            Assert.IsNotNull(xProject, $"{nameof(xProject)} was not loaded from {usageProjectPath}");

            var msbuildNS = "http://schemas.microsoft.com/developer/msbuild/2003";
            var outputPath = xProject.Descendants(XName.Get("OutputPath", msbuildNS))
                                     .FirstOrDefault(e => e.Parent?.Attributes().Any(a => a.Value.Contains(configuration)) == true)?.Value;

            Assert.IsNotNull(outputPath, $"{nameof(outputPath)} was not found in {usageProjectPath} project file");

            var pc = new ProjectCollection();
            pc.SetGlobalProperty("Configuration", configuration);
            pc.SetGlobalProperty("Platform", "Any CPU");
            var target = "Rebuild";
            var result = BuildManager.DefaultBuildManager.Build(new BuildParameters(pc),
                                                                new BuildRequestData(new ProjectInstance(definitionProjectPath),
                                                                                     new[] { target }));
            TargetResult buildResult;
            if (!result.ResultsByTarget.TryGetValue(target, out buildResult))
            {
                var message = $"Project {definitionProjectPath} compilation failed. Details: {result.Exception}";

                Assert.Fail(message);
            }

            Assert.AreEqual(TargetResultCode.Success, buildResult.ResultCode);
{'fraction_non_alphanumeric': 0.0979381443298969, 'fraction_numerical': 0.0015860428231562252, 'mean_word_length': 2.5010409437890355, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2892760', 'n_tokens_mistral': 1216, 'n_tokens_neox': 1168, 'n_words': 235}