Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
0d9ca29
Add Resolve overload to take in any type
Matthiee Aug 6, 2019
503a91f
Add FluentValidation extension project
Matthiee Aug 7, 2019
5f44e35
Add public abstract validation API
Matthiee Aug 7, 2019
1cc7c66
Fix tests
Matthiee Aug 7, 2019
6573207
Update sample app with fluent validations
Matthiee Aug 7, 2019
a95222c
Add FluentValidations extension project
Matthiee Aug 7, 2019
962e5c3
WIP
Matthiee Aug 14, 2019
fe1f77a
Fix error
Matthiee Aug 16, 2019
82b030c
Add validator implementation
Matthiee Sep 16, 2019
7c9fbb1
Add Fluent Validations Extensions test project
Matthiee Sep 16, 2019
0a87515
Add Validator extension specific tests
Matthiee Sep 16, 2019
3871315
Add correct Fluent Validation behaviour
Matthiee Sep 19, 2019
aed3eb2
Merge branch 'master' into validator-48
Matthiee Sep 19, 2019
c7ff54f
Fix failed merge commit
Matthiee Sep 19, 2019
8377e1a
Add cake support for FVE project.
Matthiee Sep 19, 2019
1744869
Use correct path
Matthiee Sep 19, 2019
66b2c9f
Attempt to use MergeWithFile coverlet setting
Matthiee Sep 22, 2019
a3e90ab
Another attempt
Matthiee Sep 22, 2019
6501c5d
Add some debug info
Matthiee Sep 22, 2019
fc5a668
more debug info
Matthiee Sep 22, 2019
845f67f
...
Matthiee Sep 22, 2019
031054e
another attempt
Matthiee Sep 22, 2019
33d564b
Another attempt
Matthiee Sep 22, 2019
0168d2f
Update nuspec
Matthiee Oct 6, 2019
e3c9f5d
Update build script
Matthiee Oct 6, 2019
e12d4bd
Oops nuspec mistake add correct closing tag
Matthiee Oct 6, 2019
26ed5e5
Add publish of nuget package to GH
Matthiee Oct 6, 2019
823228c
Don't do this yet
Matthiee Oct 6, 2019
3399cab
Add extra tests for fluent validations
Matthiee Nov 5, 2019
a904af1
Add nuspec and update build.
Matthiee Nov 5, 2019
1d56ead
Update relative path
Matthiee Nov 5, 2019
1bd5e6c
Add docs
Matthiee Nov 5, 2019
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
17 changes: 10 additions & 7 deletions CommandLineParser.Tests/Command/SubCommandTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using MatthiWare.CommandLine;
using MatthiWare.CommandLine.Abstractions;
using MatthiWare.CommandLine.Abstractions.Command;
using MatthiWare.CommandLine.Core;
using MatthiWare.CommandLine.Core.Attributes;
using System;
using System.Linq;
Expand Down Expand Up @@ -41,7 +42,7 @@ public void TestSubCommandWorksCorrectlyInModel(bool autoExecute, string bla, in
Assert.All(result.CommandResults.Select(r => r.Executed), Assert.True);
}

private class CustomInstantiator : IContainerResolver
private class CustomInstantiator : DefaultContainerResolver
{
private readonly ManualResetEventSlim lock1;
private readonly ManualResetEventSlim lock2;
Expand All @@ -60,14 +61,16 @@ public CustomInstantiator(ManualResetEventSlim lock1, ManualResetEventSlim lock2
this.n = n;
}

public T Resolve<T>()
public override T Resolve<T>() => (T)Resolve(typeof(T));

public override object Resolve(Type type)
{
if (typeof(T) == typeof(MainCommand))
return (T)Activator.CreateInstance(typeof(T), lock1, autoExecute, bla, i, n);
else if (typeof(T) == typeof(SubCommand))
return (T)Activator.CreateInstance(typeof(T), lock2, autoExecute, bla, i, n);
if (type == typeof(MainCommand))
return Activator.CreateInstance(type, lock1, autoExecute, bla, i, n);
else if (type == typeof(SubCommand))
return Activator.CreateInstance(type, lock2, autoExecute, bla, i, n);
else
throw new InvalidCastException($"Unable to resolve {(typeof(T)).Name}");
return base.Resolve(type);
}
}

Expand Down
13 changes: 7 additions & 6 deletions CommandLineParser.Tests/Parsing/ResolverFactoryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using MatthiWare.CommandLine.Abstractions.Models;
using MatthiWare.CommandLine.Abstractions.Parsing;
using MatthiWare.CommandLine.Core;
using MatthiWare.CommandLine.Core.Parsing;
using MatthiWare.CommandLine.Core.Parsing.Resolvers;

