custom UriConverter to check for invalid URIs
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using PocketSharp.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
using PocketSharp.Models;
|
||||
|
||||
namespace PocketSharp.Tests
|
||||
{
|
||||
@@ -24,6 +24,19 @@ namespace PocketSharp.Tests
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public async Task ItemWithInstableImagesIsAdded()
|
||||
{
|
||||
var uri = new Uri("http://www.valoronline.com.br");
|
||||
|
||||
PocketItem item = await client.Add(uri);
|
||||
|
||||
Assert.Equal<Uri>(uri, item.Uri);
|
||||
|
||||
itemsToDelete.Add(item.ID);
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public async Task AddComplexItem()
|
||||
{
|
||||
@@ -39,7 +52,7 @@ namespace PocketSharp.Tests
|
||||
|
||||
items.ForEach(itm =>
|
||||
{
|
||||
if(itm.ID == item.ID)
|
||||
if (itm.ID == item.ID)
|
||||
{
|
||||
itemDesired = itm;
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -30,7 +30,7 @@ namespace PocketSharp.Tests
|
||||
[Fact]
|
||||
public async Task Are100IdingtemsRetrievedProperly()
|
||||
{
|
||||
await FillAccount(8360, 10000);
|
||||
await FillAccount(9273, 10000);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -199,7 +199,8 @@ namespace PocketSharp
|
||||
{
|
||||
new BoolConverter(),
|
||||
new UnixDateTimeConverter(),
|
||||
new NullableIntConverter()
|
||||
new NullableIntConverter(),
|
||||
new UriConverter()
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
using System.Resources;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Reflection;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
@@ -25,5 +22,5 @@ using System.Runtime.InteropServices;
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("2.2.2")]
|
||||
[assembly: AssemblyFileVersion("2.2.2")]
|
||||
[assembly: AssemblyVersion("3.0.0")]
|
||||
[assembly: AssemblyFileVersion("3.0.0 RC1")]
|
||||
@@ -3,7 +3,6 @@ using Newtonsoft.Json.Converters;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace PocketSharp
|
||||
{
|
||||
@@ -40,7 +39,7 @@ namespace PocketSharp
|
||||
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
||||
{
|
||||
if(reader.Value.ToString() == "0")
|
||||
if (reader.Value.ToString() == "0")
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@@ -76,6 +75,38 @@ namespace PocketSharp
|
||||
|
||||
|
||||
|
||||
public class UriConverter : JsonConverter
|
||||
{
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
||||
{
|
||||
if (reader.TokenType == JsonToken.String && Uri.IsWellFormedUriString(reader.Value.ToString(), UriKind.Absolute))
|
||||
{
|
||||
return new Uri(reader.Value.ToString());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
writer.WriteNull();
|
||||
}
|
||||
else if (value is Uri)
|
||||
{
|
||||
writer.WriteValue(((Uri)value).OriginalString);
|
||||
}
|
||||
}
|
||||
|
||||
public override bool CanConvert(Type objectType)
|
||||
{
|
||||
return objectType.Equals(typeof(Uri));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public class ObjectToArrayConverter<T> : CustomCreationConverter<List<T>> where T : new()
|
||||
{
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
||||
|
||||
Reference in New Issue
Block a user