Skip to content

Commit

Permalink
Merge pull request #79 from ose-net/feat/issue-72
Browse files Browse the repository at this point in the history
feat: Add Load method without parameters to YeSqlLoader type
  • Loading branch information
MrDave1999 authored Jan 2, 2024
2 parents a352969 + 81ca48c commit 39d7433
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
11 changes: 11 additions & 0 deletions src/Loader/YeSqlLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ public partial class YeSqlLoader
/// </summary>
private readonly YeSqlValidationResult _validationResult = new();

/// <summary>
/// Loads the SQL statements from a default directory called <c>yesql</c>.
/// </summary>
/// <remarks>
/// This method starts searching from the current directory
/// where the application is running (e.g., bin/Debug/net8.0).
/// </remarks>
/// <returns>A collection containing the tags with their associated SQL statements.</returns>
public IYeSqlCollection Load()
=> LoadFromDirectories(Path.Combine(AppContext.BaseDirectory, "yesql"));

/// <summary>
/// Loads the SQL statements from the specified files.
/// </summary>
Expand Down
3 changes: 3 additions & 0 deletions tests/Loader/Resources/yesql/products.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- name: GetProducts
-- Gets product records.
SELECT * FROM products;
19 changes: 19 additions & 0 deletions tests/Loader/YeSqlLoaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,25 @@

public class YeSqlLoaderTests
{
[Test]
public void Load_WhenSqlFilesExistInDefaultDirectoryCalledYesql_ShouldReturnsYeSqlCollection()
{
// Arrange
var loader = new YeSqlLoader();
var expectedCollection = new Dictionary<string, string>
{
{
"GetProducts", "SELECT * FROM products;"
}
};

// Act
var sqlStatements = loader.Load();

// Assert
sqlStatements.Should().BeEquivalentTo(expectedCollection);
}

[Test]
public void LoadFromFiles_WhenErrorsAreFound_ShouldThrowAggregateException()
{
Expand Down
13 changes: 9 additions & 4 deletions tests/YeSql.Net.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,35 @@
</ItemGroup>

<ItemGroup>
<!-- SQL files with errors -->
<Content
Include="Loader\Resources\errors\*.sql"
CopyToOutputDirectory="PreserveNewest"
TargetPath="errors\%(Filename)%(Extension)"
/>
<!-- SQL file with errors -->

<Content
Include="Loader\Resources\error\*.sql"
CopyToOutputDirectory="PreserveNewest"
TargetPath="error\%(Filename)%(Extension)"
/>
<!-- SQL files without errors -->

<Content
Include="Loader\Resources\sql\*.sql"
CopyToOutputDirectory="PreserveNewest"
TargetPath="sql\%(Filename)%(Extension)"
/>
<!-- .env sample files -->

<Content
Include="Loader\Resources\env\*.env"
CopyToOutputDirectory="PreserveNewest"
TargetPath="env\%(Filename)%(Extension)"
/>

<Content
Include="Loader\Resources\yesql\*.sql"
CopyToOutputDirectory="PreserveNewest"
TargetPath="yesql\%(Filename)%(Extension)"
/>
</ItemGroup>

</Project>

0 comments on commit 39d7433

Please sign in to comment.