Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(#38) add CurrentWorkingDirectory method to AbsolutePath #68

Merged
merged 3 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
23 changes: 23 additions & 0 deletions TruePath.Tests/AbsolutePathTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,29 @@ namespace TruePath.Tests;

public class AbsolutePathTests
{
[Fact]
public void CurrentWorkingDirectoryShouldReturnCorrectAbsolutePath()
{
// Arrange
var expectedPath = Directory.GetCurrentDirectory();

// Act
var actualPath = new AbsolutePath().CurrentWorkingDirectory;

// Assert
Assert.Equal(expectedPath, actualPath.Value);
}

[Fact]
public void CurrentWorkingDirectoryShouldBeAbsolute()
{
// Act
var path = new AbsolutePath().CurrentWorkingDirectory;

// Assert
Assert.True(Path.IsPathRooted(path.Value));
}

[Fact]
public void PathIsNormalizedOnCreation()
{
Expand Down
8 changes: 8 additions & 0 deletions TruePath/AbsolutePath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ private AbsolutePath(string value, bool checkAbsoluteness)
/// <inheritdoc cref="IPath.FileName"/>
public string FileName => Underlying.FileName;

/// <summary>
/// Gets the current working directory as an AbsolutePath instance.
/// </summary>
/// <value>
/// The current working directory.
/// </value>
public AbsolutePath CurrentWorkingDirectory => new(Environment.CurrentDirectory);
ForNeVeR marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// Calculates the relative path from a base path to this path.
/// </summary>
Expand Down