Skip to content

Commit

Permalink
Fixed issue #17, bump to 1.11.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Harms committed Nov 25, 2015
1 parent ff342e8 commit 10b2baa
Show file tree
Hide file tree
Showing 11 changed files with 193 additions and 31 deletions.
2 changes: 1 addition & 1 deletion ShopifySharp.Tests/Playlists/Orders.playlist
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<Playlist Version="1.0"><Add Test="ShopifySharp.Tests.When_getting_an_order::should_get_an_order" /><Add Test="ShopifySharp.Tests.When_updating_an_order::should_update_an_order" /><Add Test="ShopifySharp.Tests.When_opening_an_order::should_open_an_order" /><Add Test="ShopifySharp.Tests.When_closing_an_order::should_close_an_order" /><Add Test="ShopifySharp.Tests.When_listing_orders_with_options::should_only_list_2_orders" /><Add Test="ShopifySharp.Tests.When_deleting_an_order::should_delete_an_order" /><Add Test="ShopifySharp.Tests.When_counting_orders::should_retrieve_a_count_of_orders" /><Add Test="ShopifySharp.Tests.When_listing_orders::should_list_orders" /><Add Test="ShopifySharp.Tests.When_creating_an_order::should_create_an_order" /></Playlist>
<Playlist Version="1.0"><Add Test="ShopifySharp.Tests.When_getting_an_order::should_get_an_order" /><Add Test="ShopifySharp.Tests.When_updating_an_order::should_update_an_order" /><Add Test="ShopifySharp.Tests.When_opening_an_order::should_open_an_order" /><Add Test="ShopifySharp.Tests.When_closing_an_order::should_close_an_order" /><Add Test="ShopifySharp.Tests.When_listing_orders_with_options::should_only_list_2_orders" /><Add Test="ShopifySharp.Tests.When_deleting_an_order::should_delete_an_order" /><Add Test="ShopifySharp.Tests.When_counting_orders::should_retrieve_a_count_of_orders" /><Add Test="ShopifySharp.Tests.When_listing_orders::should_list_orders" /><Add Test="ShopifySharp.Tests.When_creating_an_order::should_create_an_order" /><Add Test="ShopifySharp.Tests.When_listing_orders_with_options::should_list_orders_with_a_specific_id" /><Add Test="ShopifySharp.Tests.When_listing_orders_with_options::should_list_orders_with_specific_ids" /></Playlist>
2 changes: 1 addition & 1 deletion ShopifySharp.Tests/Playlists/Products.playlist
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<Playlist Version="1.0"><Add Test="ShopifySharp.Tests.Product.When_getting_a_list_of_products::should_have_the_correct_product_id" /><Add Test="ShopifySharp.Tests.Product.When_creating_a_product::should_not_be_null" /><Add Test="ShopifySharp.Tests.Product.When_getting_one_product::should_not_be_null" /><Add Test="ShopifySharp.Tests.Product.When_deleting_a_product::should_not_throw_an_error" /><Add Test="ShopifySharp.Tests.Product.When_creating_a_product::should_have_an_id" /><Add Test="ShopifySharp.Tests.Product.When_updating_a_product::should_have_the_new_title" /><Add Test="ShopifySharp.Tests.Product.When_updating_a_product::should_not_be_null" /><Add Test="ShopifySharp.Tests.Product.When_counting_products::should_be_greater_than_zero" /><Add Test="ShopifySharp.Tests.Product.When_creating_a_product::should_have_a_title" /><Add Test="ShopifySharp.Tests.Product.When_getting_a_list_of_products::should_have_one_item_in_the_list" /><Add Test="ShopifySharp.Tests.Product.When_getting_a_list_of_products::should_retrieve_a_list_of_products_with_the_correct_id" /><Add Test="ShopifySharp.Tests.Product.When_deleting_a_product::should_delete_a_product" /><Add Test="ShopifySharp.Tests.Product.When_updating_a_product::should_update_a_product" /><Add Test="ShopifySharp.Tests.Product.When_getting_a_list_of_products::should_retrieve_a_list_of_products" /><Add Test="ShopifySharp.Tests.Product.When_creating_a_product::should_create_a_product" /><Add Test="ShopifySharp.Tests.Product.When_creating_a_product::should_create_a_product_with_a_title" /><Add Test="ShopifySharp.Tests.Product.When_counting_products::should_retrieve_a_count_of_products" /><Add Test="ShopifySharp.Tests.Product.When_creating_a_product::should_create_a_product_with_an_id" /><Add Test="ShopifySharp.Tests.Product.When_getting_one_product::should_retrieve_a_product" /><Add Test="ShopifySharp.Tests.Product.When_counting_products::should_count_products" /></Playlist>
<Playlist Version="1.0"><Add Test="ShopifySharp.Tests.Product.When_getting_a_list_of_products::should_have_the_correct_product_id" /><Add Test="ShopifySharp.Tests.Product.When_creating_a_product::should_not_be_null" /><Add Test="ShopifySharp.Tests.Product.When_getting_one_product::should_not_be_null" /><Add Test="ShopifySharp.Tests.Product.When_deleting_a_product::should_not_throw_an_error" /><Add Test="ShopifySharp.Tests.Product.When_creating_a_product::should_have_an_id" /><Add Test="ShopifySharp.Tests.Product.When_updating_a_product::should_have_the_new_title" /><Add Test="ShopifySharp.Tests.Product.When_updating_a_product::should_not_be_null" /><Add Test="ShopifySharp.Tests.Product.When_counting_products::should_be_greater_than_zero" /><Add Test="ShopifySharp.Tests.Product.When_creating_a_product::should_have_a_title" /><Add Test="ShopifySharp.Tests.Product.When_getting_a_list_of_products::should_have_one_item_in_the_list" /><Add Test="ShopifySharp.Tests.Product.When_getting_a_list_of_products::should_retrieve_a_list_of_products_with_the_correct_id" /><Add Test="ShopifySharp.Tests.Product.When_deleting_a_product::should_delete_a_product" /><Add Test="ShopifySharp.Tests.Product.When_updating_a_product::should_update_a_product" /><Add Test="ShopifySharp.Tests.Product.When_getting_a_list_of_products::should_retrieve_a_list_of_products" /><Add Test="ShopifySharp.Tests.Product.When_creating_a_product::should_create_a_product" /><Add Test="ShopifySharp.Tests.Product.When_creating_a_product::should_create_a_product_with_a_title" /><Add Test="ShopifySharp.Tests.Product.When_counting_products::should_retrieve_a_count_of_products" /><Add Test="ShopifySharp.Tests.Product.When_creating_a_product::should_create_a_product_with_an_id" /><Add Test="ShopifySharp.Tests.Product.When_getting_one_product::should_retrieve_a_product" /><Add Test="ShopifySharp.Tests.Product.When_counting_products::should_count_products" /><Add Test="ShopifySharp.Tests.Product.When_getting_a_list_of_products::should_list_products" /><Add Test="ShopifySharp.Tests.Product.When_getting_a_list_of_filtered_products::should_list_products_with_specific_ids" /></Playlist>
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Machine.Specifications;
using ShopifySharp.Tests.Test_Data;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -14,37 +15,44 @@ public class When_listing_orders_with_options
{
Service = new ShopifyOrderService(Utils.MyShopifyUrl, Utils.AccessToken);

// TODO: Create three orders
for(int i = 0; i < 3; i++)
for (int i = 0; i < 3; i++)
{
var order = Service.CreateAsync(OrderCreation.CreateValidOrder()).Await().AsTask.Result;

CreatedIds.Add(order.Id.Value);
}

Options = new ShopifyOrderFilterOptions()
{
Ids = CreatedIds
};
};

Because of = () =>
{
Result = Service.ListAsync(Options).Await().AsTask.Result;
};

It should_only_list_2_orders = () =>
It should_list_orders_with_specific_ids = () =>
{
Result.ShouldNotBeNull();
Result.Count().Equals(2).ShouldBeTrue();
Result.All(order => CreatedIds.Contains(order.Id.Value));
Result.Count().ShouldEqual(CreatedIds.Count);
};

Cleanup after = () =>
{
// TODO: Delete orders
foreach (var id in CreatedIds)
{
Service.DeleteAsync(id).Await();
}
};

static ShopifyOrderService Service;

static IEnumerable<ShopifyOrder> Result;

static ShopifyOrderFilterOptions Options = new ShopifyOrderFilterOptions()
{
Limit = 2
};
static ShopifyOrderFilterOptions Options;

static List<long> CreatedIds = new List<long>();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using Machine.Specifications;
using ShopifySharp.Tests.Test_Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ShopifySharp.Tests.Product
{
[Subject(typeof(ShopifyProductService))]
public class When_getting_a_list_of_filtered_products
{
Establish context = () =>
{
Service = new ShopifyProductService(Utils.MyShopifyUrl, Utils.AccessToken);

for (var i = 0; i < 3; i++)
{
var product = Service.CreateAsync(ProductCreation.CreateValidProducts(), new ShopifyProductCreateOptions()
{
Published = false
}).Await().AsTask.Result;

ProductIds.Add(product.Id.Value);
}
};

Because of = () =>
{
Products = Service.ListAsync(new ShopifyProductFilterOptions() { Ids = ProductIds }).Await().AsTask.Result;
};

It should_list_products_with_specific_ids = () =>
{
Products.Count().ShouldEqual(ProductIds.Count);
Products.All(p => ProductIds.Contains(p.Id.Value)).ShouldBeTrue();
};

Cleanup after = () =>
{
foreach (var id in ProductIds)
{
Service.DeleteAsync(id).Await();
}
};

static ShopifyProductService Service;

static List<long> ProductIds = new List<long>();

static IEnumerable<ShopifyProduct> Products;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,38 @@ public class When_getting_a_list_of_products
{
Service = new ShopifyProductService(Utils.MyShopifyUrl, Utils.AccessToken);

ProductId = Service.CreateAsync(ProductCreation.CreateValidProducts(), new ShopifyProductCreateOptions() { Published = false }).Await().AsTask.Result.Id.Value;
for (var i = 0; i < 3; i++)
{
var product = Service.CreateAsync(ProductCreation.CreateValidProducts(), new ShopifyProductCreateOptions()
{
Published = false
}).Await().AsTask.Result;

ProductIds.Add(product.Id.Value);
}
};

Because of = () =>
{
Products = Service.ListAsync(new ShopifyProductFilterOptions() { Ids = new[] { ProductId } }).Await().AsTask.Result;
Products = Service.ListAsync().Await().AsTask.Result;
};

It should_retrieve_a_list_of_products = () => Products.Count().ShouldBeGreaterThanOrEqualTo(1);

It should_retrieve_a_list_of_products_with_the_correct_id = () => Products.Any(p => p.Id == ProductId);
It should_list_products = () =>
{
Products.Count().ShouldBeGreaterThanOrEqualTo(ProductIds.Count);
};

Cleanup after = () =>
{
if (Products != null)
foreach (var id in ProductIds)
{
Service.DeleteAsync(ProductId).Await();
Service.DeleteAsync(id).Await();
}
};

static ShopifyProductService Service;
static long ProductId;

static List<long> ProductIds = new List<long>();

static IEnumerable<ShopifyProduct> Products;
}
Expand Down
1 change: 1 addition & 0 deletions ShopifySharp.Tests/ShopifySharp.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
<Compile Include="ShopifyChargeService Tests\When_retrieving_a_charge.cs" />
<Compile Include="ShopifyProductService Tests\Test_Data\ProductCreation.cs" />
<Compile Include="ShopifyProductService Tests\When_deleting_a_product.cs" />
<Compile Include="ShopifyProductService Tests\When_getting_a_list_of_products - Copy.cs" />
<Compile Include="ShopifyProductService Tests\When_getting_a_list_of_products.cs" />
<Compile Include="ShopifyProductService Tests\When_counting_products.cs" />
<Compile Include="ShopifyProductService Tests\When_updating_a_product.cs" />
Expand Down
46 changes: 35 additions & 11 deletions ShopifySharp/Infrastructure/Parameterizable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ public IEnumerable<Parameter> ToParameters(ParameterType type)
{
object value = property.GetValue(this, null);
string propName = property.Name;
if (value == null) continue;

if (value == null)
{
continue;
}

if (property.CustomAttributes.Any(x => x.AttributeType == typeof(JsonPropertyAttribute)))
{
Expand All @@ -38,20 +42,40 @@ public IEnumerable<Parameter> ToParameters(ParameterType type)
propName = attribute != null ? attribute.PropertyName : property.Name;
}

if(value.GetType().IsEnum)
{
value = ((Enum)value).ToSerializedString();
}
var parameter = ToSingleParameter(propName, value, property, type);

output.Add(new Parameter()
{
Name = propName,
Value = value,
Type = type
});
output.Add(parameter);
}

return output;
}

