Skip to content

Commit

Permalink
removed TestFileSystem and usage
Browse files Browse the repository at this point in the history
  • Loading branch information
arturcic committed Dec 9, 2024
1 parent e4c3745 commit 2305b7c
Show file tree
Hide file tree
Showing 14 changed files with 39 additions and 156 deletions.
2 changes: 0 additions & 2 deletions src/GitVersion.App.Tests/GitVersion.App.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
<Compile Include="..\GitVersion.Core.Tests\Helpers\ExecutableHelper.cs" Link="Helpers\ExecutableHelper.cs" />
<Compile Include="..\GitVersion.Core.Tests\Helpers\TestConsoleAdapter.cs" Link="Helpers\TestConsoleAdapter.cs" />
<Compile Include="..\GitVersion.Core.Tests\Helpers\TestEnvironment.cs" Link="Helpers\TestEnvironment.cs" />
<Compile Include="..\GitVersion.Core.Tests\Helpers\TestFileSystem.cs" Link="Helpers\TestFileSystem.cs" />
<Compile Include="..\GitVersion.Core.Tests\Helpers\TestLogAppender.cs" Link="Helpers\TestLogAppender.cs" />
<Compile Include="..\GitVersion.Core.Tests\Helpers\TestStream.cs" Link="Helpers\TestStream.cs" />
<Compile Include="..\GitVersion.Core.Tests\Helpers\TestBase.cs" Link="Helpers\TestBase.cs" />
<Compile Include="..\GitVersion.Core.Tests\Helpers\GitVersionCoreTestModule.cs" Link="Helpers\GitVersionCoreTestModule.cs" />
<Compile Include="..\GitVersion.Core.Tests\Extensions\GitVersionVariablesExtensions.cs" Link="Extensions\GitVersionVariablesExtensions.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,8 @@ public void NoWarnOnGitVersionYmlFile()

this.configurationProvider.ProvideForDirectory(this.repoPath);

stringLogger.Length.ShouldBe(0);
var filePath = PathHelper.Combine(this.repoPath, ConfigurationFileLocator.DefaultFileName);
stringLogger.ShouldContain($"Found configuration file at '{filePath}'");
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ public static IDisposable<string> SetupConfigFile(this IFileSystem fileSystem, s
}

var fullPath = PathHelper.Combine(path, fileName);
var directory = PathHelper.GetDirectoryName(fullPath);
if (!fileSystem.DirectoryExists(directory))
{
fileSystem.CreateDirectory(directory);
}

fileSystem.WriteAllText(fullPath, text);

return Disposable.Create(fullPath, () => fileSystem.Delete(fullPath));
Expand Down
6 changes: 3 additions & 3 deletions src/GitVersion.Core.Tests/Core/DynamicRepositoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ private static void ClearReadOnly(DirectoryInfo parentDirectory)
}
}

[OneTimeSetUp]
[SetUp]
public void CreateTemporaryRepository()
{
// Note: we can't use guid because paths will be too long
Expand All @@ -41,15 +41,15 @@ public void CreateTemporaryRepository()
Directory.CreateDirectory(this.workDirectory);
}

[OneTimeTearDown]
[TearDown]
public void Cleanup()
{
}

