Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,10 @@
catch (IOException ex)
{
Console.WriteLine("An error occurred while reading the file: " + ex.Message);
}
}

Console.WriteLine($"Current directory: {Directory.GetCurrentDirectory()}");
Console.WriteLine($"Base directory: {AppContext.BaseDirectory}");

var content = ReadFileMethods.ReadFileUsingBaseDirectory(fileName);
Console.WriteLine($"Read {content.Length} characters through the base directory");
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net11.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static string ReadFileUsingCurrentDirectory(string fileName)

public static string ReadFileUsingBaseDirectory(string fileName)
{
var baseDirectoryPath = AppDomain.CurrentDomain.BaseDirectory;
var baseDirectoryPath = AppContext.BaseDirectory;
var filePath = Path.Combine(baseDirectoryPath, fileName);

return ReadFile(filePath);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net11.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

Expand All @@ -10,13 +10,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.12.0" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="4.0.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.0">
<PackageReference Include="coverlet.collector" Version="10.1.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ public class TestReadFileMethods
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";

[Fact]
public void When_ValidFileNameIsProvidedInAppDomainBaseDirectory_Then_FileContentIsReturned()
public void When_ValidFileNameIsProvidedInAppContextBaseDirectory_Then_FileContentIsReturned()
{
// Arrange
var fileName = Path.GetRandomFileName();
var baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
var baseDirectory = AppContext.BaseDirectory;
var filePath = Path.Combine(baseDirectory, fileName);
using var tempFile = TempFile.CreateTempFile(filePath, ExpectedContent);

Expand Down
Loading