-
-
Notifications
You must be signed in to change notification settings - Fork 298
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from nozzlegear/master
Merging nozzlegear/master
- Loading branch information
Showing
8 changed files
with
293 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace ShopifySharp.Tests | ||
{ | ||
using System.Diagnostics; | ||
using System.Globalization; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Threading.Tasks; | ||
|
||
using Newtonsoft.Json; | ||
|
||
using Xunit; | ||
|
||
public class DateTime_Tests : IClassFixture<Order_Tests_Fixture> | ||
{ | ||
public DateTime_Tests(Order_Tests_Fixture orderTestsFixture) | ||
{ | ||
this.OrderTestsFixture = orderTestsFixture; | ||
} | ||
|
||
public Order_Tests_Fixture OrderTestsFixture { get; } | ||
|
||
[Fact] | ||
public async Task GraphQL_CompareOrderDates() | ||
{ | ||
var orderId = this.OrderTestsFixture.Created.First().Id.Value; | ||
|
||
var order = await this.OrderTestsFixture.Service.GetAsync(orderId); | ||
Assert.NotNull(order.UpdatedAt); | ||
|
||
// Shopify seems to take approx. 10 seconds to propagate new orders into the GraphQL API | ||
await Task.Delay(TimeSpan.FromSeconds(11)); | ||
|
||
var graphService = new GraphService(Utils.MyShopifyUrl, Utils.AccessToken); | ||
var graphQlOrder = await graphService.PostAsync( | ||
@" | ||
{ | ||
orders(first:1,query:""id:" + orderId + @""") { | ||
edges{ | ||
node{ | ||
updatedAt | ||
} | ||
} | ||
} | ||
} | ||
"); | ||
|
||
var jtokenOrder = graphQlOrder["orders"]["edges"].First["node"]; | ||
|
||
var testOrder = jtokenOrder.ToObject<TestGraphQLOrderWithString>(); | ||
var testOrderDateTime = DateTimeOffset.Parse(testOrder.UpdatedAt, CultureInfo.InvariantCulture); | ||
Assert.Equal(order.UpdatedAt.Value, testOrderDateTime); | ||
|
||
var testOrderWithDateTimeOffset = jtokenOrder.ToObject<TestGraphQLOrderWithDateTimeOffset>(); | ||
Assert.Equal(order.UpdatedAt.Value, testOrderWithDateTimeOffset.UpdatedAt); | ||
|
||
var testOrderWithDateTime = jtokenOrder.ToObject<TestGraphQLOrderWithDateTime>(); | ||
Assert.Equal(order.UpdatedAt.Value, testOrderWithDateTime.UpdatedAt); | ||
} | ||
|
||
public class TestGraphQLOrderWithString | ||
{ | ||
public string UpdatedAt { get; set; } | ||
} | ||
|
||
public class TestGraphQLOrderWithDateTime | ||
{ | ||
public DateTime UpdatedAt { get; set; } | ||
} | ||
|
||
public class TestGraphQLOrderWithDateTimeOffset | ||
{ | ||
public DateTimeOffset UpdatedAt { get; set; } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
namespace ShopifySharp | ||
{ | ||
public static class StringExtensions | ||
{ | ||
/// <summary> | ||
/// Checks if a string starts with another string, ignoring case. | ||
/// </summary> | ||
public static bool StartsWithIgnoreCase(this string str, string a) => str.ToLower().StartsWith(a.ToLower()); | ||
|
||
/// <summary> | ||
/// Checks if a string ends with another string, ignoring case. | ||
/// </summary> | ||
public static bool EndsWithIgnoreCase(this string str, string a) => str.ToLower().EndsWith(a.ToLower()); | ||
|
||
/// <summary> | ||
/// Checks if a string contains another string, ignorning case. | ||
/// </summary> | ||
public static bool ContainsIgnoreCase(this string str, string a) => str.ToLower().Contains(a.ToLower()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,99 @@ | ||
using Newtonsoft.Json; | ||
using System; | ||
using System.Collections.Generic; | ||
using Newtonsoft.Json; | ||
|
||
namespace ShopifySharp.Filters | ||
{ | ||
/// <summary> | ||
/// Options for filtering the results of <see cref="ArticleService.ListAsync(long, ArticleFilter)"/>. | ||
/// </summary> | ||
public class ArticleFilter : PublishableListFilter | ||
public class ArticleFilter : Parameterizable | ||
{ | ||
/// <summary> | ||
/// Filter the results to this article handle. | ||
/// </summary> | ||
[JsonProperty("handle")] | ||
public string Handle { get; set; } | ||
|
||
/// <summary> | ||
/// Restricts results to those created after date (format: 2008-12-31 03:00). | ||
/// </summary> | ||
[JsonProperty("created_at_min")] | ||
public DateTimeOffset? CreatedAtMin { get; set; } | ||
|
||
/// <summary> | ||
/// Restricts results to those created before date (format: 2008-12-31 03:00). | ||
/// </summary> | ||
[JsonProperty("created_at_max")] | ||
public DateTimeOffset? CreatedAtMax { get; set; } | ||
|
||
/// <summary> | ||
/// Restricts results to those last updated after date (format: 2008-12-31 03:00). | ||
/// </summary> | ||
[JsonProperty("updated_at_min")] | ||
public DateTimeOffset? UpdatedAtMin { get; set; } | ||
|
||
/// <summary> | ||
/// Restricts results to those last updated before date (format: 2008-12-31 03:00). | ||
/// </summary> | ||
[JsonProperty("updated_at_max")] | ||
public DateTimeOffset? UpdatedAtMax { get; set; } | ||
|
||
/// <summary> | ||
/// Restrict results to after the specified ID. Note: this field may not have an effect on certain resources. | ||
/// </summary> | ||
[JsonProperty("since_id")] | ||
public long? SinceId { get; set; } | ||
|
||
/// <summary> | ||
/// An optional array of order ids to retrieve. | ||
/// </summary> | ||
[JsonProperty("ids"), Obsolete("The Ids property is ignored for articles. Using this property to list or count articles is a noop, and the property will be removed in the future.", false)] | ||
public IEnumerable<long> Ids { get; set; } | ||
|
||
/// <summary> | ||
/// Limit the amount of results. Default is 50, max is 250. | ||
/// </summary> | ||
[JsonProperty("limit")] | ||
public int? Limit { get; set; } | ||
|
||
/// <summary> | ||
/// Page of results to be returned. Default is 1. | ||
/// </summary> | ||
[JsonProperty("page")] | ||
public int? Page { get; set; } | ||
|
||
/// <summary> | ||
/// An optional, comma-separated list of fields to include in the response. | ||
/// </summary> | ||
[JsonProperty("fields")] | ||
public string Fields { get; set; } | ||
|
||
/// <summary> | ||
/// An optional field name to order by, followed by either ' asc' or ' desc'. | ||
/// For example, 'created_at asc' | ||
/// Not all fields are supported... | ||
/// </summary> | ||
[JsonProperty("order")] | ||
public string Order { get; set; } | ||
|
||
/// <summary> | ||
/// Show objects published after date (format: 2008-12-31 03:00). | ||
/// </summary> | ||
[JsonProperty("published_at_min")] | ||
public DateTimeOffset? PublishedAtMin { get; set; } = null; | ||
|
||
/// <summary> | ||
/// Show objects published before date (format: 2008-12-31 03:00). | ||
/// </summary> | ||
[JsonProperty("published_at_max")] | ||
public DateTimeOffset? PublishedAtMax { get; set; } = null; | ||
|
||
/// <summary> | ||
/// Published Status. | ||
/// published - Show only published objects, unpublished - Show only unpublished objects, any - Show all objects(default) | ||
/// </summary> | ||
[JsonProperty("published_status")] | ||
public string PublishedStatus { get; set; } = null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using Newtonsoft.Json; | ||
|
||
namespace ShopifySharp.Infrastructure | ||
{ | ||
/// <summary> | ||
/// Contains JSON serialization settings and methods used by the rest of the ShopifySharp package. | ||
/// </summary> | ||
public static class Serializer | ||
{ | ||
public static JsonSerializerSettings Settings { get; } = new JsonSerializerSettings() | ||
{ | ||
NullValueHandling = NullValueHandling.Ignore | ||
}; | ||
|
||
public static JsonSerializer JsonSerializer { get; } = new JsonSerializer | ||
{ | ||
DateParseHandling = DateParseHandling.DateTimeOffset | ||
}; | ||
|
||
public static string Serialize(object data) => JsonConvert.SerializeObject(data, Settings); | ||
|
||
public static T Deserialize<T>(string json) => JsonConvert.DeserializeObject<T>(json, Settings); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.