<commit_before>﻿using System;
using System.IO;
using GitVersion;
using GitVersionTask.Tests.Mocks;
using Microsoft.Build.Framework;
using NUnit.Framework;

[TestFixture]
public class InvalidFileCheckerTests
{
    string projectDirectory;
    string projectFile;

    [SetUp]
    public void CreateTemporaryProject()
    {
        projectDirectory = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
        projectFile = Path.Combine(projectDirectory, "Fake.csproj");

        Directory.CreateDirectory(projectDirectory);

        File.Create(projectFile).Close();
    }

    [TearDown]
    public void Cleanup()
    {
        Directory.Delete(projectDirectory, true);
    }

    [Test]
    public void VerifyIgnoreNonAssemblyInfoFile()
    {
        using (var writer = File.CreateText(Path.Combine(projectDirectory, "SomeOtherFile.cs")))
        {
            writer.Write(@"
using System;
using System.Reflection;

[assembly: AssemblyVersion(""1.0.0.0"")]
");
        }

        InvalidFileChecker.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "SomeOtherFile.cs" } }, projectFile);<commit_msg>Don't crash if cleanup fails<commit_after>﻿using System;
using System.IO;
using GitVersion;
using GitVersionTask.Tests.Mocks;
using Microsoft.Build.Framework;
using NUnit.Framework;

[TestFixture]
public class InvalidFileCheckerTests
{
    string projectDirectory;
    string projectFile;

    [SetUp]
    public void CreateTemporaryProject()
    {
        projectDirectory = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
        projectFile = Path.Combine(projectDirectory, "Fake.csproj");

        Directory.CreateDirectory(projectDirectory);

        File.Create(projectFile).Close();
    }

    [TearDown]
    public void Cleanup()
    {
        try
        {
            Directory.Delete(projectDirectory, true);
        }
        catch (Exception exception)
        {
            Console.WriteLine(exception);
        }
    }

    [Test]
    public void VerifyIgnoreNonAssemblyInfoFile()
    {
        using (var writer = File.CreateText(Path.Combine(projectDirectory, "SomeOtherFile.cs")))
        {
            writer.Write(@"
using System;
using System.Reflection;

[assembly: AssemblyVersion(""1.0.0.0"")]
");
        }

        InvalidFileChecker.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "SomeOtherFile.cs" } }, projectFile);
{'fraction_non_alphanumeric': 0.11249481112494811, 'fraction_numerical': 0.0033208800332088003, 'mean_word_length': 3.2059336823734728, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4818176', 'n_tokens_mistral': 695, 'n_tokens_neox': 677, 'n_words': 130}