Skip to content

Commit

Permalink
Merge pull request #16 from nozzlegear/ShopifyRedirectService
Browse files Browse the repository at this point in the history
ShopifyRedirectService: Create, retrieve, count, list, update and delete a store's redirects.
  • Loading branch information
nozzlegear committed Nov 12, 2015
2 parents 7314123 + 0668323 commit 5bfb7de
Show file tree
Hide file tree
Showing 17 changed files with 701 additions and 2 deletions.
1 change: 1 addition & 0 deletions ShopifySharp.Tests/Playlists/Redirects.playlist
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>
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;
}
}
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;
}
}
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;
}
}
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;
}
}
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;
}
}
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;
}
}
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;
}
}
Loading

0 comments on commit 5bfb7de

Please sign in to comment.