// Note: use same name twice to see if changing commits works on same (cached) repository
[NonParallelizable]
[TestCase("GV_main", "https://github.com/GitTools/GitVersion", MainBranch, "efddf2f92c539a9c27f1904d952dcab8fb955f0e", "5.8.2-56")]
[TestCase("GV_main", "https://github.com/GitTools/GitVersion", MainBranch, "2dc142a4a4df77db61a00d9fb7510b18b3c2c85a", "5.8.2-47")]
[TestCase("GV_main", "https://github.com/GitTools/GitVersion", MainBranch, "efddf2f92c539a9c27f1904d952dcab8fb955f0e", "5.8.2-56")]
public void FindsVersionInDynamicRepo(string name, string url, string targetBranch, string commitId, string expectedFullSemVer)
{
var root = PathHelper.Combine(this.workDirectory, name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void RegisterTypes(IServiceCollection services)
services.AddModule(new GitVersionConfigurationModule());
services.AddModule(new GitVersionCoreModule());

services.AddSingleton<IFileSystem, TestFileSystem>();
services.AddSingleton<IFileSystem, FileSystem>();
services.AddSingleton<IEnvironment, TestEnvironment>();
services.AddSingleton<ILog, NullLog>();
}
Expand Down
96 changes: 0 additions & 96 deletions src/GitVersion.Core.Tests/Helpers/TestFileSystem.cs

This file was deleted.

38 changes: 0 additions & 38 deletions src/GitVersion.Core.Tests/Helpers/TestStream.cs

This file was deleted.

7 changes: 7 additions & 0 deletions src/GitVersion.Core/Helpers/PathHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ public static string GetTempPath()

public static string GetRepositoryTempPath() => Combine(GetTempPath(), "TestRepositories", Guid.NewGuid().ToString());

public static string GetDirectoryName(string? path)
{
ArgumentNullException.ThrowIfNull(path, nameof(path));

return Path.GetDirectoryName(path)!;
}

public static string GetFullPath(string? path)
{
ArgumentNullException.ThrowIfNull(path, nameof(path));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ private List<string> CalculateDirectoryContents(string root)
{
var fi = new FileInfo(file);
result.Add(fi.Name);
result.Add(File.ReadAllText(file));
result.Add(this.fileSystem.ReadAllText(file));
}
catch (IOException e)
{
Expand Down
2 changes: 0 additions & 2 deletions src/GitVersion.MsBuild.Tests/GitVersion.MsBuild.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@
<Compile Include="..\GitVersion.Core.Tests\Helpers\ExecutableHelper.cs" Link="Helpers\ExecutableHelper.cs" />
<Compile Include="..\GitVersion.Core.Tests\Helpers\TestBase.cs" Link="Helpers\TestBase.cs" />
<Compile Include="..\GitVersion.Core.Tests\Helpers\TestEnvironment.cs" Link="Helpers\TestEnvironment.cs" />
<Compile Include="..\GitVersion.Core.Tests\Helpers\TestFileSystem.cs" Link="Helpers\TestFileSystem.cs" />
<Compile Include="..\GitVersion.Core.Tests\Helpers\TestLogAppender.cs" Link="Helpers\TestLogAppender.cs" />
<Compile Include="..\GitVersion.Core.Tests\Helpers\TestStream.cs" Link="Helpers\TestStream.cs" />
<Compile Include="..\GitVersion.Core.Tests\Extensions\GitToolsTestingExtensions.cs" Link="Extensions\GitToolsTestingExtensions.cs" />
<Compile Include="..\GitVersion.Core.Tests\Extensions\GitVersionVariablesExtensions.cs" Link="Extensions\GitVersionVariablesExtensions.cs" />
<Compile Include="..\GitVersion.Core.Tests\Extensions\MockCollectionExtensions.cs" Link="Extensions\MockCollectionExtensions.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class AssemblyInfoFileUpdaterTests : TestBase
private string workingDir;

[OneTimeSetUp]
public void OneTimeSetUp() => workingDir = PathHelper.Combine(PathHelper.GetTempPath(), "AssemblyInfoFileUpdaterTests");
public void OneTimeSetUp() => workingDir = PathHelper.Combine(PathHelper.GetTempPath(), nameof(AssemblyInfoFileUpdaterTests));

[OneTimeTearDown]
public void OneTimeTearDown() => DirectoryHelper.DeleteDirectory(workingDir);
Expand Down Expand Up @@ -93,7 +93,7 @@ public void ShouldCreateAssemblyInfoFilesAtPathWhenNotExistsAndEnsureAssemblyInf
[TestCase("vb")]
public void ShouldNotCreateAssemblyInfoFileWhenNotExistsAndNotEnsureAssemblyInfo(string fileExtension)
{
var assemblyInfoFile = "VersionAssemblyInfo." + fileExtension;
var assemblyInfoFile = "NoVersionAssemblyInfo." + fileExtension;
var fullPath = PathHelper.Combine(workingDir, assemblyInfoFile);
var variables = this.variableProvider.GetVariablesFor(
SemanticVersion.Parse("1.0.0", RegexPatterns.Configuration.DefaultTagPrefixPattern), EmptyConfigurationBuilder.New.Build(), 0
Expand Down
4 changes: 4 additions & 0 deletions src/GitVersion.Output.Tests/Output/WixFileTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ public void UpdateWixVersionFileWhenFileAlreadyExists()

// fake an already existing file
var file = PathHelper.Combine(workingDir, WixVersionFileUpdater.WixVersionFileName);
if (!fileSystem.DirectoryExists(workingDir))
{
fileSystem.CreateDirectory(workingDir);
}
fileSystem.WriteAllText(file, new('x', 1024 * 1024));

wixVersionFileUpdater.Execute(versionVariables, new(workingDir));
Expand Down
10 changes: 9 additions & 1 deletion src/GitVersion.Output/WixUpdater/WixVersionFileUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,15 @@ public void Execute(GitVersionVariables variables, WixVersionContext context)
var root = doc.DocumentElement;
doc.InsertBefore(xmlDecl, root);

this.fileSystem.Delete(this.wixVersionFile);
if (this.fileSystem.Exists(this.wixVersionFile))
{
this.fileSystem.Delete(this.wixVersionFile);
}

if (!this.fileSystem.DirectoryExists(context.WorkingDirectory))
{
this.fileSystem.CreateDirectory(context.WorkingDirectory);
}
using var fs = this.fileSystem.OpenWrite(this.wixVersionFile);
doc.Save(fs);
}
Expand Down
13 changes: 4 additions & 9 deletions src/GitVersion.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -707,16 +707,11 @@ II.2.12 &lt;HandlesEvent /&gt;&#xD;
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002EJavaScript_002ECodeStyle_002ESettingsUpgrade_002EJsParsFormattingSettingsUpgrader/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002EJavaScript_002ECodeStyle_002ESettingsUpgrade_002EJsWrapperSettingsUpgrader/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EUnitTestFramework_002EMigrations_002EEnableDisabledProvidersMigration/@EntryIndexedValue">True</s:Boolean>


<s:Boolean x:Key="/Default/Environment/UnitTesting/SeparateAppDomainPerAssembly/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/UnitTesting/SeparateAppDomainPerAssembly/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/UnitTesting/ShadowCopy/@EntryValue">False</s:Boolean>




<s:String x:Key="/Default/FilterSettingsManager/AttributeFilterXml/@EntryValue">&lt;data /&gt;</s:String>
<s:String x:Key="/Default/FilterSettingsManager/AttributeFilterXml/@EntryValue">&lt;data /&gt;</s:String>
<s:String x:Key="/Default/FilterSettingsManager/CoverageFilterXml/@EntryValue">&lt;data&gt;&lt;IncludeFilters /&gt;&lt;ExcludeFilters /&gt;&lt;/data&gt;</s:String>
<s:Boolean x:Key="/Default/UserDictionary/Words/=asbjornu/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=gitversion/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Reacheable/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Reacheable/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=veyor/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

0 comments on commit 2305b7c

Please sign in to comment.