fix tag parameter conversion; lead image generation; add complex item test;

This commit is contained in:
2013-09-17 22:48:35 +02:00
parent 9d0fb6484f
commit f40221adbd
3 changed files with 42 additions and 3 deletions
+29
View File
@@ -22,5 +22,34 @@ namespace PocketSharp.Tests
itemsToDelete.Add(item.ID);
}
[Fact]
public async Task AddComplexItem()
{
PocketItem item = await client.Add(
uri: new Uri("http://frontendplay.com"),
tags: new string[] { "blog", "frontend", "cee" },
title: "ignored title",
tweetID: "380051788172632065"
);
List<PocketItem> items = await client.Retrieve();
PocketItem itemDesired = null;
items.ForEach(itm =>
{
if(itm.ID == item.ID)
{
itemDesired = itm;
}
});
Assert.NotNull(itemDesired);
Assert.Equal(itemDesired.ID, item.ID);
Assert.Equal(itemDesired.Tags.Count, 3);
itemsToDelete.Add(item.ID);
}
}
}
+12 -2
View File
@@ -3,6 +3,8 @@ using System.Collections.Generic;
using System.Reflection;
using System.Runtime.Serialization;
using System.Linq;
using System.Collections;
using Newtonsoft.Json;
namespace PocketSharp.Models
{
@@ -31,11 +33,19 @@ namespace PocketSharp.Models
{
DataMemberAttribute attribute = (DataMemberAttribute)propertyInfo.GetCustomAttributes(typeof(DataMemberAttribute), false).FirstOrDefault();
string name = attribute.Name ?? propertyInfo.Name.ToLower();
object value = propertyInfo.GetValue(this, null);
if (propertyInfo.GetValue(this, null) != null)
if (value == null)
{
parameterDict.Add(name, propertyInfo.GetValue(this, null).ToString());
continue;
}
if (value is IEnumerable && value.GetType().GetElementType() == typeof(string))
{
value = string.Join(",", ((IEnumerable)value).Cast<object>().Select(x => x.ToString()).ToArray());
}
parameterDict.Add(name, value.ToString());
}
return parameterDict;
+1 -1
View File
@@ -268,7 +268,7 @@ namespace PocketSharp.Models
[JsonIgnore]
public PocketImage LeadImage
{
get { return Images.Count > 0 ? Images[0] : null; }
get { return Images != null && Images.Count > 0 ? Images[0] : null; }
}
/// <summary>