/// <summary>
/// Converts the given property and value to a parameter. Can be overriden to customize parameterization of a property.
/// Will NOT be called by the <see cref="Parameterizable.ToParameters(ParameterType)"/> method if the value
/// is null.
/// </summary>
/// <param name="propName">The name of the property. Will match the property's <see cref="JsonPropertyAttribute"/> name —
/// rather than the real property name — where applicable. Use <paramref name="property"/>.Name to get the real name.</param>
/// <param name="value">The property's value.</param>
/// <param name="property">The property itself.</param>
/// <param name="type">The type of parameter to create.</param>
/// <returns>The new parameter.</returns>
public virtual Parameter ToSingleParameter(string propName, object value, PropertyInfo property, ParameterType type)
{
Type valueType = value.GetType();

if (valueType.IsEnum)
{
value = ((Enum)value).ToSerializedString();
}

return new Parameter()
{
Name = propName,
Value = value,
Type = type
};
}
}
}
2 changes: 1 addition & 1 deletion ShopifySharp/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// 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("1.11.1.0")]
[assembly: AssemblyVersion("1.11.2.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
30 changes: 30 additions & 0 deletions ShopifySharp/Services/Order/ShopifyOrderFilterOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RestSharp;
using System.Reflection;

namespace ShopifySharp
{
Expand All @@ -13,6 +15,7 @@ public class ShopifyOrderFilterOptions : ShopifyFilterOptions
/// <summary>
/// An optional array of order ids to retrieve.
/// </summary>
[JsonProperty("ids")]
public IEnumerable<long> Ids { get; set; }

/// <summary>
Expand All @@ -32,5 +35,32 @@ public class ShopifyOrderFilterOptions : ShopifyFilterOptions
/// </summary>
[JsonProperty("fulfillment_status")]
public ShopifyFulfillmentStatus? FulfillmentStatus { get; set; }

/// <summary>
/// Parameterizes this <see cref="ShopifyOrderFilterOptions"/> class, with special handling for <see cref="Ids"/>.
/// </summary>
/// <param name="propName">The name of the property. Will match the property's <see cref="JsonPropertyAttribute"/> name —
/// rather than the real property name — where applicable. Use <paramref name="property"/>.Name to get the real name.</param>
/// <param name="value">The property's value.</param>
/// <param name="property">The property itself.</param>
/// <param name="type">The type of parameter to create.</param>
/// <returns>The new parameter.</returns>
public override Parameter ToSingleParameter(string propName, object value, PropertyInfo property, ParameterType type)
{
if (propName == "ids" || propName == "Ids")
{
//RestSharp does not automatically convert arrays into querystring params.
var param = new Parameter()
{
Name = propName,
Type = type,
Value = string.Join(",", value as IEnumerable<long> )
};

return param;
}

return base.ToSingleParameter(propName, value, property, type);
}
}
}
30 changes: 30 additions & 0 deletions ShopifySharp/Services/Product/ShopifyProductFilterOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RestSharp;
using System.Reflection;

namespace ShopifySharp
{
Expand All @@ -13,6 +15,7 @@ public class ShopifyProductFilterOptions : ShopifyFilterOptions
/// <summary>
/// An optional array of order ids to retrieve.
/// </summary>
[JsonProperty("ids")]
public IEnumerable<long> Ids { get; set; }

/// <summary>
Expand Down Expand Up @@ -93,5 +96,32 @@ public class ShopifyProductFilterOptions : ShopifyFilterOptions
/// </summary>
[JsonProperty("published_status")]
public string PublishedStatus { get; set; } = null;

/// <summary>
/// Parameterizes this <see cref="ShopifyOrderFilterOptions"/> class, with special handling for <see cref="Ids"/>.
/// </summary>
/// <param name="propName">The name of the property. Will match the property's <see cref="JsonPropertyAttribute"/> name —
/// rather than the real property name — where applicable. Use <paramref name="property"/>.Name to get the real name.</param>
/// <param name="value">The property's value.</param>
/// <param name="property">The property itself.</param>
/// <param name="type">The type of parameter to create.</param>
/// <returns>The new parameter.</returns>
public override Parameter ToSingleParameter(string propName, object value, PropertyInfo property, ParameterType type)
{
if (propName == "ids" || propName == "Ids")
{
//RestSharp does not automatically convert arrays into querystring params.
var param = new Parameter()
{
Name = propName,
Type = type,
Value = string.Join(",", value as IEnumerable<long>)
};

return param;
}

return base.ToSingleParameter(propName, value, property, type);
}
}
}
5 changes: 5 additions & 0 deletions ShopifySharp/ShopifySharp.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>ShopifySharp is a .NET library that enables you to authenticate and make API calls to Shopify.</description>
<releaseNotes>
1.11.2
======
- Fixed a bug ShopifyOrderService.ListAsync and ShopifyProductService.ListAsync where filtering the results to specific ids was broken.
- https://github.com/nozzlegear/shopifysharp/issues/17

1.11.1
======
- Validate proxy page requests with ShopifyAuthorizationService.IsAuthenticProxyRequest.
Expand Down

0 comments on commit 10b2baa

Please sign in to comment.