diff --git a/PocketSharp.Tests/DefaultAccount.playlist b/PocketSharp.Tests/DefaultAccount.playlist new file mode 100644 index 0000000..90ba01b --- /dev/null +++ b/PocketSharp.Tests/DefaultAccount.playlist @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/PocketSharp.Tests/GetTests.cs b/PocketSharp.Tests/GetTests.cs index 54b4367..3678084 100644 --- a/PocketSharp.Tests/GetTests.cs +++ b/PocketSharp.Tests/GetTests.cs @@ -1,6 +1,7 @@ using System; using System.Threading.Tasks; using System.Collections.Generic; +using System.Linq; using Xunit; using PocketSharp.Models; @@ -147,7 +148,7 @@ namespace PocketSharp.Tests [Fact] public async Task AreStatisticsRetrieved() { - PocketStatistics statistics = await client.Statistics(); + PocketStatistics statistics = await client.GetUserStatistics(); Assert.True(statistics.CountAll > 0); } @@ -160,5 +161,15 @@ namespace PocketSharp.Tests Assert.True(limits.RateLimitForConsumerKey > 9999); } + + + [Fact] + public async Task IsNewPocketItemListGeneratorWorking() + { + List items = await client.Get(count: 1, tag: "pocket"); + PocketItem item = items[0]; + + Assert.True(item.Tags.Find(i => i.Name == "pocket") != null); + } } } diff --git a/PocketSharp.Tests/StressAccount.playlist b/PocketSharp.Tests/StressAccount.playlist new file mode 100644 index 0000000..fd7a074 --- /dev/null +++ b/PocketSharp.Tests/StressAccount.playlist @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/PocketSharp.Tests/StressTests.cs b/PocketSharp.Tests/StressTests.cs index 551dd7e..5eec649 100644 --- a/PocketSharp.Tests/StressTests.cs +++ b/PocketSharp.Tests/StressTests.cs @@ -25,37 +25,35 @@ namespace PocketSharp.Tests ); urls = File.ReadAllLines("../../url-10000.csv").Select(item => item.Split(',')[1]); - - //await FillAccount(598, 10000); } [Fact] public async Task Are100ItemsRetrievedProperly() { - + // await FillAccount(1257, 10000); } [Fact] - public void Are1000ItemsRetrievedProperly() + public async Task Are1000ItemsRetrievedProperly() { } [Fact] - public void Are10000ItemsRetrievedProperly() + public async Task Are10000ItemsRetrievedProperly() { } [Fact] - public void Are0ItemsRetrievedProperly() + public async Task Are0ItemsRetrievedProperly() { } [Fact] - public void IsSearchedSuccessfullyOn10000Items() + public async Task IsSearchedSuccessfullyOn10000Items() { } diff --git a/PocketSharp/Models/PocketItem.cs b/PocketSharp/Models/PocketItem.cs index 75d9950..596a2f7 100644 --- a/PocketSharp/Models/PocketItem.cs +++ b/PocketSharp/Models/PocketItem.cs @@ -200,65 +200,44 @@ namespace PocketSharp.Models /// - /// Gets or sets the _ tag dictionary. - /// - /// - /// The _ tag dictionary. - /// - [JsonProperty("tags")] - private Dictionary _TagDictionary { get; set; } - - /// - /// Gets or sets the _ image dictionary. - /// - /// - /// The _ image dictionary. - /// - [JsonProperty("images")] - private Dictionary _ImageDictionary { get; set; } - - /// - /// Gets or sets the _ video dictionary. - /// - /// - /// The _ video dictionary. - /// - [JsonProperty("videos")] - private Dictionary _VideoDictionary { get; set; } - - /// - /// Gets or sets the _ author dictionary. - /// - /// - /// The _ author dictionary. - /// - [JsonProperty("authors")] - private Dictionary _AuthorDictionary { get; set; } - - - /// - /// Gets the tags. + /// Gets or sets the tags. /// /// /// The tags. /// - [JsonIgnore] - public List Tags - { - get { return Utilities.DictionaryToList(_TagDictionary); } - } + [JsonProperty("tags")] + [JsonConverter(typeof(ObjectToArrayConverter))] + public List Tags { get; set; } /// - /// Gets the images. + /// Gets or sets the images. /// /// /// The images. /// - [JsonIgnore] - public List Images - { - get { return Utilities.DictionaryToList(_ImageDictionary); } - } + [JsonProperty("images")] + [JsonConverter(typeof(ObjectToArrayConverter))] + public List Images { get; set; } + + /// + /// Gets or sets the videos. + /// + /// + /// The videos. + /// + [JsonProperty("videos")] + [JsonConverter(typeof(ObjectToArrayConverter))] + public List Videos { get; set; } + + /// + /// Gets or sets the authors. + /// + /// + /// The authors. + /// + [JsonProperty("authors")] + [JsonConverter(typeof(ObjectToArrayConverter))] + public List Authors { get; set; } /// /// Gets the lead image. @@ -271,29 +250,5 @@ namespace PocketSharp.Models { get { return Images != null && Images.Count > 0 ? Images[0] : null; } } - - /// - /// Gets the videos. - /// - /// - /// The videos. - /// - [JsonIgnore] - public List Videos - { - get { return Utilities.DictionaryToList(_VideoDictionary); } - } - - /// - /// Gets the authors. - /// - /// - /// The authors. - /// - [JsonIgnore] - public List Authors - { - get { return Utilities.DictionaryToList(_AuthorDictionary); } - } } } diff --git a/PocketSharp/Models/PocketTag.cs b/PocketSharp/Models/PocketTag.cs index 260f662..5505797 100644 --- a/PocketSharp/Models/PocketTag.cs +++ b/PocketSharp/Models/PocketTag.cs @@ -3,20 +3,20 @@ using PropertyChanged; namespace PocketSharp.Models { + /// + /// Tag + /// + [JsonObject] + [ImplementPropertyChanged] + public class PocketTag + { /// - /// Tag + /// Gets or sets the name. /// - [JsonObject] - [ImplementPropertyChanged] - public class PocketTag - { - /// - /// Gets or sets the name. - /// - /// - /// The name. - /// - [JsonProperty("tag")] - public string Name { get; set; } - } + /// + /// The name. + /// + [JsonProperty("tag")] + public string Name { get; set; } + } } diff --git a/PocketSharp/Models/PocketVideo.cs b/PocketSharp/Models/PocketVideo.cs index acad82e..4cb7247 100644 --- a/PocketSharp/Models/PocketVideo.cs +++ b/PocketSharp/Models/PocketVideo.cs @@ -4,38 +4,38 @@ using PropertyChanged; namespace PocketSharp.Models { + /// + /// Video + /// + [JsonObject] + [ImplementPropertyChanged] + public class PocketVideo + { /// - /// Video + /// Gets or sets the ID. /// - [JsonObject] - [ImplementPropertyChanged] - public class PocketVideo - { - /// - /// Gets or sets the ID. - /// - /// - /// The ID. - /// - [JsonProperty("video_id")] - public string ID { get; set; } + /// + /// The ID. + /// + [JsonProperty("video_id")] + public string ID { get; set; } - /// - /// Gets or sets the external ID. - /// - /// - /// The external ID. - /// - [JsonProperty("vid")] - public string ExternalID { get; set; } + /// + /// Gets or sets the external ID. + /// + /// + /// The external ID. + /// + [JsonProperty("vid")] + public string ExternalID { get; set; } - /// - /// Gets or sets the URI. - /// - /// - /// The URI. - /// - [JsonProperty("src")] - public Uri Uri { get; set; } - } + /// + /// Gets or sets the URI. + /// + /// + /// The URI. + /// + [JsonProperty("src")] + public Uri Uri { get; set; } + } } diff --git a/PocketSharp/Utilities/JsonExtensions.cs b/PocketSharp/Utilities/JsonExtensions.cs index fedab93..839dc58 100644 --- a/PocketSharp/Utilities/JsonExtensions.cs +++ b/PocketSharp/Utilities/JsonExtensions.cs @@ -1,6 +1,9 @@ using Newtonsoft.Json; using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Linq; using System; +using System.Collections.Generic; +using System.Diagnostics; namespace PocketSharp { @@ -70,4 +73,31 @@ namespace PocketSharp return objectType == typeof(int); } } + + + + public class ObjectToArrayConverter : CustomCreationConverter> where T : new() + { + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + { + List result = new List(); + JObject jObject = JObject.Load(reader); + T target; + + // Populate the object properties + foreach (KeyValuePair item in jObject) + { + target = new T(); + serializer.Populate(item.Value.CreateReader(), target); + result.Add(target); + } + + return result; + } + + public override List Create(Type objectType) + { + return new List(); + } + } }