Skip to content

Commit

Permalink
Вернуть поле src в объекте PhotoSize (#928)
Browse files Browse the repository at this point in the history
  • Loading branch information
Panuchi authored Feb 6, 2020
1 parent e801324 commit 3a03a7e
Show file tree
Hide file tree
Showing 6 changed files with 251 additions and 15 deletions.
4 changes: 2 additions & 2 deletions VkNet.Tests/Categories/FaveCategoryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,15 @@ 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));
Assert.That(photo.OwnerId, Is.EqualTo(-66589869));
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));
Expand Down
6 changes: 3 additions & 3 deletions VkNet.Tests/Categories/PhotoSaveMessagePhotoTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
45 changes: 40 additions & 5 deletions VkNet.Tests/Categories/PhotosCategoryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}
}
200 changes: 200 additions & 0 deletions VkNet.Tests/TestData/Categories/Photos/GetAlbums_Photo_Sizes.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
]
}
}
6 changes: 3 additions & 3 deletions VkNet/Model/Image.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
};
}

Expand Down
5 changes: 3 additions & 2 deletions VkNet/Model/PhotoSize.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public class PhotoSize
/// <summary>
/// Uri копии изображения.
/// </summary>
[Obsolete("Используйте поле url. Данное поле будет удалено в релизе 2.0.0")]
public Uri Src => Url;
[JsonProperty("src")]
public Uri Src { get; set; }

/// <summary>
/// Uri копии изображения.
Expand Down Expand Up @@ -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"],
Expand Down

0 comments on commit 3a03a7e

Please sign in to comment.