File tree 3 files changed +16
-8
lines changed
3 files changed +16
-8
lines changed Original file line number Diff line number Diff line change @@ -13,10 +13,11 @@ public class ObjectController:ControllerBase
13
13
14
14
public bool CheckObj ( [ FromJson ] TestModel model )
15
15
{
16
- if ( string . IsNullOrEmpty ( model . Text ) )
16
+ if ( string . IsNullOrEmpty ( model . Text ) || string . IsNullOrEmpty ( model . Detail . Name ) )
17
17
{
18
18
return false ;
19
19
}
20
+
20
21
return true ;
21
22
}
22
23
Original file line number Diff line number Diff line change @@ -9,5 +9,10 @@ public class TestModel
9
9
public string Text { get ; set ; }
10
10
public DateTime ? CreateAt { get ; set ; }
11
11
public int Status { get ; set ; }
12
+ public SecondModel Detail { get ; set ; }
13
+ }
14
+ public class SecondModel
15
+ {
16
+ public string Name { get ; set ; }
12
17
}
13
18
}
Original file line number Diff line number Diff line change 2
2
using FromJson . Tests . Controllers ;
3
3
using FromJson . Tests . Models ;
4
4
using NUnit . Framework ;
5
- using System ;
6
- using System . Collections . Generic ;
7
- using System . Text ;
8
5
9
6
namespace FromJson . Tests
10
7
{
11
- public class ObjectTests : Server
8
+ public class ObjectTests : Server
12
9
{
13
10
string ControllerName = "Object" ;
14
11
15
12
[ Test ]
16
13
public void ObjectInArgument ( )
17
14
{
18
15
var server = GetTestServer ( ) ;
19
- var model = new TestModel ( ) {
20
- Text = "bbbb"
16
+ var model = new TestModel ( )
17
+ {
18
+ Text = "bbbb" ,
19
+ Detail = new SecondModel ( )
20
+ {
21
+ Name = "Name!"
22
+ }
21
23
} ;
22
24
using ( var client = server . CreateClient ( ) )
23
25
{
24
26
var res = client . PostAsync ( $ "/{ ControllerName } /{ nameof ( ObjectController . CheckObj ) } ", ParseJsonContent ( new
25
27
{
26
28
model = model
27
29
} ) ) . Result ;
28
- Assert . AreEqual ( true , bool . Parse ( res . Content . ReadAsStringAsync ( ) . Result ) ) ;
30
+ Assert . AreEqual ( true , bool . Parse ( res . Content . ReadAsStringAsync ( ) . Result ) ) ;
29
31
}
30
32
Assert . Pass ( ) ;
31
33
}
You can’t perform that action at this time.
0 commit comments