Expand All @@ -25,7 +26,7 @@ public enum Output
[Fact]
public void ContainsWork()
{
var factory = new DefaultArgumentResolverFactory();
var factory = new DefaultArgumentResolverFactory(new DefaultContainerResolver());

Assert.True(factory.Contains<string>());
Assert.True(factory.Contains<int>());
Expand All @@ -39,7 +40,7 @@ public void ContainsWork()
[Fact]
public void CreateEnumResolver()
{
var factory = new DefaultArgumentResolverFactory();
var factory = new DefaultArgumentResolverFactory(new DefaultContainerResolver());

var output = factory.CreateResolver<Output>();
var output2 = factory.CreateResolver(typeof(Output));
Expand All @@ -59,7 +60,7 @@ public void RegisterAndGet()
mockResolver.Setup(_ => _.CanResolve(It.IsAny<ArgumentModel>())).Returns(true);
mockResolver.Setup(_ => _.Resolve(It.IsAny<ArgumentModel>())).Returns(instance);

var factory = new DefaultArgumentResolverFactory();
var factory = new DefaultArgumentResolverFactory(new DefaultContainerResolver());

factory.Register(mockResolver.Object);

Expand All @@ -79,7 +80,7 @@ public void RegisterOverrideWorks()
{
var mockResolver = new Mock<ArgumentResolver<string>>();

var factory = new DefaultArgumentResolverFactory();
var factory = new DefaultArgumentResolverFactory(new DefaultContainerResolver());

factory.Register(typeof(string), mockResolver.Object.GetType(), true);
factory.Register<string, StringResolver>(true);
Expand All @@ -90,7 +91,7 @@ public void RegisterThrowsException()
{
var mockResolver = new Mock<ArgumentResolver<string>>();

var factory = new DefaultArgumentResolverFactory();
var factory = new DefaultArgumentResolverFactory(new DefaultContainerResolver());

Assert.Throws<ArgumentException>(() => factory.Register<string, StringResolver>());
}
Expand All @@ -105,7 +106,7 @@ public void RegisterObjectResolver()
resolver.Setup(_ => _.CanResolve(It.IsAny<ArgumentModel>())).Returns(true);
resolver.Setup(_ => _.Resolve(It.IsAny<ArgumentModel>())).Returns(obj);

var factory = new DefaultArgumentResolverFactory();
var factory = new DefaultArgumentResolverFactory(new DefaultContainerResolver());
var dummyArg = new ArgumentModel();

factory.Register(resolver.Object);
Expand Down
21 changes: 21 additions & 0 deletions CommandLineParser.sln
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
README.md = README.md
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Extensions", "Extensions", "{9AE7A2BC-8475-4331-9C61-3B5045A1389A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FluentValidationsExtensions", "Extensions\FluentValidationsExtensions\FluentValidationsExtensions.csproj", "{5B43A461-C8AC-44C0-94D5-DAEE102A5F41}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{5046CC21-D258-4313-8866-E952ABB472E4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FluentValidationsExtensions.Tests", "Extensions\Tests\FluentValidationsExtensions.Tests\FluentValidationsExtensions.Tests.csproj", "{07BCB8B9-AFA2-485B-A01D-EB11FAFD5061}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -36,10 +44,23 @@ Global
{6871A016-97E8-48C5-B797-DD0FA3DD6288}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6871A016-97E8-48C5-B797-DD0FA3DD6288}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6871A016-97E8-48C5-B797-DD0FA3DD6288}.Release|Any CPU.Build.0 = Release|Any CPU
{5B43A461-C8AC-44C0-94D5-DAEE102A5F41}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5B43A461-C8AC-44C0-94D5-DAEE102A5F41}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5B43A461-C8AC-44C0-94D5-DAEE102A5F41}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5B43A461-C8AC-44C0-94D5-DAEE102A5F41}.Release|Any CPU.Build.0 = Release|Any CPU
{07BCB8B9-AFA2-485B-A01D-EB11FAFD5061}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{07BCB8B9-AFA2-485B-A01D-EB11FAFD5061}.Debug|Any CPU.Build.0 = Debug|Any CPU
{07BCB8B9-AFA2-485B-A01D-EB11FAFD5061}.Release|Any CPU.ActiveCfg = Release|Any CPU
{07BCB8B9-AFA2-485B-A01D-EB11FAFD5061}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{5B43A461-C8AC-44C0-94D5-DAEE102A5F41} = {9AE7A2BC-8475-4331-9C61-3B5045A1389A}
{5046CC21-D258-4313-8866-E952ABB472E4} = {9AE7A2BC-8475-4331-9C61-3B5045A1389A}
{07BCB8B9-AFA2-485B-A01D-EB11FAFD5061} = {5046CC21-D258-4313-8866-E952ABB472E4}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {CE28B97B-DDE7-41B6-B779-91914BDBCB80}
EndGlobalSection
Expand Down
5 changes: 4 additions & 1 deletion CommandLineParser/Abstractions/IContainerResolver.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
namespace MatthiWare.CommandLine.Abstractions
using System;

