Skip to content

Commit 5647e24

Browse files
committed
add object tests
1 parent 1358411 commit 5647e24

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

FromJson.Tests/Controllers/ObjectController.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ public class ObjectController:ControllerBase
1313

1414
public bool CheckObj([FromJson]TestModel model)
1515
{
16-
if (string.IsNullOrEmpty(model.Text))
16+
if (string.IsNullOrEmpty(model.Text) || string.IsNullOrEmpty(model.Detail.Name))
1717
{
1818
return false;
1919
}
20+
2021
return true;
2122
}
2223

FromJson.Tests/Models/TestModel.cs

+5
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,10 @@ public class TestModel
99
public string Text { get; set; }
1010
public DateTime? CreateAt { get; set; }
1111
public int Status { get; set; }
12+
public SecondModel Detail { get; set; }
13+
}
14+
public class SecondModel
15+
{
16+
public string Name { get; set; }
1217
}
1318
}

FromJson.Tests/ObjectTests.cs

+9-7
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,32 @@
22
using FromJson.Tests.Controllers;
33
using FromJson.Tests.Models;
44
using NUnit.Framework;
5-
using System;
6-
using System.Collections.Generic;
7-
using System.Text;
85

96
namespace FromJson.Tests
107
{
11-
public class ObjectTests:Server
8+
public class ObjectTests : Server
129
{
1310
string ControllerName = "Object";
1411

1512
[Test]
1613
public void ObjectInArgument()
1714
{
1815
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+
}
2123
};
2224
using (var client = server.CreateClient())
2325
{
2426
var res = client.PostAsync($"/{ControllerName}/{nameof(ObjectController.CheckObj)}", ParseJsonContent(new
2527
{
2628
model = model
2729
})).Result;
28-
Assert.AreEqual(true,bool.Parse(res.Content.ReadAsStringAsync().Result));
30+
Assert.AreEqual(true, bool.Parse(res.Content.ReadAsStringAsync().Result));
2931
}
3032
Assert.Pass();
3133
}

0 commit comments

Comments
 (0)