-
-
Notifications
You must be signed in to change notification settings - Fork 312
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 #8 from nozzlegear/ShopifyScriptTagService
ShopifyScriptTagService: Create, get, list, count, update and delete script tags.
- Loading branch information
Showing
15 changed files
with
602 additions
and
2 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
ShopifySharp.Tests/ShopifyScriptTagService Tests/When_counting_script_tags.cs
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,60 @@ | ||
using Machine.Specifications; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace ShopifySharp.Tests.ShopifyScriptTagService_Tests | ||
{ | ||
[Subject(typeof(ShopifyScriptTagService))] | ||
class When_counting_script_tags | ||
{ | ||
Establish context = () => | ||
{ | ||
Service = new ShopifyScriptTagService(Utils.MyShopifyUrl, Utils.AccessToken); | ||
FilteredSrc = string.Format("https://nozzlegear.com/{0}/even.js", Guid.NewGuid().ToString()); | ||
for (int i = 0; i < 5; i++) | ||
{ | ||
string src = i % 2 == 0 ? FilteredSrc : "https://nozzlegear.com/odd.js"; | ||
Tags.Add(Service.CreateAsync(new ShopifyScriptTag() | ||
{ | ||
Event = Enums.ShopifyScriptTagEvent.Onload, | ||
Src = src | ||
}).Await().AsTask.Result); | ||
} | ||
}; | ||
|
||
Because of = () => | ||
{ | ||
Count = Service.CountAsync().Await().AsTask.Result; | ||
FilteredCount = Service.CountAsync(FilteredSrc).Await().AsTask.Result; | ||
}; | ||
|
||
It should_count_script_tags = () => | ||
{ | ||
Count.ShouldBeGreaterThanOrEqualTo(3); | ||
FilteredCount.ShouldEqual(3); | ||
}; | ||
|
||
Cleanup after = () => | ||
{ | ||
foreach (var tag in Tags) | ||
{ | ||
Service.DeleteAsync(tag.Id.Value).Await(); | ||
} | ||
}; | ||
|
||
static string FilteredSrc; | ||
|
||
static int Count; | ||
|
||
static int FilteredCount; | ||
|
||
static ShopifyScriptTagService Service; | ||
|
||
static List<ShopifyScriptTag> Tags = new List<ShopifyScriptTag>(); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
ShopifySharp.Tests/ShopifyScriptTagService Tests/When_creating_a_script_tag.cs
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,42 @@ | ||
using Machine.Specifications; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace ShopifySharp.Tests.ShopifyScriptTagService_Tests | ||
{ | ||
[Subject(typeof(ShopifyScriptTagService))] | ||
class When_creating_a_script_tag | ||
{ | ||
Establish context = () => | ||
{ | ||
Service = new ShopifyScriptTagService(Utils.MyShopifyUrl, Utils.AccessToken); | ||
}; | ||
|
||
Because of = () => | ||
{ | ||
Tag = Service.CreateAsync(new ShopifyScriptTag() | ||
{ | ||
Event = Enums.ShopifyScriptTagEvent.Onload, | ||
Src = "https://nozzlegear.com/test.js" | ||
}).Await().AsTask.Result; | ||
}; | ||
|
||
It should_create_a_script_tag = () => | ||
{ | ||
Tag.ShouldNotBeNull(); | ||
Tag.Src.ShouldEqual("https://nozzlegear.com/test.js"); | ||
}; | ||
|
||
Cleanup after = () => | ||
{ | ||
Service.DeleteAsync(Tag.Id.Value).Await(); | ||
}; | ||
|
||
static ShopifyScriptTagService Service; | ||
|
||
static ShopifyScriptTag Tag; | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
ShopifySharp.Tests/ShopifyScriptTagService Tests/When_deleting_a_script_tag.cs
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,51 @@ | ||
using Machine.Specifications; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace ShopifySharp.Tests.ShopifyScriptTagService_Tests | ||
{ | ||
[Subject(typeof(ShopifyScriptTagService))] | ||
class When_deleting_a_script_tag | ||
{ | ||
Establish context = () => | ||
{ | ||
Service = new ShopifyScriptTagService(Utils.MyShopifyUrl, Utils.AccessToken); | ||
Tag = Service.CreateAsync(new ShopifyScriptTag() | ||
{ | ||
Event = Enums.ShopifyScriptTagEvent.Onload, | ||
Src = "https://nozzlegear.com/test.js" | ||
}).Await().AsTask.Result; | ||
}; | ||
|
||
Because of = () => | ||
{ | ||
try | ||
{ | ||
Service.DeleteAsync(Tag.Id.Value).Await(); | ||
} | ||
catch(Exception e) | ||
{ | ||
Ex = e; | ||
} | ||
}; | ||
|
||
It should_delete_a_script_tag = () => | ||
{ | ||
Ex.ShouldBeNull(); | ||
}; | ||
|
||
Cleanup after = () => | ||
{ | ||
}; | ||
|
||
static ShopifyScriptTagService Service; | ||
|
||
static ShopifyScriptTag Tag; | ||
|
||
static Exception Ex; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
ShopifySharp.Tests/ShopifyScriptTagService Tests/When_getting_a_script_tag.cs
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,45 @@ | ||
using Machine.Specifications; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace ShopifySharp.Tests.ShopifyScriptTagService_Tests | ||
{ | ||
[Subject(typeof(ShopifyScriptTagService))] | ||
class When_getting_a_script_tag | ||
{ | ||
Establish context = () => | ||
{ | ||
Service = new ShopifyScriptTagService(Utils.MyShopifyUrl, Utils.AccessToken); | ||
TagId = Service.CreateAsync(new ShopifyScriptTag() | ||
{ | ||
Event = Enums.ShopifyScriptTagEvent.Onload, | ||
Src = "https://nozzlegear.com/test.js" | ||
}).Await().AsTask.Result.Id.Value; | ||
}; | ||
|
||
Because of = () => | ||
{ | ||
Tag = Service.GetAsync(TagId).Await().AsTask.Result; | ||
}; | ||
|
||
It should_get_a_script_tag = () => | ||
{ | ||
Tag.ShouldNotBeNull(); | ||
Tag.Id.ShouldEqual(TagId); | ||
}; | ||
|
||
Cleanup after = () => | ||
{ | ||
Service.DeleteAsync(TagId).Await(); | ||
}; | ||
|
||
static ShopifyScriptTagService Service; | ||
|
||
static ShopifyScriptTag Tag; | ||
|
||
static long TagId; | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
ShopifySharp.Tests/ShopifyScriptTagService Tests/When_listing_script_tags.cs
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,59 @@ | ||
using Machine.Specifications; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace ShopifySharp.Tests.ShopifyScriptTagService_Tests | ||
{ | ||
[Subject(typeof(ShopifyScriptTagService))] | ||
class When_listing_script_tags | ||
{ | ||
Establish context = () => | ||
{ | ||
Service = new ShopifyScriptTagService(Utils.MyShopifyUrl, Utils.AccessToken); | ||
for (int i = 0; i < 5; i++) | ||
{ | ||
string src = i % 2 == 0 ? FilteredSrc : "https://nozzlegear.com/odd.js"; | ||
Service.CreateAsync(new ShopifyScriptTag() | ||
{ | ||
Event = Enums.ShopifyScriptTagEvent.Onload, | ||
Src = src | ||
}).Await(); | ||
} | ||
}; | ||
|
||
Because of = () => | ||
{ | ||
Tags = Service.ListAsync().Await().AsTask.Result; | ||
FilteredTags = Service.ListAsync(new ShopifyScriptTagListOptions() { | ||
Src = FilteredSrc | ||
}).Await().AsTask.Result; | ||
}; | ||
|
||
It should_list_script_tags = () => | ||
{ | ||
Tags.Count().ShouldBeGreaterThanOrEqualTo(5); | ||
FilteredTags.All(x => x.Src == FilteredSrc).ShouldBeTrue(); | ||
}; | ||
|
||
Cleanup after = () => | ||
{ | ||
foreach (var tag in Tags) | ||
{ | ||
Service.DeleteAsync(tag.Id.Value).Await(); | ||
} | ||
}; | ||
|
||
static string FilteredSrc = "https://nozzlegear.com/even.js"; | ||
|
||
static ShopifyScriptTagService Service; | ||
|
||
static IEnumerable<ShopifyScriptTag> Tags; | ||
|
||
static IEnumerable<ShopifyScriptTag> FilteredTags; | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
ShopifySharp.Tests/ShopifyScriptTagService Tests/When_updating_a_script_tag.cs
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,47 @@ | ||
using Machine.Specifications; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace ShopifySharp.Tests.ShopifyScriptTagService_Tests | ||
{ | ||
[Subject(typeof(ShopifyScriptTagService))] | ||
class When_updating_a_script_tag | ||
{ | ||
Establish context = () => | ||
{ | ||
Service = new ShopifyScriptTagService(Utils.MyShopifyUrl, Utils.AccessToken); | ||
OriginalTag = Service.CreateAsync(new ShopifyScriptTag() | ||
{ | ||
Event = Enums.ShopifyScriptTagEvent.Onload, | ||
Src = "https://nozzlegear.com/test.js" | ||
}).Await().AsTask.Result; | ||
OriginalTag.Src = "https://nozzlegear.com/updated.js"; | ||
}; | ||
|
||
Because of = () => | ||
{ | ||
UpdatedTag = Service.UpdateAsync(OriginalTag).Await().AsTask.Result; | ||
}; | ||
|
||
It should_update_a_script_tag = () => | ||
{ | ||
UpdatedTag.ShouldNotBeNull(); | ||
UpdatedTag.Src.ShouldEqual("https://nozzlegear.com/updated.js"); | ||
}; | ||
|
||
Cleanup after = () => | ||
{ | ||
Service.DeleteAsync(OriginalTag.Id.Value).Await(); | ||
}; | ||
|
||
static ShopifyScriptTagService Service; | ||
|
||
static ShopifyScriptTag OriginalTag; | ||
|
||
static ShopifyScriptTag UpdatedTag; | ||
} | ||
} |
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,41 @@ | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Converters; | ||
using ShopifySharp.Enums; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace ShopifySharp | ||
{ | ||
/// <summary> | ||
/// An object representing remote javascript tags that are loaded into the pages of a shop's storefront. | ||
/// </summary> | ||
public class ShopifyScriptTag: ShopifyObject | ||
{ | ||
/// <summary> | ||
/// The date and time when the <see cref="ShopifyScriptTag"/> was created. | ||
/// </summary> | ||
[JsonProperty("created_at")] | ||
public DateTime CreatedAt { get; set; } | ||
|
||
/// <summary> | ||
/// DOM event which triggers the loading of the script. Valid values are: <see cref="ShopifyScriptTagEvent.Onload"/>. | ||
/// </summary> | ||
[JsonProperty("event"), JsonConverter(typeof(StringEnumConverter))] | ||
public ShopifyScriptTagEvent Event { get; set; } | ||
|
||
/// <summary> | ||
/// Specifies the location of the ScriptTag. | ||
/// </summary> | ||
[JsonProperty("src")] | ||
public string Src { get; set; } | ||
|
||
/// <summary> | ||
/// The date and time when the <see cref="ShopifyScriptTag"/> was updated. | ||
/// </summary> | ||
[JsonProperty("updated_at")] | ||
public DateTime UpdatedAt { get; set; } | ||
} | ||
} |
Oops, something went wrong.