Skip to content

Commit

Permalink
Исправлено - поле User.Military это массив
Browse files Browse the repository at this point in the history
  • Loading branch information
CaCTuCaTu4ECKuu committed Oct 1, 2024
1 parent feef559 commit dc69c40
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 4 deletions.
25 changes: 24 additions & 1 deletion VkNet.Tests/Categories/Users/UserGetTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using FluentAssertions;
using VkNet.Enums;
Expand Down Expand Up @@ -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<long>
{
43136387
}, ProfileFields.Military);

users.Should()
.NotBeNull();

var user = users.FirstOrDefault();

user.Should()
.NotBeNull();

user.Military.Should()
.NotBeNullOrEmpty();
}
}
19 changes: 19 additions & 0 deletions VkNet.Tests/TestData/Categories/Users/Get_Male_SingleUser.json
Original file line number Diff line number Diff line change
@@ -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
}
]
}
2 changes: 1 addition & 1 deletion VkNet/Model/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ private string Name
/// Информация о военной службе пользователя.
/// </summary>
[JsonProperty("military")]
public Military Military { get; set; }
public Military[] Military { get; set; }

/// <summary>
/// Любимые фильмы пользователя.
Expand Down
4 changes: 2 additions & 2 deletions VkNet/Utils/JsonConverter/UserJsonConverter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.ObjectModel;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
Expand Down Expand Up @@ -199,7 +199,7 @@ public override User ReadJson(JsonReader reader, Type objectType, User existingV
.ToString()),
Military = !response.ContainsKey("military")
? null
: JsonConvert.DeserializeObject<Military>(response["military"]
: JsonConvert.DeserializeObject<Military[]>(response["military"]
.ToString()),
Blacklisted = response["blacklisted"],
BlacklistedByMe = response["blacklisted_by_me"],
Expand Down

0 comments on commit dc69c40

Please sign in to comment.