diff --git a/.github/workflows/on-push-do-test.yml b/.github/workflows/on-push-do-test.yml
index 9e66be3..881883f 100644
--- a/.github/workflows/on-push-do-test.yml
+++ b/.github/workflows/on-push-do-test.yml
@@ -37,7 +37,6 @@ jobs:
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.x
- include-prerelease: true
- uses: dotnet/nbgv@master
id: nbgv
diff --git a/src/EasyTestFile.Nunit/MethodInfoResolver.cs b/src/EasyTestFile.Nunit/MethodInfoResolver.cs
index 0a59fc7..0a29740 100644
--- a/src/EasyTestFile.Nunit/MethodInfoResolver.cs
+++ b/src/EasyTestFile.Nunit/MethodInfoResolver.cs
@@ -25,7 +25,7 @@ public static bool TryGet([NotNullWhen(true)] out MethodInfo? methodInfo)
return false;
}
- // Type type = test.TypeInfo!.Type;
+ // Type type = test.TypeInfo!.Type
methodInfo = test.Method!.MethodInfo;
return true;
}
diff --git a/src/EasyTestFile/AssemblyMetadataAttributeNotFoundException.cs b/src/EasyTestFile/AssemblyMetadataAttributeNotFoundException.cs
index c05e1a1..7cc262d 100644
--- a/src/EasyTestFile/AssemblyMetadataAttributeNotFoundException.cs
+++ b/src/EasyTestFile/AssemblyMetadataAttributeNotFoundException.cs
@@ -8,7 +8,7 @@ namespace EasyTestFile;
/// Exception thrown when an expected AssemblyMetadataAttribute was not found.
///
[Serializable]
-public class AssemblyMetadataAttributeNotFoundException : Exception
+public sealed class AssemblyMetadataAttributeNotFoundException : Exception
{
internal AssemblyMetadataAttributeNotFoundException(string assemblyName, string key)
{
diff --git a/src/EasyTestFile/EasyTestFileSettings.Extension.cs b/src/EasyTestFile/EasyTestFileSettings.Extension.cs
index 721c764..d426465 100644
--- a/src/EasyTestFile/EasyTestFileSettings.Extension.cs
+++ b/src/EasyTestFile/EasyTestFileSettings.Extension.cs
@@ -27,4 +27,52 @@ internal string ExtensionOrTxt()
{
return ExtensionOrDefault("txt");
}
+
+ ///
+ /// Custom directory for test files.
+ ///
+ public string? Directory { get; internal set; }
+
+ ///
+ /// Use a custom directory for the test file.
+ ///
+ /// Thrown when argument is null.
+ /// Thrown when argument is not a valid directory.
+ public EasyTestFileSettings UseDirectory(string directory)
+ {
+ Guard.BadDirectoryName(directory, nameof(directory));
+ Directory = directory;
+ return this;
+ }
+
+ internal string? MethodName;
+
+ ///
+ /// Use a custom method name for the testfile.
+ /// Where the file format is `{Directory}/{TestClassName}.{TestMethodName}_{Parameters}.testfile.{extension}`.
+ ///
+ /// Not compatible with .
+ public void UseMethodName(string name)
+ {
+ Guard.BadFileName(name, nameof(name));
+ /* ThrowIfFileNameDefined()*/
+
+ MethodName = name;
+ }
+
+ internal string? FileName;
+
+ ///
+ /// Use a file name for the test file.
+ /// Overrides the `{TestClassName}.{TestMethodName}{Suffix}` parts of the file naming.
+ /// Where the file format is `{Directory}/{TestClassName}.{TestMethodName}{Suffix}.testfile.{extension}`.
+ ///
+ /// Not compatible with , or .
+ public void UseFileName(string fileName)
+ {
+ Guard.BadFileName(fileName, nameof(fileName));
+ // ThrowIfMethodOrTypeNameDefined()
+
+ FileName = fileName;
+ }
}
\ No newline at end of file
diff --git a/src/EasyTestFile/EasyTestFileSettings.cs b/src/EasyTestFile/EasyTestFileSettings.cs
index 85a1229..bbacb60 100644
--- a/src/EasyTestFile/EasyTestFileSettings.cs
+++ b/src/EasyTestFile/EasyTestFileSettings.cs
@@ -28,6 +28,9 @@ public EasyTestFileSettings(EasyTestFileSettings? settings)
}
_extension = settings._extension;
+ FileName = settings.FileName;
+ Directory = settings.Directory;
+ MethodName = settings.MethodName;
AutoCreateMissingTestFileDisabled = settings.AutoCreateMissingTestFileDisabled;
TestFileNamingSuffix = settings.TestFileNamingSuffix;
Assembly = settings.Assembly;
@@ -64,7 +67,7 @@ public void DisableAutoCreateMissingTestFile()
///
/// Use as suffix for naming the testfile.
- /// In this case, the testfile will be named `{Directory}/{TestClassName}.{TestMethodName}_{Suffix}.testfile.{extension}`.
+ /// In this case, the testfile will be named `{Directory}/{TestClassName}.{TestMethodName}{Suffix}.testfile.{extension}`.
///
/// The suffix.
public void SetTestFileNameSuffix(int input)
diff --git a/src/EasyTestFile/DerivedPaths/AttributeReader.cs b/src/EasyTestFile/Internals/AttributeReader.cs
similarity index 96%
rename from src/EasyTestFile/DerivedPaths/AttributeReader.cs
rename to src/EasyTestFile/Internals/AttributeReader.cs
index 99cb046..2be738a 100644
--- a/src/EasyTestFile/DerivedPaths/AttributeReader.cs
+++ b/src/EasyTestFile/Internals/AttributeReader.cs
@@ -1,10 +1,9 @@
-namespace EasyTestFile.DerivedPaths;
+namespace EasyTestFile.Internals;
using System;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
-using EasyTestFile.Internals;
internal static class AttributeReader
{
@@ -21,7 +20,7 @@ public static string GetProjectDirectory()
/// Thrown when the `CallingAssembly` doesn't contain an with the ProjectDirectory.
public static string GetProjectDirectory(Assembly assembly)
{
- return GetEscapedPathValue(assembly, PROJECT_DIRECTORY).Replace('/', '\\');
+ return GetEscapedPathValue(assembly, PROJECT_DIRECTORY);
}
public static bool TryGetProjectDirectory([NotNullWhen(true)] out string? projectDirectory)
@@ -96,7 +95,7 @@ private static bool TryGetEscapedPathValue(Assembly assembly, string key, [NotNu
{
if (TryGetValue(assembly, key, out value))
{
- value = value.Replace('/', '\\');
+ value = value.Replace('\\', DirectorySanitizer.DIRECTORY_SEPARATOR_CHAR);
return true;
}
diff --git a/src/EasyTestFile/Internals/FileNameResolver.cs b/src/EasyTestFile/Internals/FileNameResolver.cs
index 48936f0..539c690 100644
--- a/src/EasyTestFile/Internals/FileNameResolver.cs
+++ b/src/EasyTestFile/Internals/FileNameResolver.cs
@@ -1,28 +1,45 @@
namespace EasyTestFile.Internals;
-using System;
+using System.IO;
internal static class FileNameResolver
{
- internal static (string RelativeFilename, string AbsoluteFilename) Find(EasyTestFileSettings settings, TestAssemblyInfo testAssemblyInfo, TestMethodInfo testMethodInfo)
+ internal static string GetFileNamePrefix(EasyTestFileSettings settings, TestAssemblyInfo testAssemblyInfo, TestMethodInfo testMethodInfo)
{
- var physicalFilename = testMethodInfo.SanitizedFullSourceFile;
- if (physicalFilename.EndsWith(".cs"))
+ _ = testAssemblyInfo;
+
+ if (settings.FileName is not null)
{
- physicalFilename = physicalFilename.Substring(0, physicalFilename.Length - 3);
+ return settings.FileName;
}
+ // var typeName = settings.typeName ?? pathInfo.TypeName ?? GetTypeName(type)
+ var typeName = testMethodInfo.FileName;
+ var methodName = settings.MethodName ?? testMethodInfo.Method;
+
var suffix = string.Empty;
if (!string.IsNullOrWhiteSpace(settings.TestFileNamingSuffix))
{
suffix = "." + settings.TestFileNamingSuffix;
}
+
+ return $"{typeName}.{methodName}{suffix}";
+ }
+
+ internal static (string Relative, string Absolute) GetDirectories(EasyTestFileSettings settings, TestAssemblyInfo testAssemblyInfo, TestMethodInfo testMethodInfo)
+ {
+ _ = testAssemblyInfo;
+ var absoluteDir = testMethodInfo.SanitizedDirectory;
+ if (settings.Directory is not null)
+ {
+ absoluteDir = DirectorySanitizer.Sanitize(Path.Combine(DirectorySanitizer.ToOperatingSystemPath(absoluteDir), settings.Directory));
+ }
- physicalFilename = physicalFilename + "." + testMethodInfo.Method + suffix + EasyTestFileConstants.EASY_TEST_FILE_SUFFIX + "." + settings.ExtensionOrTxt();
- physicalFilename = DirectorySanitizer.Sanitize(physicalFilename);
+ absoluteDir = absoluteDir.TrimEnd('\\', '/');
+ absoluteDir += DirectorySanitizer.DIRECTORY_SEPARATOR_CHAR;
- var relativeFilename = StringHelpers.StringReplaceIgnoreCase(physicalFilename, DirectorySanitizer.Sanitize(testAssemblyInfo.ProjectDirectory), string.Empty);
+ var relativeFilename = StringHelpers.StringReplaceIgnoreCase(absoluteDir, DirectorySanitizer.Sanitize(testAssemblyInfo.ProjectDirectory), string.Empty);
- return (relativeFilename, physicalFilename);
+ return (relativeFilename, absoluteDir);
}
}
\ No newline at end of file
diff --git a/src/EasyTestFile/Internals/StreamResolver.cs b/src/EasyTestFile/Internals/StreamResolver.cs
index fbed5cc..8d6e31b 100644
--- a/src/EasyTestFile/Internals/StreamResolver.cs
+++ b/src/EasyTestFile/Internals/StreamResolver.cs
@@ -2,7 +2,6 @@ namespace EasyTestFile.Internals;
using System.IO;
using System.Reflection;
-using EasyTestFile.DerivedPaths;
internal static class StreamResolver
{
diff --git a/src/EasyTestFile/TestAssemblyInfo.cs b/src/EasyTestFile/TestAssemblyInfo.cs
index 3c21f8a..53f158e 100644
--- a/src/EasyTestFile/TestAssemblyInfo.cs
+++ b/src/EasyTestFile/TestAssemblyInfo.cs
@@ -2,7 +2,7 @@ namespace EasyTestFile;
using System;
using System.Reflection;
-using EasyTestFile.DerivedPaths;
+using EasyTestFile.Internals;
internal readonly struct TestAssemblyInfo
{
diff --git a/src/EasyTestFile/TestFile.cs b/src/EasyTestFile/TestFile.cs
index 6aef8df..2e5f9c9 100644
--- a/src/EasyTestFile/TestFile.cs
+++ b/src/EasyTestFile/TestFile.cs
@@ -1,10 +1,8 @@
namespace EasyTestFile;
using System;
-using System.Collections.Generic;
using System.IO;
using System.Reflection;
-using System.Threading.Tasks;
using EasyTestFile.Internals;
///
@@ -14,9 +12,10 @@ public sealed class TestFile
{
private readonly EasyTestFileSettings _settings;
private readonly Assembly _assembly;
- private readonly string _physicalFilename;
- private readonly string _relativeFilename;
-
+ private readonly string _filenamePrefix;
+ private readonly string _relativeDirectory;
+ private readonly string _absoluteDirectory;
+
internal TestFile(
EasyTestFileSettings? settings,
TestAssemblyInfo testAssemblyInfo,
@@ -25,7 +24,8 @@ internal TestFile(
_settings = settings ?? new EasyTestFileSettings();
_assembly = _settings.Assembly ?? testAssemblyInfo.Assembly;
- (_relativeFilename, _physicalFilename) = FileNameResolver.Find(_settings, testAssemblyInfo, testMethodInfo);
+ _filenamePrefix = FileNameResolver.GetFileNamePrefix(_settings, testAssemblyInfo, testMethodInfo);
+ (_relativeDirectory, _absoluteDirectory) = FileNameResolver.GetDirectories(_settings, testAssemblyInfo, testMethodInfo);
}
///
@@ -35,14 +35,18 @@ internal TestFile(
/// Thrown when stream cannot be found.
public Stream AsStream()
{
- Stream? stream = StreamResolver.Resolve(_relativeFilename, _physicalFilename, _assembly);
+ var filename = _filenamePrefix + EasyTestFileConstants.EASY_TEST_FILE_SUFFIX + "." + _settings.ExtensionOrTxt();
+ var relativeFilename = DirectorySanitizer.PathCombine(_relativeDirectory, filename);
+ var physicalFilename = DirectorySanitizer.PathCombine(_absoluteDirectory, filename);
+
+ Stream? stream = StreamResolver.Resolve(relativeFilename, physicalFilename, _assembly);
if (stream != null)
{
return stream;
}
- var operatingSystemFullFilename = DirectorySanitizer.ToOperatingSystemPath(_physicalFilename);
+ var operatingSystemFullFilename = DirectorySanitizer.ToOperatingSystemPath(physicalFilename);
var created = false;
if (!_settings.AutoCreateMissingTestFileDisabled)
@@ -75,5 +79,4 @@ internal EasyTestFileSettings GetSettings()
{
return _settings;
}
-
}
\ No newline at end of file
diff --git a/src/EasyTestFile/TestMethodInfo.cs b/src/EasyTestFile/TestMethodInfo.cs
index 0f08d43..7ad77b8 100644
--- a/src/EasyTestFile/TestMethodInfo.cs
+++ b/src/EasyTestFile/TestMethodInfo.cs
@@ -13,6 +13,7 @@ internal readonly struct TestMethodInfo
internal TestMethodInfo(MethodInfo info, string sourceFile, string method) :
this(sourceFile, method)
{
+ _ = info;
}
/// Thrown when a parameter is null.
@@ -41,19 +42,34 @@ private TestMethodInfo(string sourceFile, string method)
throw new Exception("Could not determine directory.");
}
+ dirName = dirName.TrimEnd(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar;
SanitizedDirectory = DirectorySanitizer.Sanitize(dirName);
SanitizedFullSourceFile = DirectorySanitizer.Sanitize(sourceFile);
-
+
+ if (fi!.Name.Length >= fi!.Extension.Length && fi!.Name.EndsWith(fi!.Extension))
+ {
+ FileName = fi!.Name.Substring(0, fi!.Name.Length - fi!.Extension.Length);
+ }
+ else
+ {
+ FileName = fi!.Name;
+ }
+
Method = method;
}
+ ///
+ /// Filename without extension.
+ ///
+ public string FileName { get; }
+
///
/// Caller full filename with '\' path separators.
///
public string SanitizedFullSourceFile { get; }
///
- ///
+ /// Caller full directory with '\' path separators. Ends with '\'.
///
public string SanitizedDirectory { get; }
diff --git a/tests/EasyTestFile.Tests/EasyTestFile.Tests.csproj b/tests/EasyTestFile.Tests/EasyTestFile.Tests.csproj
index e242648..252317d 100644
--- a/tests/EasyTestFile.Tests/EasyTestFile.Tests.csproj
+++ b/tests/EasyTestFile.Tests/EasyTestFile.Tests.csproj
@@ -20,8 +20,4 @@
runtime; build; native; contentfiles; analyzers
-
-
-
-
diff --git a/tests/EasyTestFile.Tests/EasyTestFileSettingsTest.WhenCreatedFromSettings.verified.txt b/tests/EasyTestFile.Tests/EasyTestFileSettingsTest.WhenCreatedFromSettings.verified.txt
index 43d6958..8f5a49a 100644
--- a/tests/EasyTestFile.Tests/EasyTestFileSettingsTest.WhenCreatedFromSettings.verified.txt
+++ b/tests/EasyTestFile.Tests/EasyTestFileSettingsTest.WhenCreatedFromSettings.verified.txt
@@ -2,6 +2,9 @@
Assembly: null,
AutoCreateMissingTestFileDisabled: false,
Context: {},
+ Directory: null,
+ FileName: null,
+ MethodName: null,
TestFileNamingSuffix: null,
_extension: null
}
\ No newline at end of file
diff --git a/tests/EasyTestFile.Tests/EasyTestFileSettingsTest.WithDisableAutoCreateMissingTestFile.verified.txt b/tests/EasyTestFile.Tests/EasyTestFileSettingsTest.WithDisableAutoCreateMissingTestFile.verified.txt
index f91d008..079387b 100644
--- a/tests/EasyTestFile.Tests/EasyTestFileSettingsTest.WithDisableAutoCreateMissingTestFile.verified.txt
+++ b/tests/EasyTestFile.Tests/EasyTestFileSettingsTest.WithDisableAutoCreateMissingTestFile.verified.txt
@@ -2,6 +2,9 @@
Assembly: null,
AutoCreateMissingTestFileDisabled: true,
Context: {},
+ Directory: null,
+ FileName: null,
+ MethodName: null,
TestFileNamingSuffix: null,
_extension: null
}
\ No newline at end of file
diff --git a/tests/EasyTestFile.Tests/EasyTestFileSettingsTest.WithSetTestFileNameSuffix1.verified.txt b/tests/EasyTestFile.Tests/EasyTestFileSettingsTest.WithSetTestFileNameSuffix1.verified.txt
index 433db96..6860c7c 100644
--- a/tests/EasyTestFile.Tests/EasyTestFileSettingsTest.WithSetTestFileNameSuffix1.verified.txt
+++ b/tests/EasyTestFile.Tests/EasyTestFileSettingsTest.WithSetTestFileNameSuffix1.verified.txt
@@ -2,6 +2,9 @@
Assembly: null,
AutoCreateMissingTestFileDisabled: false,
Context: {},
+ Directory: null,
+ FileName: null,
+ MethodName: null,
TestFileNamingSuffix: 1,
_extension: null
}
\ No newline at end of file
diff --git a/tests/EasyTestFile.Tests/EasyTestFileSettingsTest.WithSetTestFileNameSuffixString.verified.txt b/tests/EasyTestFile.Tests/EasyTestFileSettingsTest.WithSetTestFileNameSuffixString.verified.txt
index 1c0602a..fb80c2a 100644
--- a/tests/EasyTestFile.Tests/EasyTestFileSettingsTest.WithSetTestFileNameSuffixString.verified.txt
+++ b/tests/EasyTestFile.Tests/EasyTestFileSettingsTest.WithSetTestFileNameSuffixString.verified.txt
@@ -2,6 +2,9 @@
Assembly: null,
AutoCreateMissingTestFileDisabled: false,
Context: {},
+ Directory: null,
+ FileName: null,
+ MethodName: null,
TestFileNamingSuffix: test123,
_extension: null
}
\ No newline at end of file
diff --git a/tests/EasyTestFile.Tests/EasyTestFileSettingsTest.WithUseExtension.verified.txt b/tests/EasyTestFile.Tests/EasyTestFileSettingsTest.WithUseExtension.verified.txt
index f360750..b89cd31 100644
--- a/tests/EasyTestFile.Tests/EasyTestFileSettingsTest.WithUseExtension.verified.txt
+++ b/tests/EasyTestFile.Tests/EasyTestFileSettingsTest.WithUseExtension.verified.txt
@@ -2,6 +2,9 @@
Assembly: null,
AutoCreateMissingTestFileDisabled: false,
Context: {},
+ Directory: null,
+ FileName: null,
+ MethodName: null,
TestFileNamingSuffix: null,
_extension: json
}
\ No newline at end of file
diff --git a/tests/EasyTestFile.Tests/Internals/AttributeReaderTest.cs b/tests/EasyTestFile.Tests/Internals/AttributeReaderTest.cs
new file mode 100644
index 0000000..eeebe21
--- /dev/null
+++ b/tests/EasyTestFile.Tests/Internals/AttributeReaderTest.cs
@@ -0,0 +1,73 @@
+namespace EasyTestFile.Tests.Internals;
+
+using System.IO;
+using FluentAssertions;
+using global::EasyTestFile.Internals;
+using VerifyXunit;
+using Xunit;
+
+[UsesVerify]
+public class AttributeReaderTest
+{
+ [Fact]
+ public void GetProjectDirectory_ShouldNotBeNullOrEmpty()
+ {
+ // arrange
+
+ // act
+ var result = AttributeReader.GetProjectDirectory();
+
+ // assert
+ result.Should().NotBeNullOrWhiteSpace();
+ result.Should().EndWith($"{DirectorySanitizer.DIRECTORY_SEPARATOR_CHAR}");
+ }
+
+ [Fact]
+ public void TryGetProjectDirectory_ShouldNotBeNullOrEmpty()
+ {
+ // arrange
+
+ // act
+ var result = AttributeReader.TryGetProjectDirectory(out var projectDirectory);
+
+ // assert
+ result.Should().BeTrue();
+ projectDirectory.Should().NotBeNullOrWhiteSpace();
+ projectDirectory.Should().EndWith($"{DirectorySanitizer.DIRECTORY_SEPARATOR_CHAR}");
+ }
+
+ [Fact]
+ public void GetSolutionDirectory_ShouldNotBeNullOrEmpty()
+ {
+ // This test depends on how the project was compiled
+ // dotnet build EasyTestFile.csproj => fails the test
+ // dotnet build EasyTestFile.sln => test will succeed
+
+ // arrange
+
+ // act
+ var result = AttributeReader.GetSolutionDirectory();
+
+ // assert
+ result.Should().NotBeNullOrWhiteSpace();
+ result.Should().EndWith($"{DirectorySanitizer.DIRECTORY_SEPARATOR_CHAR}");
+ }
+
+ [Fact]
+ public void TryGetSolutionDirectory_ShouldNotBeNullOrEmpty()
+ {
+ // This test depends on how the project was compiled
+ // dotnet build EasyTestFile.csproj => fails the test
+ // dotnet build EasyTestFile.sln => test will succeed
+
+ // arrange
+
+ // act
+ var result = AttributeReader.TryGetSolutionDirectory(out var solutionDirectory);
+
+ // assert
+ result.Should().BeTrue();
+ solutionDirectory.Should().NotBeNullOrWhiteSpace();
+ solutionDirectory.Should().EndWith($"{DirectorySanitizer.DIRECTORY_SEPARATOR_CHAR}");
+ }
+}
\ No newline at end of file
diff --git a/tests/EasyTestFile.Tests/Internals/FileNameResolverTest.Find_ShouldReturnCorrectAbsoluteAndRelativeFileNames.verified.txt b/tests/EasyTestFile.Tests/Internals/FileNameResolverTest.Find_ShouldReturnCorrectAbsoluteAndRelativeFileNames.verified.txt
deleted file mode 100644
index 65e4a82..0000000
--- a/tests/EasyTestFile.Tests/Internals/FileNameResolverTest.Find_ShouldReturnCorrectAbsoluteAndRelativeFileNames.verified.txt
+++ /dev/null
@@ -1,4 +0,0 @@
-{
- relativeFilename: Internals/FileNameResolverTest.Find_ShouldReturnCorrectAbsoluteAndRelativeFileNames.testfile.txt,
- absoluteFilename: {ProjectDirectory}Internals/FileNameResolverTest.Find_ShouldReturnCorrectAbsoluteAndRelativeFileNames.testfile.txt
-}
\ No newline at end of file
diff --git a/tests/EasyTestFile.Tests/Internals/FileNameResolverTest.GetDirectories_ShouldReturnCorrectAbsoluteAndRelativeFileNames.verified.txt b/tests/EasyTestFile.Tests/Internals/FileNameResolverTest.GetDirectories_ShouldReturnCorrectAbsoluteAndRelativeFileNames.verified.txt
new file mode 100644
index 0000000..2564012
--- /dev/null
+++ b/tests/EasyTestFile.Tests/Internals/FileNameResolverTest.GetDirectories_ShouldReturnCorrectAbsoluteAndRelativeFileNames.verified.txt
@@ -0,0 +1,4 @@
+{
+ relative: Internals/,
+ absolute: {ProjectDirectory}Internals/
+}
\ No newline at end of file
diff --git a/tests/EasyTestFile.Tests/Internals/FileNameResolverTest.cs b/tests/EasyTestFile.Tests/Internals/FileNameResolverTest.cs
index e3d884b..0418349 100644
--- a/tests/EasyTestFile.Tests/Internals/FileNameResolverTest.cs
+++ b/tests/EasyTestFile.Tests/Internals/FileNameResolverTest.cs
@@ -1,8 +1,6 @@
namespace EasyTestFile.Tests.Internals;
-using System.Diagnostics;
using System.Reflection;
-using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using FluentAssertions;
using VerifyXunit;
@@ -13,7 +11,7 @@ namespace EasyTestFile.Tests.Internals;
public class FileNameResolverTest
{
[Fact]
- public async Task Find_ShouldReturnCorrectAbsoluteAndRelativeFileNames()
+ public void GetFileNamePrefix_ShouldReturnCorrectString()
{
// arrange
var settings = new EasyTestFileSettings();
@@ -21,13 +19,28 @@ public async Task Find_ShouldReturnCorrectAbsoluteAndRelativeFileNames()
TestMethodInfo testMethodInfo = TestMethodInfoFactory.CreateTestMethodInfo(MethodBase.GetCurrentMethod()!);
// act
- (string relativeFilename, string absoluteFilename) = Sut.Find(settings, testAssemblyInfo, testMethodInfo);
+ var result = Sut.GetFileNamePrefix(settings, testAssemblyInfo, testMethodInfo);
+
+ // assert
+ result.Should().Be("FileNameResolverTest.GetFileNamePrefix_ShouldReturnCorrectString");
+ }
+
+ [Fact]
+ public async Task GetDirectories_ShouldReturnCorrectAbsoluteAndRelativeFileNames()
+ {
+ // arrange
+ var settings = new EasyTestFileSettings();
+ var testAssemblyInfo = new TestAssemblyInfo(typeof(FileNameResolverTest).Assembly);
+ TestMethodInfo testMethodInfo = TestMethodInfoFactory.CreateTestMethodInfo(MethodBase.GetCurrentMethod()!);
+
+ // act
+ var (relative, absolute) = Sut.GetDirectories(settings, testAssemblyInfo, testMethodInfo);
// assert
await VerifyXunit.Verifier.Verify(new
{
- relativeFilename,
- absoluteFilename,
+ relative,
+ absolute,
});
}
}
\ No newline at end of file
diff --git a/tests/EasyTestFile.Tests/TestMethodInfoTest.Find_ShouldReturnCorrectAbsoluteAndRelativeFileNames.verified.txt b/tests/EasyTestFile.Tests/TestMethodInfoTest.Find_ShouldReturnCorrectAbsoluteAndRelativeFileNames.verified.txt
index 04db44f..178a2a1 100644
--- a/tests/EasyTestFile.Tests/TestMethodInfoTest.Find_ShouldReturnCorrectAbsoluteAndRelativeFileNames.verified.txt
+++ b/tests/EasyTestFile.Tests/TestMethodInfoTest.Find_ShouldReturnCorrectAbsoluteAndRelativeFileNames.verified.txt
@@ -1,4 +1,5 @@
{
+ FileName: TestMethodInfoTest,
SanitizedFullSourceFile: {ProjectDirectory}TestMethodInfoTest.cs,
SanitizedDirectory: {ProjectDirectory},
Method: Find_ShouldReturnCorrectAbsoluteAndRelativeFileNames
diff --git a/tests/EasyTestFile.Tests/TestMethodInfoTest.cs b/tests/EasyTestFile.Tests/TestMethodInfoTest.cs
index 54e2734..e5b5c7c 100644
--- a/tests/EasyTestFile.Tests/TestMethodInfoTest.cs
+++ b/tests/EasyTestFile.Tests/TestMethodInfoTest.cs
@@ -1,4 +1,4 @@
-namespace EasyTestFile.Tests.Internals;
+namespace EasyTestFile.Tests;
using System;
using System.Diagnostics;
diff --git a/tests/EasyTestFile.Xunit.CopyAlways.Tests/AttributeReaderTest.cs b/tests/EasyTestFile.Xunit.CopyAlways.Tests/AttributeReaderTest.cs
index 303af2b..c413577 100644
--- a/tests/EasyTestFile.Xunit.CopyAlways.Tests/AttributeReaderTest.cs
+++ b/tests/EasyTestFile.Xunit.CopyAlways.Tests/AttributeReaderTest.cs
@@ -2,7 +2,6 @@ namespace EasyTestFileXunit.CopyAlways.Tests;
using FluentAssertions;
using global::EasyTestFile;
-using global::EasyTestFile.DerivedPaths;
using global::EasyTestFile.Internals;
using Xunit;
diff --git a/tests/EasyTestFile.Xunit.CopyPreserveNewest.Tests/AttributeReaderTest.cs b/tests/EasyTestFile.Xunit.CopyPreserveNewest.Tests/AttributeReaderTest.cs
index c84849c..6086334 100644
--- a/tests/EasyTestFile.Xunit.CopyPreserveNewest.Tests/AttributeReaderTest.cs
+++ b/tests/EasyTestFile.Xunit.CopyPreserveNewest.Tests/AttributeReaderTest.cs
@@ -3,7 +3,6 @@ namespace EasyTestFileXunit.CopyPreserveNewest.Tests;
using FluentAssertions;
using Xunit;
using global::EasyTestFile;
-using global::EasyTestFile.DerivedPaths;
using global::EasyTestFile.Internals;
public class AttributeReaderTest
diff --git a/tests/EasyTestFile.Xunit.Embed.Tests/AttributeReaderTest.cs b/tests/EasyTestFile.Xunit.Embed.Tests/AttributeReaderTest.cs
index fa56b2a..175cd1e 100644
--- a/tests/EasyTestFile.Xunit.Embed.Tests/AttributeReaderTest.cs
+++ b/tests/EasyTestFile.Xunit.Embed.Tests/AttributeReaderTest.cs
@@ -3,7 +3,6 @@ namespace EasyTestFileXunit.Embed.Tests;
using FluentAssertions;
using Xunit;
using global::EasyTestFile;
-using global::EasyTestFile.DerivedPaths;
using global::EasyTestFile.Internals;
public class AttributeReaderTest
diff --git a/tests/EasyTestFile.Xunit.ModeNone.Tests/AttributeReaderTest.cs b/tests/EasyTestFile.Xunit.ModeNone.Tests/AttributeReaderTest.cs
index 41f5e3a..d3e6403 100644
--- a/tests/EasyTestFile.Xunit.ModeNone.Tests/AttributeReaderTest.cs
+++ b/tests/EasyTestFile.Xunit.ModeNone.Tests/AttributeReaderTest.cs
@@ -2,7 +2,6 @@ namespace EasyTestFileXunit.ModeNone.Tests;
using FluentAssertions;
using global::EasyTestFile;
-using global::EasyTestFile.DerivedPaths;
using global::EasyTestFile.Internals;
using Xunit;
diff --git a/tests/EasyTestFile.Xunit.Tests/Folder1/Partial/MyDirectory/MyFilename.testfile.txt b/tests/EasyTestFile.Xunit.Tests/Folder1/Partial/MyDirectory/MyFilename.testfile.txt
new file mode 100644
index 0000000..3e51b31
--- /dev/null
+++ b/tests/EasyTestFile.Xunit.Tests/Folder1/Partial/MyDirectory/MyFilename.testfile.txt
@@ -0,0 +1 @@
+CustomDirectory with my filename
\ No newline at end of file
diff --git a/tests/EasyTestFile.Xunit.Tests/Folder1/Partial/MyDirectory/MyPartialTest.MyMethodName.testfile.txt b/tests/EasyTestFile.Xunit.Tests/Folder1/Partial/MyDirectory/MyPartialTest.MyMethodName.testfile.txt
new file mode 100644
index 0000000..695327b
--- /dev/null
+++ b/tests/EasyTestFile.Xunit.Tests/Folder1/Partial/MyDirectory/MyPartialTest.MyMethodName.testfile.txt
@@ -0,0 +1 @@
+CustomDirectory with my method name
\ No newline at end of file
diff --git a/tests/EasyTestFile.Xunit.Tests/Folder1/Partial/MyDirectory/MyPartialTest.UseDirectory.testfile.txt b/tests/EasyTestFile.Xunit.Tests/Folder1/Partial/MyDirectory/MyPartialTest.UseDirectory.testfile.txt
new file mode 100644
index 0000000..d48a2a2
--- /dev/null
+++ b/tests/EasyTestFile.Xunit.Tests/Folder1/Partial/MyDirectory/MyPartialTest.UseDirectory.testfile.txt
@@ -0,0 +1 @@
+CustomDirectory content
\ No newline at end of file
diff --git a/tests/EasyTestFile.Xunit.Tests/Folder1/Partial/MyPartialTest.cs b/tests/EasyTestFile.Xunit.Tests/Folder1/Partial/MyPartialTest.cs
index ceafe42..df79e88 100644
--- a/tests/EasyTestFile.Xunit.Tests/Folder1/Partial/MyPartialTest.cs
+++ b/tests/EasyTestFile.Xunit.Tests/Folder1/Partial/MyPartialTest.cs
@@ -23,4 +23,39 @@ public async Task Test2()
var content = await EasyTestFile.LoadAsText();
content.Should().Be("partial test2");
}
+
+ [Fact]
+ public async Task UseDirectory()
+ {
+ var settings = new EasyTestFileSettings();
+ settings.UseDirectory("MyDirectory");
+
+ var content = await EasyTestFile.LoadAsText(settings);
+
+ content.Should().Be("CustomDirectory content");
+ }
+
+ [Fact]
+ public async Task UseMethodName()
+ {
+ var settings = new EasyTestFileSettings();
+ settings.UseDirectory("MyDirectory");
+ settings.UseMethodName("MyMethodName");
+
+ var content = await EasyTestFile.LoadAsText(settings);
+
+ content.Should().Be("CustomDirectory with my method name");
+ }
+
+ [Fact]
+ public async Task UseFileName()
+ {
+ var settings = new EasyTestFileSettings();
+ settings.UseDirectory("MyDirectory");
+ settings.UseFileName("MyFilename");
+
+ var content = await EasyTestFile.LoadAsText(settings);
+
+ content.Should().Be("CustomDirectory with my filename");
+ }
}
\ No newline at end of file
diff --git a/tests/EasyTestFile.Xunit.Tests/VerifyEmbedded.VerifyEmbeddedFiles.verified.txt b/tests/EasyTestFile.Xunit.Tests/VerifyEmbedded.VerifyEmbeddedFiles.verified.txt
index 022809b..054d2f1 100644
--- a/tests/EasyTestFile.Xunit.Tests/VerifyEmbedded.VerifyEmbeddedFiles.verified.txt
+++ b/tests/EasyTestFile.Xunit.Tests/VerifyEmbedded.VerifyEmbeddedFiles.verified.txt
@@ -7,6 +7,9 @@
{EasyTestFile}/CustomPath/CustomProjectPath.CustomPathTest2.2.testfile.txt,
{EasyTestFile}/Folder1/Folder2/PropertyTest.PropertyFile1.testfile.txt,
{EasyTestFile}/Folder1/Folder2/PropertyTest.PropertyFile2.testfile.json,
+ {EasyTestFile}/Folder1/Partial/MyDirectory/MyFilename.testfile.txt,
+ {EasyTestFile}/Folder1/Partial/MyDirectory/MyPartialTest.MyMethodName.testfile.txt,
+ {EasyTestFile}/Folder1/Partial/MyDirectory/MyPartialTest.UseDirectory.testfile.txt,
{EasyTestFile}/Folder1/Partial/MyPartialTest.Test1.testfile.txt,
{EasyTestFile}/Folder1/Partial/MyPartialTest.Test2.testfile.txt,
{EasyTestFile}/Folder1/Partial/Sub/MyPartialTest.Test2.testfile.txt,
diff --git a/version.json b/version.json
index 4704f3d..c37feba 100644
--- a/version.json
+++ b/version.json
@@ -1,6 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
- "version": "1.2-alpha",
+ "version": "1.1",
"assemblyVersion": {
"precision": "revision"
},