From 3a03a7ea72d93cfc7b5e1e10734b6abc202365fe Mon Sep 17 00:00:00 2001
From: Panuchi <41389318+Panuchi@users.noreply.github.com>
Date: Thu, 6 Feb 2020 12:15:45 +0300
Subject: [PATCH] =?UTF-8?q?=D0=92=D0=B5=D1=80=D0=BD=D1=83=D1=82=D1=8C=20?=
=?UTF-8?q?=D0=BF=D0=BE=D0=BB=D0=B5=20src=20=D0=B2=20=D0=BE=D0=B1=D1=8A?=
=?UTF-8?q?=D0=B5=D0=BA=D1=82=D0=B5=20PhotoSize=20(#928)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
VkNet.Tests/Categories/FaveCategoryTest.cs | 4 +-
.../Categories/PhotoSaveMessagePhotoTests.cs | 6 +-
VkNet.Tests/Categories/PhotosCategoryTest.cs | 45 +++-
.../Photos/GetAlbums_Photo_Sizes.json | 200 ++++++++++++++++++
VkNet/Model/Image.cs | 6 +-
VkNet/Model/PhotoSize.cs | 5 +-
6 files changed, 251 insertions(+), 15 deletions(-)
create mode 100644 VkNet.Tests/TestData/Categories/Photos/GetAlbums_Photo_Sizes.json
diff --git a/VkNet.Tests/Categories/FaveCategoryTest.cs b/VkNet.Tests/Categories/FaveCategoryTest.cs
index 18b6f59c8..5c0f483b9 100644
--- a/VkNet.Tests/Categories/FaveCategoryTest.cs
+++ b/VkNet.Tests/Categories/FaveCategoryTest.cs
@@ -98,7 +98,7 @@ public void GetPhotos_ExtendedCase()
Assert.That(photos, Is.Not.Null);
Assert.That(photos.Count, Is.EqualTo(1));
- var photo = photos.FirstOrDefault();
+ var photo = photos.First();
Assert.That(photo.Id, Is.EqualTo(390044361));
Assert.That(photo.AlbumId, Is.EqualTo(-7));
@@ -106,7 +106,7 @@ public void GetPhotos_ExtendedCase()
Assert.That(photo.UserId, Is.EqualTo(100));
Assert.That(photos[0].Sizes[0].Height, Is.EqualTo(67));
- Assert.That(photos[0].Sizes[0].Src,
+ Assert.That(photos[0].Sizes[0].Url,
Is.EqualTo(new Uri("http://cs629301.vk.me/v629301456/1caaf/XpHNgelMOc0.jpg")));
Assert.That(photos[0].Sizes[0].Width, Is.EqualTo(75));
diff --git a/VkNet.Tests/Categories/PhotoSaveMessagePhotoTests.cs b/VkNet.Tests/Categories/PhotoSaveMessagePhotoTests.cs
index a9bb414f1..40d633236 100644
--- a/VkNet.Tests/Categories/PhotoSaveMessagePhotoTests.cs
+++ b/VkNet.Tests/Categories/PhotoSaveMessagePhotoTests.cs
@@ -28,9 +28,9 @@ public void SaveMessagePhoto()
var result = Api.Photo.SaveMessagesPhoto(parameter);
Assert.IsNotEmpty(result);
- var first = result.FirstOrDefault();
- var size = first.Sizes.FirstOrDefault();
- Assert.AreEqual(new Uri("https://pp.userapi.com/c847017/v847017534/66e9c/PAZHqnQBYt4.jpg"), size.Src);
+ var first = result.First();
+ var size = first.Sizes.First();
+ Assert.AreEqual(new Uri("https://pp.userapi.com/c847017/v847017534/66e9c/PAZHqnQBYt4.jpg"), size.Url);
}
}
}
\ No newline at end of file
diff --git a/VkNet.Tests/Categories/PhotosCategoryTest.cs b/VkNet.Tests/Categories/PhotosCategoryTest.cs
index e4994d8f6..db857c95b 100644
--- a/VkNet.Tests/Categories/PhotosCategoryTest.cs
+++ b/VkNet.Tests/Categories/PhotosCategoryTest.cs
@@ -26,7 +26,8 @@ public void CreateAlbum_NormalCase()
var album = Api.Photo
.CreateAlbum(new PhotoCreateAlbumParams
{
- Title = "hello world", Description = "description for album"
+ Title = "hello world",
+ Description = "description for album"
});
Assert.That(album, Is.Not.Null);
@@ -63,7 +64,9 @@ public void EditAlbum_NormalCase()
var result = Api.Photo
.EditAlbum(new PhotoEditAlbumParams
{
- AlbumId = 19726, Title = "new album title", Description = "new description"
+ AlbumId = 19726,
+ Title = "new album title",
+ Description = "new description"
});
Assert.That(result, Is.Not.Null);
@@ -170,7 +173,9 @@ public void GetAll_NormalCase()
var photos = Api.Photo
.GetAll(new PhotoGetAllParams
{
- OwnerId = 1, Offset = 4, Count = 2
+ OwnerId = 1,
+ Offset = 4,
+ Count = 2
});
Assert.That(photos, Is.Not.Null);
@@ -341,7 +346,10 @@ public void Search_Error26_Lat_and_Long_in_output_photo()
var photos = Api.Photo
.Search(new PhotoSearchParams
{
- Query = "", Latitude = 30, Longitude = 30, Count = 2
+ Query = "",
+ Latitude = 30,
+ Longitude = 30,
+ Count = 2
});
Assert.That(photos, Is.Not.Null);
@@ -369,7 +377,9 @@ public void Search_NormalCase()
var photos = Api.Photo
.Search(new PhotoSearchParams
{
- Query = "порно", Offset = 2, Count = 3
+ Query = "порно",
+ Offset = 2,
+ Count = 3
});
Assert.That(photos, Is.Not.Null);
@@ -400,5 +410,30 @@ public void Search_NormalCase()
Assert.That(photo.CreateTime, Is.EqualTo(DateHelper.TimeStampToDateTime(1403455788))); // 2014-06-22 20:49:48.000
}
+
+ [Test]
+ public void GetAlbums_Photo_Sizes()
+ {
+ Url = "https://api.vk.com/method/photos.getAlbums";
+ ReadCategoryJsonPath(nameof(GetAlbums_Photo_Sizes));
+
+ long[] albumsids =
+ {
+ 270417281
+ };
+
+ var result = Api.Photo.GetAlbums(new PhotoGetAlbumsParams
+ {
+ AlbumIds = albumsids,
+ OwnerId = 504736359,
+ NeedSystem = true,
+ NeedCovers = true,
+ PhotoSizes = true
+ });
+
+ Assert.That(result, Is.Not.Null);
+ Assert.AreEqual(albumsids[0], result[2].Id);
+ Assert.AreEqual("https://sun9-46.userapi.com/c858232/v858232634/16acf0/SNHX0daieLw.jpg",result[2].Sizes.Last().Src.AbsoluteUri);
+ }
}
}
\ No newline at end of file
diff --git a/VkNet.Tests/TestData/Categories/Photos/GetAlbums_Photo_Sizes.json b/VkNet.Tests/TestData/Categories/Photos/GetAlbums_Photo_Sizes.json
new file mode 100644
index 000000000..a766a7c37
--- /dev/null
+++ b/VkNet.Tests/TestData/Categories/Photos/GetAlbums_Photo_Sizes.json
@@ -0,0 +1,200 @@
+{
+ "response": {
+ "count": 3,
+ "items": [
+ {
+ "id": -6,
+ "thumb_id": 457250130,
+ "owner_id": 504736359,
+ "title": "Timokha's profile photos",
+ "size": 2,
+ "sizes": [
+ {
+ "src": "https://sun9-19.userapi.com/c855528/v855528591/1594a8/uifE5_nhkIo.jpg",
+ "width": 130,
+ "height": 87,
+ "type": "m"
+ },
+ {
+ "src": "https://sun9-35.userapi.com/c855528/v855528591/1594ac/fqnqMBipv-4.jpg",
+ "width": 130,
+ "height": 87,
+ "type": "o"
+ },
+ {
+ "src": "https://sun9-30.userapi.com/c855528/v855528591/1594ad/eL2Rm3HX9wY.jpg",
+ "width": 200,
+ "height": 133,
+ "type": "p"
+ },
+ {
+ "src": "https://sun9-14.userapi.com/c855528/v855528591/1594ae/jwic8xrH-Qk.jpg",
+ "width": 320,
+ "height": 213,
+ "type": "q"
+ },
+ {
+ "src": "https://sun9-4.userapi.com/c855528/v855528591/1594af/gAQx4ROcb_Q.jpg",
+ "width": 510,
+ "height": 340,
+ "type": "r"
+ },
+ {
+ "src": "https://sun9-12.userapi.com/c855528/v855528591/1594a7/aRMHeleCazk.jpg",
+ "width": 75,
+ "height": 50,
+ "type": "s"
+ },
+ {
+ "src": "https://sun9-41.userapi.com/c855528/v855528591/1594a9/DJcyT-EI3MU.jpg",
+ "width": 604,
+ "height": 403,
+ "type": "x"
+ },
+ {
+ "src": "https://sun9-6.userapi.com/c855528/v855528591/1594aa/HlaIiWomgNM.jpg",
+ "width": 807,
+ "height": 538,
+ "type": "y"
+ },
+ {
+ "src": "https://sun9-2.userapi.com/c855528/v855528591/1594ab/oCqB4FLkvEk.jpg",
+ "width": 1280,
+ "height": 853,
+ "type": "z"
+ }
+ ]
+ },
+ {
+ "id": -7,
+ "thumb_id": 457253410,
+ "owner_id": 504736359,
+ "title": "Timokha's wall photos",
+ "size": 2,
+ "sizes": [
+ {
+ "src": "https://sun9-45.userapi.com/c857320/v857320578/9cfb2/X6HL9ETl340.jpg",
+ "width": 130,
+ "height": 97,
+ "type": "m"
+ },
+ {
+ "src": "https://sun9-48.userapi.com/c857320/v857320578/9cfb6/o1mh_4J7hkQ.jpg",
+ "width": 130,
+ "height": 98,
+ "type": "o"
+ },
+ {
+ "src": "https://sun9-33.userapi.com/c857320/v857320578/9cfb7/oi3qdVDCc6I.jpg",
+ "width": 200,
+ "height": 150,
+ "type": "p"
+ },
+ {
+ "src": "https://sun9-32.userapi.com/c857320/v857320578/9cfb8/3l-PT6irWHU.jpg",
+ "width": 320,
+ "height": 240,
+ "type": "q"
+ },
+ {
+ "src": "https://sun9-72.userapi.com/c857320/v857320578/9cfb9/5RenidHLKTI.jpg",
+ "width": 510,
+ "height": 382,
+ "type": "r"
+ },
+ {
+ "src": "https://sun9-33.userapi.com/c857320/v857320578/9cfb1/TIuJnohvBGk.jpg",
+ "width": 75,
+ "height": 56,
+ "type": "s"
+ },
+ {
+ "src": "https://sun9-67.userapi.com/c857320/v857320578/9cfb3/okbKw2LhFM0.jpg",
+ "width": 604,
+ "height": 453,
+ "type": "x"
+ },
+ {
+ "src": "https://sun9-19.userapi.com/c857320/v857320578/9cfb4/2DTNLY1nJvE.jpg",
+ "width": 807,
+ "height": 605,
+ "type": "y"
+ },
+ {
+ "src": "https://sun9-72.userapi.com/c857320/v857320578/9cfb5/zMew6hjortM.jpg",
+ "width": 1280,
+ "height": 959,
+ "type": "z"
+ }
+ ]
+ },
+ {
+ "id": 270417281,
+ "thumb_id": 457256011,
+ "owner_id": 504736359,
+ "title": "test",
+ "description": "",
+ "created": 1580933939,
+ "updated": 1580933953,
+ "size": 1,
+ "thumb_is_last": 1,
+ "sizes": [
+ {
+ "src": "https://sun9-43.userapi.com/c858232/v858232634/16ace8/4IUTktBdPzY.jpg",
+ "width": 75,
+ "height": 50,
+ "type": "s"
+ },
+ {
+ "src": "https://sun9-41.userapi.com/c858232/v858232634/16ace9/WLD9eSKzBOI.jpg",
+ "width": 130,
+ "height": 87,
+ "type": "m"
+ },
+ {
+ "src": "https://sun9-12.userapi.com/c858232/v858232634/16acea/1sRK4GVuNRU.jpg",
+ "width": 604,
+ "height": 403,
+ "type": "x"
+ },
+ {
+ "src": "https://sun9-16.userapi.com/c858232/v858232634/16aceb/WcsOF7Oawy0.jpg",
+ "width": 807,
+ "height": 538,
+ "type": "y"
+ },
+ {
+ "src": "https://sun9-59.userapi.com/c858232/v858232634/16acec/uqY3k-mTzps.jpg",
+ "width": 950,
+ "height": 633,
+ "type": "z"
+ },
+ {
+ "src": "https://sun9-21.userapi.com/c858232/v858232634/16aced/XUZYqZjL4Ks.jpg",
+ "width": 130,
+ "height": 87,
+ "type": "o"
+ },
+ {
+ "src": "https://sun9-55.userapi.com/c858232/v858232634/16acee/mtDWcWfSLU4.jpg",
+ "width": 200,
+ "height": 133,
+ "type": "p"
+ },
+ {
+ "src": "https://sun9-52.userapi.com/c858232/v858232634/16acef/d2I-WqCV5vQ.jpg",
+ "width": 320,
+ "height": 213,
+ "type": "q"
+ },
+ {
+ "src": "https://sun9-46.userapi.com/c858232/v858232634/16acf0/SNHX0daieLw.jpg",
+ "width": 510,
+ "height": 340,
+ "type": "r"
+ }
+ ]
+ }
+ ]
+ }
+}
diff --git a/VkNet/Model/Image.cs b/VkNet/Model/Image.cs
index 590758b7b..f00cc41a9 100644
--- a/VkNet/Model/Image.cs
+++ b/VkNet/Model/Image.cs
@@ -33,9 +33,9 @@ public static Image FromJson(VkResponse response)
{
return new Image
{
- Url = response[key: "url"]
- , Width = response[key: "width"]
- , Height = response[key: "height"]
+ Url = response[key: "url"],
+ Width = response[key: "width"],
+ Height = response[key: "height"]
};
}
diff --git a/VkNet/Model/PhotoSize.cs b/VkNet/Model/PhotoSize.cs
index f593708b2..c937626e6 100644
--- a/VkNet/Model/PhotoSize.cs
+++ b/VkNet/Model/PhotoSize.cs
@@ -15,8 +15,8 @@ public class PhotoSize
///
/// Uri копии изображения.
///
- [Obsolete("Используйте поле url. Данное поле будет удалено в релизе 2.0.0")]
- public Uri Src => Url;
+ [JsonProperty("src")]
+ public Uri Src { get; set; }
///
/// Uri копии изображения.
@@ -52,6 +52,7 @@ public static PhotoSize FromJson(VkResponse response)
{
var photoSize = new PhotoSize
{
+ Src = response["src"],
Url = response["url"],
Width = response[key: "width"],
Height = response[key: "height"],