Skip to content

Commit

Permalink
Merge pull request #65 from seesharper/pass-null-to-converter-functions
Browse files Browse the repository at this point in the history
Pass null to converter functions
  • Loading branch information
seesharper committed Jun 1, 2023
2 parents 1ddab8f + 72a3eef commit d5dd958
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- name: Install .Net Core
uses: actions/setup-dotnet@v2.0.0
with:
dotnet-version: 6.0.203
dotnet-version: "7.0.200"
- name: Install dotnet-script
run: dotnet tool install dotnet-script --global

Expand Down
8 changes: 7 additions & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
"presentation": {
"reveal": "always"
},
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": "$msCompile"
},
{
Expand All @@ -29,6 +32,9 @@
"reveal": "always",
"clear": true
},
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": "$msCompile"
},
{
Expand Down Expand Up @@ -60,7 +66,7 @@
"type": "process",
"args": [
"script",
"${workspaceFolder}/../build/build.csx",
"${workspaceFolder}/build/build.csx",
"testcoverage"
],
"problemMatcher": "$msCompile",
Expand Down
6 changes: 0 additions & 6 deletions build/omnisharp.json

This file was deleted.

5 changes: 3 additions & 2 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"sdk": {
"version": "6.0.203"
"version": "7.0.100",
"rollForward": "latestFeature"
}
}
}
2 changes: 1 addition & 1 deletion omnisharp.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
},
"script": {
"enableScriptNuGetReferences": true,
"defaultTargetFramework": "net6.0"
"defaultTargetFramework": "net7.0"
}
}
27 changes: 26 additions & 1 deletion src/DbReader.Tests/ArgumentParserMethodBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,23 @@ public void ShouldHandleEnumWithConverterFunction()
[Fact]
public void ShouldHandleNullableEnumWithoutConverterFunctionPassingNull()
{
var args = new { Status = new EnumParameterWithoutConverterFunction?() };
//var args = new { EnumParameterWithoutConverterFunctionStatus = (EnumParameterWithoutConverterFunction?)null };
var args = new Args() { Status = null };
var method = argumentParserMethodBuilder.CreateMethod("@Status", args.GetType(), Array.Empty<IDataParameter>());
var result = method("@Status", args, () => new TestDataParameter());
result.Parameters[0].Value.ShouldBe(DBNull.Value);
}

[Fact]
public void ShouldHandleNullableEnumWithConverterFunctionPassingNull()
{
DbReaderOptions.WhenPassing<EnumParameterWithConverterFunctionPassingNull?>().Use((parameter, value) => parameter.Value = (int)EnumParameterWithConverterFunctionPassingNull.Value3);
var args = new { Status = (EnumParameterWithConverterFunctionPassingNull?)null };
var method = argumentParserMethodBuilder.CreateMethod("@Status", args.GetType(), Array.Empty<IDataParameter>());
var result = method("@Status", args, () => new TestDataParameter());
result.Parameters[0].Value.ShouldBe(3);
}

[Fact]
public void ShouldHandleNullableEnumWithoutConverterFunction()
{
Expand Down Expand Up @@ -118,6 +129,15 @@ public class ThrowingDataParameter : IDataParameter
public DataRowVersion SourceVersion { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public object Value { get => throw new NotImplementedException(); set => throw new ArgumentException(); }
}

public enum EnumParameterWithConverterFunctionPassingNull
{
Value1 = 1,
Value2 = 2,
Value3 = 3
}


public enum EnumParameterWithoutConverterFunction
{
Value1 = 1,
Expand All @@ -131,7 +151,12 @@ public enum EnumParameterWithConverterFunction
Value2 = 2,
Value3 = 3
}
public class Args
{
public EnumParameterWithoutConverterFunction? Status { get; set; }
}
}



}
2 changes: 1 addition & 1 deletion src/DbReader.Tests/DbReader.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<PackageReference Include="ILVerifier" Version="0.0.1" />
</ItemGroup>
<PropertyGroup>
<TargetFrameworks>net6.0</TargetFrameworks>
<TargetFrameworks>net7.0</TargetFrameworks>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>
<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/DbReader.Tests/InstanceReaderVerificationTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if NET6_0
#if NET7_0
namespace DbReader.Tests
{
using System;
Expand Down
2 changes: 1 addition & 1 deletion src/DbReader.Tests/VerifiableMethodSkeletonFactory.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if NET6_0
#if NET7_0
namespace DbReader.Tests
{
using System;
Expand Down
4 changes: 2 additions & 2 deletions src/DbReader/ArgumentProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ static ArgumentProcessor()
ProcessDelegates.TryAdd(typeof(byte), (parameter, value) => AssignParameterValue(parameter, (byte)value));
ProcessDelegates.TryAdd(typeof(short), (parameter, value) => AssignParameterValue(parameter, (short)value));
ProcessDelegates.TryAdd(typeof(ushort), (parameter, value) => AssignParameterValue(parameter, (ushort)value));
ProcessDelegates.TryAdd(typeof(ushort), (parameter, value) => AssignParameterValue(parameter, (ushort)value));
ProcessDelegates.TryAdd(typeof(ushort), (parameter, value) => AssignParameterValue(parameter, (ushort)value));
}


Expand Down Expand Up @@ -75,7 +75,7 @@ public static void RegisterProcessDelegate<TArgument>(Action<IDataParameter, TAr

public static void Process(Type argumentType, IDataParameter dataParameter, object argument)
{
if (argument == null)
if (argument == null && !ProcessDelegates.ContainsKey(argumentType))
{
dataParameter.Value = DBNull.Value;
return;
Expand Down
5 changes: 3 additions & 2 deletions src/DbReader/DbReader.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;netstandard2.0;net462</TargetFrameworks>
<TargetFrameworks>net6.0;netstandard2.0;net462</TargetFrameworks>
<Authors>Bernhard Richter</Authors>
<PackageProjectUrl>https://github.com/seesharper/DbReader</PackageProjectUrl>
<RepositoryType>git</RepositoryType>
Expand All @@ -16,6 +16,7 @@
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup Condition="'$(TargetFramework)'=='netstandard2.0'">
<PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.7.0" />
Expand All @@ -30,7 +31,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
<PackageReference Include="LightInject.Source" Version="6.5.1">
<PackageReference Include="LightInject.Source" Version="6.6.4">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1">
Expand Down

0 comments on commit d5dd958

Please sign in to comment.