From 77af7cf20e9d58956994c0b301f7f2076392e5eb Mon Sep 17 00:00:00 2001 From: Tobias Klika Date: Sun, 27 Jul 2014 15:19:14 +0200 Subject: [PATCH] Revert "sliiim" This reverts commit 816e06269f0bad630ae558c9181ba332bbb1f6cc. --- PocketSharp.Tests/GetTests.cs | 32 ++++++------ PocketSharp.Tests/StressTests.cs | 24 ++------- PocketSharp/Models/PocketItem.cs | 66 +++++++++++++++++++++++++ PocketSharp/Utilities/JsonExtensions.cs | 2 +- 4 files changed, 88 insertions(+), 36 deletions(-) diff --git a/PocketSharp.Tests/GetTests.cs b/PocketSharp.Tests/GetTests.cs index f931a01..388e6a1 100644 --- a/PocketSharp.Tests/GetTests.cs +++ b/PocketSharp.Tests/GetTests.cs @@ -33,23 +33,23 @@ namespace PocketSharp.Tests Assert.True(item.Uri == itemDuplicate.Uri); } -// [Fact] -// public async Task IsItemJsonPopulated() -// { -// List items = (await client.Get()).ToList(); -// string schemaJson = @"{ -// 'description': 'PocketItem', -// 'type': 'object' -// }"; + [Fact] + public async Task IsItemJsonPopulated() + { + List items = (await client.Get()).ToList(); + string schemaJson = @"{ + 'description': 'PocketItem', + 'type': 'object' + }"; -// JsonSchema schema = JsonSchema.Parse(schemaJson); -// foreach (var pocketItem in items) -// { -// Assert.True(!string.IsNullOrWhiteSpace(pocketItem.Json)); -// var jObject = JObject.Parse(pocketItem.Json); -// Assert.True(jObject.IsValid(schema)); -// } -// } + JsonSchema schema = JsonSchema.Parse(schemaJson); + foreach (var pocketItem in items) + { + Assert.True(!string.IsNullOrWhiteSpace(pocketItem.Json)); + var jObject = JObject.Parse(pocketItem.Json); + Assert.True(jObject.IsValid(schema)); + } + } [Fact] public async Task AreFilteredItemsRetrieved() diff --git a/PocketSharp.Tests/StressTests.cs b/PocketSharp.Tests/StressTests.cs index 4da2dc3..30fa7c1 100644 --- a/PocketSharp.Tests/StressTests.cs +++ b/PocketSharp.Tests/StressTests.cs @@ -105,27 +105,13 @@ namespace PocketSharp.Tests string[] tag; Random rnd = new Random(); - var items = urls.Skip(offset).Take(count) - .Select((value, idx) => new { Value = value, Index = idx }) - .GroupBy(item => item.Index / 100, item => item.Value) - .Cast>(); - - foreach (IEnumerable urlGroup in items) + foreach (string url in urls.Skip(offset).Take(count)) { - await Task.WhenAll(urlGroup.Select(url => - { - r = rnd.Next(tags.Length); - r2 = rnd.Next(tags.Length); - tag = new string[] { tags[r], tags[r2] }; - return client.Add(new Uri("http://" + url), tag); - })); + r = rnd.Next(tags.Length); + r2 = rnd.Next(tags.Length); + tag = new string[] { tags[r], tags[r2] }; + await client.Add(new Uri("http://" + url), tag); } } - - [Fact] - public async Task Fillll() - { - await FillAccount(11000, 89999); - } } } \ No newline at end of file diff --git a/PocketSharp/Models/PocketItem.cs b/PocketSharp/Models/PocketItem.cs index b2be7fa..ee73d1e 100644 --- a/PocketSharp/Models/PocketItem.cs +++ b/PocketSharp/Models/PocketItem.cs @@ -168,6 +168,15 @@ namespace PocketSharp.Models [JsonProperty("is_article")] public bool IsArticle { get; set; } + /// + /// Gets or sets a value indicating whether this instance has image. + /// + /// + /// true if this instance has image; otherwise, false. + /// + [JsonProperty("has_image")] + private PocketBoolean? _HasImage { get; set; } + /// /// Gets or sets a value indicating whether this instance has video. /// @@ -177,6 +186,21 @@ namespace PocketSharp.Models [JsonProperty("has_video")] private PocketBoolean? _HasVideo { get; set; } + /// + /// Gets a value indicating whether [has image]. + /// + /// + /// true if [has image]; otherwise, false. + /// + [JsonIgnore] + public bool HasImage + { + get + { + return _HasImage == PocketBoolean.Yes || _HasImage == PocketBoolean.IsType; + } + } + /// /// Gets a value indicating whether [has video]. /// @@ -207,6 +231,21 @@ namespace PocketSharp.Models } } + /// + /// Gets a value indicating whether [is image]. + /// + /// + /// true if [is image]; otherwise, false. + /// + [JsonIgnore] + public bool IsImage + { + get + { + return _HasImage == PocketBoolean.IsType; + } + } + /// /// Gets or sets the word count. /// @@ -244,6 +283,24 @@ namespace PocketSharp.Models [JsonProperty("time_updated")] public DateTime? UpdateTime { get; set; } + /// + /// Gets or sets the read time. + /// + /// + /// The read time. + /// + [JsonProperty("time_read")] + public DateTime? ReadTime { get; set; } + + /// + /// Gets or sets the favorite time. + /// + /// + /// The favorite time. + /// + [JsonProperty("time_favorited")] + public DateTime? FavoriteTime { get; set; } + /// /// Gets or sets the tags as comma-separated strings. /// @@ -308,6 +365,15 @@ namespace PocketSharp.Models get { return Images != null && Images.Count() > 0 ? Images.First() : null; } } + /// + /// Gets and sets the JSON the model was deserialized from + /// + /// + /// Model's original JSON representation + /// + [JsonIgnore] + public string Json { get; set; } + /// /// Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object. /// diff --git a/PocketSharp/Utilities/JsonExtensions.cs b/PocketSharp/Utilities/JsonExtensions.cs index fe2302a..3ce4cd7 100644 --- a/PocketSharp/Utilities/JsonExtensions.cs +++ b/PocketSharp/Utilities/JsonExtensions.cs @@ -191,7 +191,7 @@ namespace PocketSharp var jObject = JObject.ReadFrom(reader); var pocketItem = new PocketItem(); serializer.Populate(jObject.CreateReader(), pocketItem); - //pocketItem.Json = jObject.ToString(); + pocketItem.Json = jObject.ToString(); return pocketItem; }