namespace MatthiWare.CommandLine.Abstractions
{
public interface IContainerResolver
{
T Resolve<T>();
object Resolve(Type type);
}
}
10 changes: 10 additions & 0 deletions CommandLineParser/Abstractions/Validations/IValidationResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;

namespace MatthiWare.CommandLine.Abstractions.Validations
{
public interface IValidationResult
{
bool IsValid { get; }
Exception Error { get; }
}
}
11 changes: 11 additions & 0 deletions CommandLineParser/Abstractions/Validations/IValidator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace MatthiWare.CommandLine.Abstractions.Validations
{
public interface IValidator
{
IValidationResult Validate(object @object);
}
}
11 changes: 11 additions & 0 deletions CommandLineParser/Abstractions/Validations/IValidator`T.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace MatthiWare.CommandLine.Abstractions.Validations
{
public interface IValidator<T> : IValidator
{
IValidationResult Validate(T @object);
}
}
21 changes: 21 additions & 0 deletions CommandLineParser/Abstractions/Validations/IValidatorsContainer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace MatthiWare.CommandLine.Abstractions.Validations
{
public interface IValidatorsContainer
{
void AddValidator<TKey>(IValidator<TKey> validator);
void AddValidator(Type key, IValidator validator);

void AddValidator<TKey, V>() where V : IValidator<TKey>;
void AddValidator(Type key, Type validator);

bool HasValidatorFor<TKey>();
bool HasValidatorFor(Type type);

IReadOnlyCollection<IValidator> GetValidators<TKey>();
IReadOnlyCollection<IValidator> GetValidators(Type key);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace MatthiWare.CommandLine.Abstractions.Validations
{
public abstract class ValidationConfigurationBase
{
protected IValidatorsContainer Validators { get; private set; }

public ValidationConfigurationBase(IValidatorsContainer validators)
{
Validators = validators;
}
}
}
22 changes: 16 additions & 6 deletions CommandLineParser/CommandLineParser.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@
<TargetFramework>netstandard2.0</TargetFramework>
<RootNamespace>MatthiWare.CommandLine</RootNamespace>
<PackageId>MatthiWare.CommandLineParser</PackageId>
<Version>0.2.3</Version>
<Version>0.2.4</Version>
<Authors>Matthias Beerens</Authors>
<Company>MatthiWare</Company>
<Product>Command Line Parser</Product>
<Description>Command Line Parser for .Net Core</Description>
<Description>Command Line Parser for .NET Core written in .NET Standard</Description>
<PackageProjectUrl>https://github.com/MatthiWare/CommandLineParser.Core</PackageProjectUrl>
<PackageLicenseUrl>https://github.com/MatthiWare/CommandLineParser.Core/blob/master/LICENSE</PackageLicenseUrl>
<PackageLicenseUrl></PackageLicenseUrl>
<RepositoryUrl>https://github.com/MatthiWare/CommandLineParser.Core</RepositoryUrl>
<PackageTags>Commandline parser</PackageTags>
<PackageTags>Commandline parser commandline-parser cli</PackageTags>
<LangVersion>7.3</LangVersion>
<AssemblyVersion>0.2.3.0</AssemblyVersion>
<FileVersion>0.2.3.0</FileVersion>
<AssemblyVersion>0.2.4.0</AssemblyVersion>
<FileVersion>0.2.4.0</FileVersion>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageReleaseNotes>Validation API added, general bugfixes and improvements</PackageReleaseNotes>
<Copyright>Copyright Matthias Beerens 2018</Copyright>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand All @@ -32,4 +35,11 @@
<PackageReference Include="System.Memory" Version="4.5.3" />
</ItemGroup>

<ItemGroup>
<None Include="..\LICENSE">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
</ItemGroup>

</Project>
3 changes: 2 additions & 1 deletion CommandLineParser/CommandLineParser.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package>
<metadata>
<id>MatthiWare.CommandLineParser</id>
<version>0.2.3</version>
<version>0.2.4</version>
<title>CommandLineParser.Core</title>
<authors>Matthias Beerens</authors>
<owners>Matthiee</owners>
Expand All @@ -21,6 +21,7 @@
<tags>commandline parser commandline-parser</tags>
</metadata>
<files>
<file src="CommandLineParser.dll" target="lib\netstandard2.0" />
<file src=".\CommandLineParser.xml" target="lib\netstandard2.0" />
</files>
</package>
5 changes: 5 additions & 0 deletions CommandLineParser/CommandLineParser.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading