From dc69c406ccdb20b700fcd58a2b54a7d5edfa50fc Mon Sep 17 00:00:00 2001 From: CaCTuCaTu4ECKuu Date: Tue, 1 Oct 2024 08:56:50 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=BE=20-=20=D0=BF=D0=BE=D0=BB=D0=B5=20User.Milita?= =?UTF-8?q?ry=20=D1=8D=D1=82=D0=BE=20=D0=BC=D0=B0=D1=81=D1=81=D0=B8=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- VkNet.Tests/Categories/Users/UserGetTests.cs | 25 ++++++++++++++++++- .../Categories/Users/Get_Male_SingleUser.json | 19 ++++++++++++++ VkNet/Model/User.cs | 2 +- .../Utils/JsonConverter/UserJsonConverter.cs | 4 +-- 4 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 VkNet.Tests/TestData/Categories/Users/Get_Male_SingleUser.json diff --git a/VkNet.Tests/Categories/Users/UserGetTests.cs b/VkNet.Tests/Categories/Users/UserGetTests.cs index 6673abcab..4d33f7606 100644 --- a/VkNet.Tests/Categories/Users/UserGetTests.cs +++ b/VkNet.Tests/Categories/Users/UserGetTests.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using FluentAssertions; using VkNet.Enums; @@ -35,4 +35,27 @@ public void Get_Olesya_SingleUser() user.Sex.Should() .Be(Sex.Deactivated); } + + [Fact] + public void Get_Male_SingleUser() + { + Url = "https://api.vk.com/method/users.get"; + ReadCategoryJsonPath(nameof(Get_Male_SingleUser)); + + var users = Api.Users.Get(new List + { + 43136387 + }, ProfileFields.Military); + + users.Should() + .NotBeNull(); + + var user = users.FirstOrDefault(); + + user.Should() + .NotBeNull(); + + user.Military.Should() + .NotBeNullOrEmpty(); + } } \ No newline at end of file diff --git a/VkNet.Tests/TestData/Categories/Users/Get_Male_SingleUser.json b/VkNet.Tests/TestData/Categories/Users/Get_Male_SingleUser.json new file mode 100644 index 000000000..2eedec0ec --- /dev/null +++ b/VkNet.Tests/TestData/Categories/Users/Get_Male_SingleUser.json @@ -0,0 +1,19 @@ +{ + "response": [ + { + "id": 43136387, + "military": [ + { + "unit": "145 отдельный инженерно-саперный батальон 31 Висленской танковой", + "unit_id": 3363063, + "from": 1986, + "until": 1988 + } + ], + "first_name": "Влад", + "last_name": "Невідомий", + "can_access_closed": true, + "is_closed": false + } + ] +} \ No newline at end of file diff --git a/VkNet/Model/User.cs b/VkNet/Model/User.cs index 2adf8579c..0aad53d6e 100644 --- a/VkNet/Model/User.cs +++ b/VkNet/Model/User.cs @@ -402,7 +402,7 @@ private string Name /// Информация о военной службе пользователя. /// [JsonProperty("military")] - public Military Military { get; set; } + public Military[] Military { get; set; } /// /// Любимые фильмы пользователя. diff --git a/VkNet/Utils/JsonConverter/UserJsonConverter.cs b/VkNet/Utils/JsonConverter/UserJsonConverter.cs index 9d703158b..675f93e79 100644 --- a/VkNet/Utils/JsonConverter/UserJsonConverter.cs +++ b/VkNet/Utils/JsonConverter/UserJsonConverter.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.ObjectModel; using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -199,7 +199,7 @@ public override User ReadJson(JsonReader reader, Type objectType, User existingV .ToString()), Military = !response.ContainsKey("military") ? null - : JsonConvert.DeserializeObject(response["military"] + : JsonConvert.DeserializeObject(response["military"] .ToString()), Blacklisted = response["blacklisted"], BlacklistedByMe = response["blacklisted_by_me"],