Skip to content

Commit ad301c3

Browse files
committed
Consolidated both option collections into a single class, generalizing each type of option to IOption. Added embedded property tests.
1 parent 326ff26 commit ad301c3

24 files changed

+653
-278
lines changed

Binder.Tests/Binder.Tests.csproj

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414

1515
<ItemGroup>
1616
<Compile Remove="test-data\CollectionTests.cs" />
17+
<Compile Remove="test-data\OptionContextConfig.cs" />
18+
<Compile Remove="test-data\OptionTypeBoundConfig.cs" />
1719
<Compile Remove="test-data\SingleValueTests.cs" />
1820
<Compile Remove="test-data\SwitchTests.cs" />
19-
<Compile Remove="EmbeddedTest.cs" />
2021
</ItemGroup>
2122

2223
<ItemGroup>
@@ -46,8 +47,11 @@
4647
<None Update="appConfig.json">
4748
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
4849
</None>
50+
<None Update="embeddedProperties.json">
51+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
52+
</None>
4953
<None Update="singleProperties.json">
50-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
54+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
5155
</None>
5256
</ItemGroup>
5357

Binder.Tests/ContextTests.cs

Lines changed: 0 additions & 25 deletions
This file was deleted.

Binder.Tests/EmbeddedProperties.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System.Collections.Generic;
2+
using FluentAssertions;
3+
using Xunit;
4+
5+
namespace J4JSoftware.Binder.Tests
6+
{
7+
public class EmbeddedProperties : BaseTest
8+
{
9+
[Theory]
10+
[MemberData(nameof(TestDataSource.GetEmbeddedPropertyData), MemberType=typeof(TestDataSource))]
11+
public void Allocations( TestConfig config )
12+
{
13+
Initialize( config );
14+
15+
Bind<EmbeddedTarget, bool>( x => x.Target1.ASwitch );
16+
Bind<EmbeddedTarget, string>(x => x.Target1.ASingleValue);
17+
Bind<EmbeddedTarget, TestEnum>(x => x.Target1.AnEnumValue);
18+
Bind<EmbeddedTarget, TestFlagEnum>(x => x.Target1.AFlagEnumValue);
19+
Bind<EmbeddedTarget, List<string>>(x => x.Target1.ACollection);
20+
21+
ValidateAllocations();
22+
}
23+
24+
[Theory]
25+
[MemberData(nameof(TestDataSource.GetEmbeddedPropertyData), MemberType = typeof(TestDataSource))]
26+
public void Parsing(TestConfig config)
27+
{
28+
Initialize(config);
29+
30+
Bind<EmbeddedTarget, bool>(x => x.Target1.ASwitch);
31+
Bind<EmbeddedTarget, string>(x => x.Target1.ASingleValue);
32+
Bind<EmbeddedTarget, TestEnum>(x => x.Target1.AnEnumValue);
33+
Bind<EmbeddedTarget, TestFlagEnum>(x => x.Target1.AFlagEnumValue);
34+
Bind<EmbeddedTarget, List<string>>(x => x.Target1.ACollection);
35+
36+
ValidateConfiguration<EmbeddedTarget>();
37+
}
38+
}
39+
}

Binder.Tests/EmbeddedTest.cs

Lines changed: 0 additions & 92 deletions
This file was deleted.

Binder.Tests/SingleProperties.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System.Linq;
2+
using Xunit;
3+
4+
namespace J4JSoftware.Binder.Tests
5+
{
6+
public class SingleProperties : BaseTest
7+
{
8+
[ Theory ]
9+
[ MemberData( nameof(TestDataSource.GetSinglePropertyData), MemberType = typeof(TestDataSource) ) ]
10+
public void Allocations( TestConfig config )
11+
{
12+
Initialize( config );
13+
14+
Options!.CreateOptionsFromContextKeys( TestConfig!.OptionConfigurations);
15+
16+
ValidateAllocations();
17+
}
18+
19+
[ Theory ]
20+
[ MemberData( nameof(TestDataSource.GetSinglePropertyData), MemberType = typeof(TestDataSource) ) ]
21+
public void Parsing( TestConfig config )
22+
{
23+
Initialize( config );
24+
25+
Options!.CreateOptionsFromContextKeys(TestConfig!.OptionConfigurations);
26+
27+
ValidateConfiguration<BasicTarget>();
28+
}
29+
}
30+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
[
2+
{
3+
"CommandLine": "-a -b ASingleValue -c EnumValue1 -d EnumValue1 EnumValue2 -e Item1 Item2 Item3",
4+
"UnkeyedParameters": 0,
5+
"UnknownKeys": 0,
6+
"OptionConfigurations": [
7+
{
8+
"ContextPath": "Target1:ASwitch",
9+
"CommandLineKey": "a",
10+
"Style": "Switch",
11+
"ValuesSatisfied": true,
12+
"CorrectText": "true"
13+
},
14+
{
15+
"ContextPath": "Target1:ASingleValue",
16+
"CommandLineKey": "b",
17+
"Style": "SingleValued",
18+
"ValuesSatisfied": true,
19+
"CorrectText": "ASingleValue"
20+
},
21+
{
22+
"ContextPath": "Target1:AnEnumValue",
23+
"CommandLineKey": "c",
24+
"Style": "SingleValued",
25+
"ValuesSatisfied": true,
26+
"CorrectText": "EnumValue1"
27+
},
28+
{
29+
"ContextPath": "Target1:AFlagEnumValue",
30+
"CommandLineKey": "d",
31+
"Style": "ConcatenatedSingleValue",
32+
"ValuesSatisfied": true,
33+
"CorrectText": "EnumValue1, EnumValue2"
34+
},
35+
{
36+
"ContextPath": "Target1:ACollection",
37+
"CommandLineKey": "e",
38+
"Style": "Collection",
39+
"ValuesSatisfied": true,
40+
"CorrectTextArray": [
41+
"Item1",
42+
"Item2",
43+
"Item3"
44+
]
45+
}
46+
]
47+
},
48+
{
49+
"CommandLine": "-a -b -c EnumValue1 -d EnumValue1 EnumValue2 -e Item1 Item2 Item3",
50+
"UnkeyedParameters": 0,
51+
"UnknownKeys": 0,
52+
"OptionConfigurations": [
53+
{
54+
"ContextPath": "Target1:ASwitch",
55+
"CommandLineKey": "a",
56+
"Style": "Switch",
57+
"ValuesSatisfied": true,
58+
"CorrectText": "true"
59+
},
60+
{
61+
"ContextPath": "Target1:ASingleValue",
62+
"CommandLineKey": "b",
63+
"Style": "SingleValued"
64+
},
65+
{
66+
"ContextPath": "Target1:AnEnumValue",
67+
"CommandLineKey": "c",
68+
"Style": "SingleValued",
69+
"ValuesSatisfied": true,
70+
"CorrectText": "EnumValue1"
71+
},
72+
{
73+
"ContextPath": "Target1:AFlagEnumValue",
74+
"CommandLineKey": "d",
75+
"Style": "ConcatenatedSingleValue",
76+
"ValuesSatisfied": true,
77+
"CorrectText": "EnumValue1, EnumValue2"
78+
},
79+
{
80+
"ContextPath": "Target1:ACollection",
81+
"CommandLineKey": "e",
82+
"Style": "Collection",
83+
"ValuesSatisfied": true,
84+
"CorrectTextArray": [
85+
"Item1",
86+
"Item2",
87+
"Item3"
88+
]
89+
}
90+
]
91+
}
92+
]

0 commit comments

Comments
 (0)