diff --git a/docs/TinyHelpers.Dapper/StringArrayTypeHandler.md b/docs/TinyHelpers.Dapper/StringArrayTypeHandler.md new file mode 100644 index 0000000..3176f74 --- /dev/null +++ b/docs/TinyHelpers.Dapper/StringArrayTypeHandler.md @@ -0,0 +1,42 @@ +# StringArrayTypeHandler Class + +A custom Dapper type handler for mapping arrays of strings to and from the database. + +### Usage + +This handler allows the conversion of a delimited string in the database to a string array in the application, and vice versa. A custom separator can be defined to split or join the string elements. + +```csharp +StringArrayTypeHandler.Configure(";"); +``` + + +### `Parse(object value)` + +Converts a database value, expected to be a delimited string, into a `string[]`. + +#### Parameters +- **`value`** (`object`): +The database value to be parsed. It is expected to be a string containing multiple values separated by the specified separator. + +#### Returns +- **`string[]`**: +A array of strings obtained by splitting the input value based on the separator. Empty entries are removed from the result. + +### `SetValue(IDbDataParameter parameter, string[]? value)` + +The `SetValue` method converts an `string[]` array into a single delimited string, suitable for saving to the database, and assigns it to the given database parameter. + +#### Parameters +- **`parameter`** (`IDbDataParameter `): +The database parameter. + +- **`value`** (`string[]? value `): +The string array of values + +#### Returns +- **`void`**: + +### `Configure(string separator = ";")` +Configures Dapper to use the `StringArrayTypeHandler` for handling string array mappings. Allows specifying a custom separator (default is `";"`). +Should be called during application startup to ensure that Dapper is configured to correctly map arrays of strings. diff --git a/docs/TinyHelpers.Dapper/TimeOnlyTypeHandler.md b/docs/TinyHelpers.Dapper/TimeOnlyTypeHandler.md new file mode 100644 index 0000000..cf89dc2 --- /dev/null +++ b/docs/TinyHelpers.Dapper/TimeOnlyTypeHandler.md @@ -0,0 +1,37 @@ +# TimeOnlyTypeHandler Class + +A custom Dapper type handler for the `TimeOnly` struct, used to map database time values to `TimeOnly` in .NET 6.0 or greater. + +### Usage + +This class provides functionality to parse database time values into `TimeOnly` and to convert `TimeOnly` values to a format suitable for database storage. + +### `Parse(object value)` + +- Parses a database value to a `TimeOnly` object. + +#### Parameters +- **`value`** (`object`): + Takes a database value expected to be a time-based type and converts it to a `TimeOnly` representation. + +#### Returns +- **TimeOnly**: + Returns value converted to a `TimeOnly` Structure. + +### `SetValue(IDbDataParameter parameter, TimeOnly value)` + +- Sets the value of the database parameter to a `TimeOnly` converted to a `TimeSpan`.Configures the database parameter's type as `DbType.Time` to indicate that the value represents a time. + +#### Parameters +- **`parameter`** (`IDbDataParameter `): + The database parameter. + +- **`value`** (`IEnumerable `): + The TimeOnly value to be set + +#### Returns +- **`void`**: + +### Configure Method +- Configures Dapper to use the `TimeOnlyTypeHandler` for handling `TimeOnly` values. +- Should be called during application startup to ensure that Dapper is correctly configured to map `TimeOnly` values to and from the database. diff --git a/samples/TinyHelpers.AspNetCore.Sample/TinyHelpers.AspNetCore.Sample.csproj b/samples/TinyHelpers.AspNetCore.Sample/TinyHelpers.AspNetCore.Sample.csproj index f68ffc3..67a5926 100644 --- a/samples/TinyHelpers.AspNetCore.Sample/TinyHelpers.AspNetCore.Sample.csproj +++ b/samples/TinyHelpers.AspNetCore.Sample/TinyHelpers.AspNetCore.Sample.csproj @@ -8,7 +8,7 @@ - + diff --git a/samples/TinyHelpers.Dapper.Sample/TinyHelpers.Dapper.Sample.csproj b/samples/TinyHelpers.Dapper.Sample/TinyHelpers.Dapper.Sample.csproj index 357eeae..0c294fb 100644 --- a/samples/TinyHelpers.Dapper.Sample/TinyHelpers.Dapper.Sample.csproj +++ b/samples/TinyHelpers.Dapper.Sample/TinyHelpers.Dapper.Sample.csproj @@ -6,7 +6,7 @@ - + diff --git a/src/TinyHelpers.AspNetCore/TinyHelpers.AspNetCore.csproj b/src/TinyHelpers.AspNetCore/TinyHelpers.AspNetCore.csproj index 7d57d44..029aa94 100644 --- a/src/TinyHelpers.AspNetCore/TinyHelpers.AspNetCore.csproj +++ b/src/TinyHelpers.AspNetCore/TinyHelpers.AspNetCore.csproj @@ -25,7 +25,7 @@ - + diff --git a/tests/TinyHelpers.Tests/Extensions/CollectionExtensionsTests.cs b/tests/TinyHelpers.Tests/Extensions/CollectionExtensionsTests.cs index d702656..344a887 100644 --- a/tests/TinyHelpers.Tests/Extensions/CollectionExtensionsTests.cs +++ b/tests/TinyHelpers.Tests/Extensions/CollectionExtensionsTests.cs @@ -4,6 +4,7 @@ namespace TinyHelpers.Tests.Extensions; public class CollectionExtensionsTests { + [Fact] public void Chunk_ExactMultipleChunkSize_ReturnsEqualChunks() { @@ -75,4 +76,26 @@ public void Remove_MatchingElements_RemovesCorrectElements() // Assert Assert.Equal(new[] { 1, 3, 5 }, collection); } + + [Fact] + public void PerformAction_ForEach_ReturnDesiredResult() + { + // Arrange + var collection = new List { 1, 2, 3, 4, 5 }; + var modifiedList = new List(); // Local variable for storing result + + // Act + collection.ForEach(x => modifiedList.Add(x * 5)); + + // Assert + Assert.Equal(new[] { 5, 10, 15, 20, 25 }, modifiedList); + } + + [Fact] + public void List_IsEmpty_ReturnTrue() + { + var collection = new List(); + + Assert.True(collection.IsEmpty()); + } }