Skip to content

Commit dc69c40

Browse files
Исправлено - поле User.Military это массив
1 parent feef559 commit dc69c40

File tree

4 files changed

+46
-4
lines changed

4 files changed

+46
-4
lines changed

VkNet.Tests/Categories/Users/UserGetTests.cs

+24-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Collections.Generic;
1+
using System.Collections.Generic;
22
using System.Linq;
33
using FluentAssertions;
44
using VkNet.Enums;
@@ -35,4 +35,27 @@ public void Get_Olesya_SingleUser()
3535
user.Sex.Should()
3636
.Be(Sex.Deactivated);
3737
}
38+
39+
[Fact]
40+
public void Get_Male_SingleUser()
41+
{
42+
Url = "https://api.vk.com/method/users.get";
43+
ReadCategoryJsonPath(nameof(Get_Male_SingleUser));
44+
45+
var users = Api.Users.Get(new List<long>
46+
{
47+
43136387
48+
}, ProfileFields.Military);
49+
50+
users.Should()
51+
.NotBeNull();
52+
53+
var user = users.FirstOrDefault();
54+
55+
user.Should()
56+
.NotBeNull();
57+
58+
user.Military.Should()
59+
.NotBeNullOrEmpty();
60+
}
3861
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"response": [
3+
{
4+
"id": 43136387,
5+
"military": [
6+
{
7+
"unit": "145 отдельный инженерно-саперный батальон 31 Висленской танковой",
8+
"unit_id": 3363063,
9+
"from": 1986,
10+
"until": 1988
11+
}
12+
],
13+
"first_name": "Влад",
14+
"last_name": "Невідомий",
15+
"can_access_closed": true,
16+
"is_closed": false
17+
}
18+
]
19+
}

VkNet/Model/User.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ private string Name
402402
/// Информация о военной службе пользователя.
403403
/// </summary>
404404
[JsonProperty("military")]
405-
public Military Military { get; set; }
405+
public Military[] Military { get; set; }
406406

407407
/// <summary>
408408
/// Любимые фильмы пользователя.

VkNet/Utils/JsonConverter/UserJsonConverter.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.ObjectModel;
33
using Newtonsoft.Json;
44
using Newtonsoft.Json.Linq;
@@ -199,7 +199,7 @@ public override User ReadJson(JsonReader reader, Type objectType, User existingV
199199
.ToString()),
200200
Military = !response.ContainsKey("military")
201201
? null
202-
: JsonConvert.DeserializeObject<Military>(response["military"]
202+
: JsonConvert.DeserializeObject<Military[]>(response["military"]
203203
.ToString()),
204204
Blacklisted = response["blacklisted"],
205205
BlacklistedByMe = response["blacklisted_by_me"],

0 commit comments

Comments
 (0)