From acbd75b2e6c3c58e566865ae8e55058fa3d0ecd5 Mon Sep 17 00:00:00 2001 From: MrDave1999 Date: Tue, 2 Jan 2024 12:40:05 -0500 Subject: [PATCH 1/3] chore: Add resource for testing --- tests/Loader/Resources/yesql/products.sql | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 tests/Loader/Resources/yesql/products.sql diff --git a/tests/Loader/Resources/yesql/products.sql b/tests/Loader/Resources/yesql/products.sql new file mode 100644 index 0000000..79733fb --- /dev/null +++ b/tests/Loader/Resources/yesql/products.sql @@ -0,0 +1,3 @@ +-- name: GetProducts +-- Gets product records. +SELECT * FROM products; \ No newline at end of file From 3a0d15084838c6763b4dd58ba0f58412ccbd0314 Mon Sep 17 00:00:00 2001 From: MrDave1999 Date: Tue, 2 Jan 2024 12:40:27 -0500 Subject: [PATCH 2/3] chore: Copy resource to output directory --- tests/YeSql.Net.Tests.csproj | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tests/YeSql.Net.Tests.csproj b/tests/YeSql.Net.Tests.csproj index 6da2ea6..1d525f0 100644 --- a/tests/YeSql.Net.Tests.csproj +++ b/tests/YeSql.Net.Tests.csproj @@ -22,30 +22,35 @@ - - + - + - + + + From 81ca48c0e20e176590c1b01567f35db6942d142c Mon Sep 17 00:00:00 2001 From: MrDave1999 Date: Tue, 2 Jan 2024 12:43:00 -0500 Subject: [PATCH 3/3] feat: Add Load method without parameters to YeSqlLoader type --- src/Loader/YeSqlLoader.cs | 11 +++++++++++ tests/Loader/YeSqlLoaderTests.cs | 19 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/Loader/YeSqlLoader.cs b/src/Loader/YeSqlLoader.cs index 0a6f823..80b4e35 100644 --- a/src/Loader/YeSqlLoader.cs +++ b/src/Loader/YeSqlLoader.cs @@ -18,6 +18,17 @@ public partial class YeSqlLoader /// private readonly YeSqlValidationResult _validationResult = new(); + /// + /// Loads the SQL statements from a default directory called yesql. + /// + /// + /// This method starts searching from the current directory + /// where the application is running (e.g., bin/Debug/net8.0). + /// + /// A collection containing the tags with their associated SQL statements. + public IYeSqlCollection Load() + => LoadFromDirectories(Path.Combine(AppContext.BaseDirectory, "yesql")); + /// /// Loads the SQL statements from the specified files. /// diff --git a/tests/Loader/YeSqlLoaderTests.cs b/tests/Loader/YeSqlLoaderTests.cs index 34b7b4f..b9b90e2 100644 --- a/tests/Loader/YeSqlLoaderTests.cs +++ b/tests/Loader/YeSqlLoaderTests.cs @@ -2,6 +2,25 @@ public class YeSqlLoaderTests { + [Test] + public void Load_WhenSqlFilesExistInDefaultDirectoryCalledYesql_ShouldReturnsYeSqlCollection() + { + // Arrange + var loader = new YeSqlLoader(); + var expectedCollection = new Dictionary + { + { + "GetProducts", "SELECT * FROM products;" + } + }; + + // Act + var sqlStatements = loader.Load(); + + // Assert + sqlStatements.Should().BeEquivalentTo(expectedCollection); + } + [Test] public void LoadFromFiles_WhenErrorsAreFound_ShouldThrowAggregateException() {