Skip to content

Made IsFileCsv into an extension method and added tests#17

Merged
jdubar merged 1 commit intomasterfrom
Fix/System-IO-Path-is-different
Nov 10, 2025
Merged

Made IsFileCsv into an extension method and added tests#17
jdubar merged 1 commit intomasterfrom
Fix/System-IO-Path-is-different

Conversation

@bechtd
Copy link
Copy Markdown
Collaborator

@bechtd bechtd commented Nov 10, 2025

Made IsFileCsv into an extension method and added tests

  • Moved IsFileCsv out of FileService and into String extensions
  • Added unit tests in StringExtensionsTests.cs to validate the method with various file path scenarios.
  • Updated FileService.cs to use the new IsFileCsv extension method.

- Moved `IsFileCsv` out of `FileService` and into String extensions
- Added unit tests in `StringExtensionsTests.cs` to validate the method with various file path scenarios.
- Updated `FileService.cs` to use the new `IsFileCsv` extension method.
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
RoyAppMaui/Extensions/StringExtensions.cs 100.00% <100.00%> (ø)
RoyAppMaui/Services/Impl/FileService.cs 96.77% <100.00%> (+1.53%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Collaborator Author

@bechtd bechtd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

System.IO.Path is NOT System.IO.File

This is a common mistake to make because they look similar. You would think both talk to the file system. Path does not.

: Result.Fail("Selected file is not a CSV file.");
}

private bool IsFileCsv(string filePath) => fileSystem.Path.GetExtension(filePath)?.ToLower(CultureInfo.CurrentCulture) == ".csv";
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I know it feels like System.IO.Path is part of the "file system", especially since you can access it that way. BUT when it comes to using these methods, such as GetExtension, they are independent of the OS, to the best of my knowledge. This is a static method. That signifies that this is most likely a "pure function" with no hard dependencies.

You can inspect the actual library and see for yourself:
image
image

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since System.IO.Path (as best as I can tell) NEVER TALKS to the OS, you do not have to put it inside a Service, to use the "heavy" fileSystem object.

Yes, it is there, but I think they did that for "completeness" of their Abstraction library.
It's static, so you can treat it as a pure function (an isolated algorithm that only works internally inside C#).

Therefore instead of putting this Is CSV checker in a Service, we make it an extension and then Unit Test it.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. String comparison should be done using string.Equals( "string1", "string2", StringComparison.IgnoreCase). Don't use ToLower() or ToUpper(). It is best to use this function for comparing two strings, always, using one of the ignore case flags, if you plan to ignore case.
  2. Now that this is in an extension, we can test it extensively (raising the coverage numbers).

Comment on lines +80 to +81
[InlineData("fileWith.csv.txt", false)]
[InlineData("fileWith.txt.csv", true)]
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try to trick it
it's not fooled

Copy link
Copy Markdown
Owner

@jdubar jdubar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

@jdubar jdubar added refactor cleanup and improve code coverage added or modified coverage tests labels Nov 10, 2025
@jdubar jdubar merged commit e91b633 into master Nov 10, 2025
4 checks passed
@jdubar jdubar deleted the Fix/System-IO-Path-is-different branch November 10, 2025 18:02
@bechtd
Copy link
Copy Markdown
Collaborator Author

bechtd commented Nov 11, 2025

Good catch!

AND a 1.53% Code Coverage increase! I'll TAKE IT! (You climb a mountain, one step at a time)
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

coverage added or modified coverage tests refactor cleanup and improve code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants