Skip to content

Commit 79e351c

Browse files
Keboojonsequitur
authored andcommitted
Added model binder test
Cleaned up some dead test classes that are no longer used by the model binder tests
1 parent 506060e commit 79e351c

File tree

2 files changed

+25
-110
lines changed

2 files changed

+25
-110
lines changed

src/System.CommandLine.Tests/Binding/ModelBinderTests.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,5 +616,30 @@ public void Custom_ModelBinders_specified_via_BindingContext_can_be_used_for_com
616616

617617
boundInstance.Value.Should().Be(456);
618618
}
619+
620+
[Fact]
621+
public void Default_values_from_options_with_the_same_type_are_bound_and_use_their_own_defaults()
622+
{
623+
int first = 0, second = 0;
624+
625+
var rootCommand = new RootCommand
626+
{
627+
new Option<int>("one", () => 1),
628+
new Option<int>("two", () => 2)
629+
};
630+
rootCommand.Handler = CommandHandler.Create<int, int>((one, two) =>
631+
{
632+
first = one;
633+
second = two;
634+
});
635+
636+
var parser = new CommandLineBuilder(rootCommand)
637+
.Build();
638+
639+
parser.Invoke("");
640+
641+
first.Should().Be(1);
642+
second.Should().Be(2);
643+
}
619644
}
620645
}

src/System.CommandLine.Tests/Binding/TestModels.cs

Lines changed: 0 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,6 @@
55

66
namespace System.CommandLine.Tests.Binding
77
{
8-
public class ClassWithSingleLetterCtorParameter
9-
{
10-
public ClassWithSingleLetterCtorParameter(int x, string y)
11-
{
12-
X = x;
13-
Y = y;
14-
}
15-
16-
public int X { get; }
17-
18-
public string Y { get; }
19-
}
20-
21-
public class ClassWithSingleLetterProperty
22-
{
23-
public int X { get; set; }
24-
25-
public int Y { get; set; }
26-
}
27-
288
public class ClassWithMultiLetterCtorParameters
299
{
3010
public ClassWithMultiLetterCtorParameters(
@@ -66,23 +46,6 @@ public ClassWithSettersAndCtorParametersWithDifferentNames(
6646
public bool BoolOption { get; set; }
6747
}
6848

69-
public class ClassWithSettersAndCtorParametersWithMatchingNames
70-
{
71-
public ClassWithSettersAndCtorParametersWithMatchingNames(
72-
int intOption = 123,
73-
string stringOption = "the default",
74-
bool boolOption = false)
75-
{
76-
IntOption = intOption;
77-
StringOption = stringOption;
78-
BoolOption = boolOption;
79-
}
80-
81-
public int IntOption { get; set; }
82-
public string StringOption { get; set; }
83-
public bool BoolOption { get; set; }
84-
}
85-
8649
public class ClassWithCtorParameter<T>
8750
{
8851
public ClassWithCtorParameter(T value) => Value = value;
@@ -125,79 +88,6 @@ public Task<int> HandleAsync(T value)
12588
public T ReceivedValue { get; set; }
12689
}
12790

128-
public class TypeWithInvokeAndCtor
129-
{
130-
public TypeWithInvokeAndCtor(int intFromCtor, string stringFromCtor)
131-
{
132-
IntValueFromCtor = intFromCtor;
133-
StringValueFromCtor = stringFromCtor;
134-
}
135-
136-
public int IntValueFromCtor { get; }
137-
138-
public string StringValueFromCtor { get; }
139-
140-
public int IntProperty { get; set; }
141-
public string StringProperty { get; set; }
142-
143-
public Task<int> Invoke(string stringParam, int intParam)
144-
{
145-
return Task.FromResult(76);
146-
}
147-
}
148-
149-
public class ClassWithInvokeAndDefaultCtor
150-
{
151-
public int IntProperty { get; set; }
152-
public string StringProperty { get; set; }
153-
154-
public Task<int> Invoke(string stringParam, int intParam)
155-
{
156-
return Task.FromResult(66);
157-
}
158-
159-
public Task<int> SomethingElse(int intParam, string stringParam)
160-
{
161-
return Task.FromResult(67);
162-
}
163-
}
164-
165-
public class ClassWithStaticsInvokeAndCtor
166-
{
167-
public ClassWithStaticsInvokeAndCtor(int intFromCtor, string stringFromCtor)
168-
{
169-
IntValueFromCtor = intFromCtor;
170-
StringValueFromCtor = stringFromCtor;
171-
}
172-
173-
public static int StaticIntProperty { get; set; } = 67;
174-
175-
public static string StaticStringProperty { get; set; }
176-
177-
public int IntValueFromCtor { get; }
178-
179-
public string StringValueFromCtor { get; }
180-
181-
public int IntProperty { get; set; }
182-
public string StringProperty { get; set; }
183-
184-
public static Task<int> Invoke(string stringParam, int intParam)
185-
{
186-
return Task.FromResult(96);
187-
}
188-
}
189-
190-
public class ClassWithParameterlessInvokeAndDefaultCtor
191-
{
192-
public int IntProperty { get; set; }
193-
public string StringProperty { get; set; }
194-
195-
public Task<int> Invoke()
196-
{
197-
return Task.FromResult(86);
198-
}
199-
}
200-
20191
public class ClassWithMultipleCtor
20292
{
20393
public ClassWithMultipleCtor()

0 commit comments

Comments
 (0)