-
-
Notifications
You must be signed in to change notification settings - Fork 313
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 #16 from nozzlegear/ShopifyRedirectService
ShopifyRedirectService: Create, retrieve, count, list, update and delete a store's redirects.
- Loading branch information
Showing
17 changed files
with
701 additions
and
2 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 @@ | ||
<Playlist Version="1.0"><Add Test="ShopifySharp.Tests.ShopifyRedirectService_Tests.When_deleting_a_redirect::should_delete_a_redirect" /><Add Test="ShopifySharp.Tests.ShopifyRedirectService_Tests.When_listing_redirects::should_list_redirects" /><Add Test="ShopifySharp.Tests.ShopifyRedirectService_Tests.When_counting_redirects_with_a_filter::should_count_redirects_with_a_filter" /><Add Test="ShopifySharp.Tests.ShopifyRedirectService_Tests.When_counting_redirects::should_count_redirects" /><Add Test="ShopifySharp.Tests.ShopifyRedirectService_Tests.When_getting_a_redirect::should_get_a_redirect" /><Add Test="ShopifySharp.Tests.ShopifyRedirectService_Tests.When_listing_redirects_with_a_filter::should_list_redirects_with_a_filter" /><Add Test="ShopifySharp.Tests.ShopifyRedirectService_Tests.When_creating_a_redirect::should_create_a_redirect" /><Add Test="ShopifySharp.Tests.ShopifyRedirectService_Tests.When_updating_a_redirect::should_create_a_redirect" /></Playlist> |
53 changes: 53 additions & 0 deletions
53
ShopifySharp.Tests/ShopifyRedirectService Tests/When_counting_redirects.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,53 @@ | ||
using Machine.Specifications; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace ShopifySharp.Tests.ShopifyRedirectService_Tests | ||
{ | ||
[Subject(typeof(ShopifyRedirectService))] | ||
class When_counting_redirects | ||
{ | ||
Establish context = () => | ||
{ | ||
Service = new ShopifyRedirectService(Utils.MyShopifyUrl, Utils.AccessToken); | ||
for (int i = 0; i < 2; i++) | ||
{ | ||
var redirect = Service.CreateAsync(new ShopifyRedirect() | ||
{ | ||
Path = Guid.NewGuid().ToString(), | ||
Target = "https://example.com" | ||
}).Await().AsTask.Result; | ||
Created.Add(redirect); | ||
} | ||
}; | ||
|
||
Because of = () => | ||
{ | ||
Result = Service.CountAsync().Await().AsTask.Result; | ||
}; | ||
|
||
It should_count_redirects = () => | ||
{ | ||
Result.ShouldBeGreaterThanOrEqualTo(2); | ||
}; | ||
|
||
Cleanup after = () => | ||
{ | ||
foreach (var redirect in Created) | ||
{ | ||
Service.DeleteAsync(redirect.Id.Value).Await(); | ||
} | ||
}; | ||
|
||
static ShopifyRedirectService Service; | ||
|
||
static List<ShopifyRedirect> Created = new List<ShopifyRedirect>(); | ||
|
||
static int Result; | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
ShopifySharp.Tests/ShopifyRedirectService Tests/When_counting_redirects_with_a_filter.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,63 @@ | ||
using Machine.Specifications; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace ShopifySharp.Tests.ShopifyRedirectService_Tests | ||
{ | ||
[Subject(typeof(ShopifyRedirectService))] | ||
class When_counting_redirects_with_a_filter | ||
{ | ||
Establish context = () => | ||
{ | ||
Service = new ShopifyRedirectService(Utils.MyShopifyUrl, Utils.AccessToken); | ||
FilteredTarget = "https://example.com/" + Guid.NewGuid().ToString(); | ||
FilteredPath = Guid.NewGuid().ToString(); | ||
for (int i = 1; i < 5; i++) | ||
{ | ||
var redirect = Service.CreateAsync(new ShopifyRedirect() | ||
{ | ||
Path = i == 3 ? FilteredPath : Guid.NewGuid().ToString(), | ||
Target = i % 2 == 0 ? FilteredTarget : "https://example.com" | ||
}).Await().AsTask.Result; | ||
Created.Add(redirect); | ||
} | ||
}; | ||
|
||
Because of = () => | ||
{ | ||
TargetResult = Service.CountAsync(target: FilteredTarget).Await().AsTask.Result; | ||
PathResult = Service.CountAsync(path: FilteredPath).Await().AsTask.Result; | ||
}; | ||
|
||
It should_count_redirects_with_a_filter = () => | ||
{ | ||
TargetResult.ShouldEqual(2); | ||
PathResult.ShouldEqual(1); | ||
}; | ||
|
||
Cleanup after = () => | ||
{ | ||
foreach (var redirect in Created) | ||
{ | ||
Service.DeleteAsync(redirect.Id.Value).Await(); | ||
} | ||
}; | ||
|
||
static ShopifyRedirectService Service; | ||
|
||
static List<ShopifyRedirect> Created = new List<ShopifyRedirect>(); | ||
|
||
static string FilteredPath; | ||
|
||
static string FilteredTarget; | ||
|
||
static int PathResult; | ||
|
||
static int TargetResult; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
ShopifySharp.Tests/ShopifyRedirectService Tests/When_creating_a_redirect.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.ShopifyRedirectService_Tests | ||
{ | ||
[Subject(typeof(ShopifyRedirectService))] | ||
class When_creating_a_redirect | ||
{ | ||
Establish context = () => | ||
{ | ||
Service = new ShopifyRedirectService(Utils.MyShopifyUrl, Utils.AccessToken); | ||
}; | ||
|
||
Because of = () => | ||
{ | ||
Result = Service.CreateAsync(new ShopifyRedirect() | ||
{ | ||
Path = Guid.NewGuid().ToString(), | ||
Target = "https://example.com" | ||
}).Await().AsTask.Result; | ||
}; | ||
|
||
It should_create_a_redirect = () => | ||
{ | ||
Result.ShouldNotBeNull(); | ||
Result.Target.ShouldEqual("https://example.com/"); | ||
}; | ||
|
||
Cleanup after = () => | ||
{ | ||
Service.DeleteAsync(Result.Id.Value).Await(); | ||
}; | ||
|
||
static ShopifyRedirectService Service; | ||
|
||
static ShopifyRedirect Result; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
ShopifySharp.Tests/ShopifyRedirectService Tests/When_deleting_a_redirect.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,43 @@ | ||
using Machine.Specifications; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace ShopifySharp.Tests.ShopifyRedirectService_Tests | ||
{ | ||
[Subject(typeof(ShopifyRedirectService))] | ||
class When_deleting_a_redirect | ||
{ | ||
Establish context = () => | ||
{ | ||
Service = new ShopifyRedirectService(Utils.MyShopifyUrl, Utils.AccessToken); | ||
Id = Service.CreateAsync(new ShopifyRedirect() | ||
{ | ||
Path = Guid.NewGuid().ToString(), | ||
Target = "https://example.com" | ||
}).Await().AsTask.Result.Id.Value; | ||
}; | ||
|
||
Because of = () => | ||
{ | ||
Service.DeleteAsync(Id).Await(); | ||
}; | ||
|
||
It should_delete_a_redirect = () => | ||
{ | ||
//Passes if no exception was thrown. | ||
}; | ||
|
||
Cleanup after = () => | ||
{ | ||
}; | ||
|
||
static ShopifyRedirectService Service; | ||
|
||
static long Id; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
ShopifySharp.Tests/ShopifyRedirectService Tests/When_getting_a_redirect.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.ShopifyRedirectService_Tests | ||
{ | ||
[Subject(typeof(ShopifyRedirectService))] | ||
class When_getting_a_redirect | ||
{ | ||
Establish context = () => | ||
{ | ||
Service = new ShopifyRedirectService(Utils.MyShopifyUrl, Utils.AccessToken); | ||
Id = Service.CreateAsync(new ShopifyRedirect() | ||
{ | ||
Path = Guid.NewGuid().ToString(), | ||
Target = "https://example.com" | ||
}).Await().AsTask.Result.Id.Value; | ||
}; | ||
|
||
Because of = () => | ||
{ | ||
Result = Service.GetAsync(Id).Await().AsTask.Result; | ||
}; | ||
|
||
It should_get_a_redirect = () => | ||
{ | ||
Result.ShouldNotBeNull(); | ||
}; | ||
|
||
Cleanup after = () => | ||
{ | ||
Service.DeleteAsync(Id).Await(); | ||
}; | ||
|
||
static ShopifyRedirectService Service; | ||
|
||
static ShopifyRedirect Result; | ||
|
||
static long Id; | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
ShopifySharp.Tests/ShopifyRedirectService Tests/When_listing_redirects.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,54 @@ | ||
using Machine.Specifications; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace ShopifySharp.Tests.ShopifyRedirectService_Tests | ||
{ | ||
[Subject(typeof(ShopifyRedirectService))] | ||
class When_listing_redirects | ||
{ | ||
Establish context = () => | ||
{ | ||
Service = new ShopifyRedirectService(Utils.MyShopifyUrl, Utils.AccessToken); | ||
for (int i = 0; i < 2; i++) | ||
{ | ||
var redirect = Service.CreateAsync(new ShopifyRedirect() | ||
{ | ||
Path = Guid.NewGuid().ToString(), | ||
Target = "https://example.com" | ||
}).Await().AsTask.Result; | ||
Created.Add(redirect); | ||
} | ||
}; | ||
|
||
Because of = () => | ||
{ | ||
Result = Service.ListAsync().Await().AsTask.Result; | ||
}; | ||
|
||
It should_list_redirects = () => | ||
{ | ||
Result.ShouldNotBeNull(); | ||
Result.Count().ShouldBeGreaterThanOrEqualTo(2); | ||
}; | ||
|
||
Cleanup after = () => | ||
{ | ||
foreach (var redirect in Created) | ||
{ | ||
Service.DeleteAsync(redirect.Id.Value).Await(); | ||
} | ||
}; | ||
|
||
static ShopifyRedirectService Service; | ||
|
||
static List<ShopifyRedirect> Created = new List<ShopifyRedirect>(); | ||
|
||
static IEnumerable<ShopifyRedirect> Result; | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
ShopifySharp.Tests/ShopifyRedirectService Tests/When_listing_redirects_with_a_filter.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,73 @@ | ||
using Machine.Specifications; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace ShopifySharp.Tests.ShopifyRedirectService_Tests | ||
{ | ||
[Subject(typeof(ShopifyRedirectService))] | ||
class When_listing_redirects_with_a_filter | ||
{ | ||
Establish context = () => | ||
{ | ||
Service = new ShopifyRedirectService(Utils.MyShopifyUrl, Utils.AccessToken); | ||
FilteredTarget = "https://example.com/" + Guid.NewGuid().ToString(); | ||
FilteredPath = Guid.NewGuid().ToString(); | ||
for (int i = 1; i < 5; i++) | ||
{ | ||
var redirect = Service.CreateAsync(new ShopifyRedirect() | ||
{ | ||
Path = i == 3 ? FilteredPath : Guid.NewGuid().ToString(), | ||
Target = i % 2 == 0 ? FilteredTarget : "https://example.com" | ||
}).Await().AsTask.Result; | ||
Created.Add(redirect); | ||
} | ||
}; | ||
|
||
Because of = () => | ||
{ | ||
TargetResult = Service.ListAsync(new ShopifyRedirectFilterOptions() | ||
{ | ||
Target = FilteredTarget | ||
}).Await().AsTask.Result; | ||
PathResult = Service.ListAsync(new ShopifyRedirectFilterOptions() | ||
{ | ||
Path = FilteredPath | ||
}).Await().AsTask.Result; | ||
}; | ||
|
||
It should_list_redirects_with_a_filter = () => | ||
{ | ||
TargetResult.ShouldNotBeNull(); | ||
PathResult.ShouldNotBeNull(); | ||
TargetResult.Count().ShouldEqual(2); | ||
PathResult.Count().ShouldEqual(1); | ||
}; | ||
|
||
Cleanup after = () => | ||
{ | ||
foreach (var redirect in Created) | ||
{ | ||
Service.DeleteAsync(redirect.Id.Value).Await(); | ||
} | ||
}; | ||
|
||
static ShopifyRedirectService Service; | ||
|
||
static List<ShopifyRedirect> Created = new List<ShopifyRedirect>(); | ||
|
||
static string FilteredPath; | ||
|
||
static string FilteredTarget; | ||
|
||
static IEnumerable<ShopifyRedirect> PathResult; | ||
|
||
static IEnumerable<ShopifyRedirect> TargetResult; | ||
} | ||
} |
Oops, something went wrong.