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

Update libraries and documentation #214

Merged
merged 7 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
42 changes: 42 additions & 0 deletions docs/TinyHelpers.Dapper/StringArrayTypeHandler.md
Original file line number Diff line number Diff line change
@@ -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.
37 changes: 37 additions & 0 deletions docs/TinyHelpers.Dapper/TimeOnlyTypeHandler.md
Original file line number Diff line number Diff line change
@@ -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<string> `):
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.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.10" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.8.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.9.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Identity" Version="1.12.1" />
<PackageReference Include="Azure.Identity" Version="1.13.0" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.2.2" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/TinyHelpers.AspNetCore/TinyHelpers.AspNetCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.8.1" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.9.0" />
</ItemGroup>

<ItemGroup>
Expand Down
23 changes: 23 additions & 0 deletions tests/TinyHelpers.Tests/Extensions/CollectionExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace TinyHelpers.Tests.Extensions;

public class CollectionExtensionsTests
{

[Fact]
public void Chunk_ExactMultipleChunkSize_ReturnsEqualChunks()
{
Expand Down Expand Up @@ -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<int> { 1, 2, 3, 4, 5 };
var modifiedList = new List<int>(); // 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<int>();

Assert.True(collection.IsEmpty());
}
}
Loading