Skip to content

Commit

Permalink
support Dictionary parameter,fix #58
Browse files Browse the repository at this point in the history
  • Loading branch information
neuecc committed Apr 7, 2021
1 parent c784d76 commit 22a073b
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 4 deletions.
6 changes: 3 additions & 3 deletions sandbox/SingleContainedApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,10 @@ public void Hello(
if (hello == null) hello = DateTime.Now;
Console.WriteLine(hello);
}
public void Dispose()

void IDisposable.Dispose()
{
Console.WriteLine("DISPOSE!");
throw new NotImplementedException();
}

}
}
2 changes: 1 addition & 1 deletion src/ConsoleAppFramework/ConsoleAppEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ bool TryGetInvokeArguments(ParameterInfo[] parameters, string?[] args, int argsO
return false;
}
}
else if (typeof(System.Collections.IEnumerable).IsAssignableFrom(parameters[i].ParameterType))
else if (typeof(System.Collections.IEnumerable).IsAssignableFrom(parameters[i].ParameterType) && !typeof(System.Collections.IDictionary).IsAssignableFrom(parameters[i].ParameterType))
{
var v = value.Value;
if (!(v.StartsWith("[") && v.EndsWith("]")))
Expand Down
46 changes: 46 additions & 0 deletions tests/ConsoleAppFramework.Tests/ParameterCheckTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using FluentAssertions;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;

namespace ConsoleAppFramework.Tests
{
public class ParameterCheckTest
{
ITestOutputHelper testOutput;

public ParameterCheckTest(ITestOutputHelper testOutput)
{
this.testOutput = testOutput;
}

public class DictionaryCheck : ConsoleAppBase
{
public void Hello(Dictionary<string, string> q)
{

foreach (var item in q)
{
Context.Logger.LogInformation($"{item.Key}:{item.Value}");
}
}
}

[Fact]
public async Task DictParse()
{
var args = @"-q {""Key1"":""Value1*""}".Split(' ');

var log = new LogStack();
await new HostBuilder()
.ConfigureTestLogging(testOutput, log, true)
.RunConsoleAppFrameworkAsync<DictionaryCheck>(args);

log.InfoLogShouldBe(0, "Key1:Value1*");
}
}
}

0 comments on commit 22a073b

Please sign in to comment.