-
-
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.
Tests, bug fix and Readme update for #20 ShopifyCollectService.
- Loading branch information
Joshua Harms
committed
Dec 25, 2015
1 parent
0067198
commit 4d274c0
Showing
14 changed files
with
462 additions
and
8 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.ShopifyCollectService_Tests.When_listing_collects::should_list_collects" /><Add Test="ShopifySharp.Tests.ShopifyCollectService_Tests.When_counting_collects::should_count_collects" /><Add Test="ShopifySharp.Tests.ShopifyCollectService_Tests.When_getting_a_collect::should_get_a_collect" /><Add Test="ShopifySharp.Tests.ShopifyCollectService_Tests.When_listing_collects_with_a_filter::should_list_collects_with_a_filter" /><Add Test="ShopifySharp.Tests.ShopifyCollectService_Tests.When_deleting_a_collect::should_delete_a_collect" /><Add Test="ShopifySharp.Tests.ShopifyCollectService_Tests.When_creating_a_collect::should_create_a_collect" /></Playlist> |
48 changes: 48 additions & 0 deletions
48
ShopifySharp.Tests/ShopifyCollectService Tests/Test_Data/CollectCreation.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,48 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace ShopifySharp.Tests.ShopifyCollectService_Tests.Test_Data | ||
{ | ||
public class CollectCreation | ||
{ | ||
/// <summary> | ||
/// A manual product collection needed for testing the Collect API. NOTE: This will FAIL on your store, | ||
/// it needs to be replaced with your own collection id. Eventually, this entire var will be | ||
/// deprecated when we get CustomCollection API support. | ||
/// </summary> | ||
public static long CollectionId { get; } = 27369427; | ||
|
||
/// <summary> | ||
/// Creates a new product that can be used to test the Collect API. | ||
/// </summary> | ||
/// <returns>The new product.</returns> | ||
public static async Task<ShopifyProduct> CreateProduct() | ||
{ | ||
var service = new ShopifyProductService(Utils.MyShopifyUrl, Utils.AccessToken); | ||
var product = new ShopifyProduct() | ||
{ | ||
CreatedAt = DateTime.UtcNow, | ||
Title = "Burton Custom Freestlye 151", | ||
Vendor = "Burton", | ||
BodyHtml = "<strong>Good snowboard!</strong>", | ||
ProductType = "Snowboard", | ||
Images = new List<ShopifyProductImage> { new ShopifyProductImage { Attachment = "R0lGODlhAQABAIAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" } }, | ||
}; | ||
|
||
return await service.CreateAsync(product); | ||
} | ||
|
||
/// <summary> | ||
/// Deletes a product that was used to test the Collect API. | ||
/// </summary> | ||
public static async Task DeleteProduct(long id) | ||
{ | ||
var service = new ShopifyProductService(Utils.MyShopifyUrl, Utils.AccessToken); | ||
|
||
await service.DeleteAsync(id); | ||
} | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
ShopifySharp.Tests/ShopifyCollectService Tests/When_counting_collects.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,50 @@ | ||
using Machine.Specifications; | ||
using ShopifySharp.Tests.ShopifyCollectService_Tests.Test_Data; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace ShopifySharp.Tests.ShopifyCollectService_Tests | ||
{ | ||
[Subject(typeof(ShopifyCollectService))] | ||
class When_counting_collects | ||
{ | ||
Establish context = () => | ||
{ | ||
Service = new ShopifyCollectService(Utils.MyShopifyUrl, Utils.AccessToken); | ||
Product = CollectCreation.CreateProduct().Await().AsTask.Result; | ||
Id = Service.CreateAsync(new ShopifyCollect() | ||
{ | ||
CollectionId = CollectCreation.CollectionId, | ||
ProductId = Product.Id.Value | ||
}).Await().AsTask.Result.Id.Value; | ||
}; | ||
|
||
Because of = () => | ||
{ | ||
Count = Service.CountAsync().Await().AsTask.Result; | ||
}; | ||
|
||
It should_count_collects = () => | ||
{ | ||
Count.ShouldBeGreaterThanOrEqualTo(1); | ||
}; | ||
|
||
Cleanup after = () => | ||
{ | ||
Service.DeleteAsync(Id).Await(); | ||
CollectCreation.DeleteProduct(Product.Id.Value).Await(); | ||
}; | ||
|
||
static ShopifyCollectService Service; | ||
|
||
static long Id; | ||
|
||
static int Count; | ||
|
||
static ShopifyProduct Product; | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
ShopifySharp.Tests/ShopifyCollectService Tests/When_creating_a_collect.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 ShopifySharp.Tests.ShopifyCollectService_Tests.Test_Data; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace ShopifySharp.Tests.ShopifyCollectService_Tests | ||
{ | ||
[Subject(typeof(ShopifyCollectService))] | ||
class When_creating_a_collect | ||
{ | ||
Establish context = () => | ||
{ | ||
Service = new ShopifyCollectService(Utils.MyShopifyUrl, Utils.AccessToken); | ||
Product = CollectCreation.CreateProduct().Await().AsTask.Result; | ||
}; | ||
|
||
Because of = () => | ||
{ | ||
Collect = Service.CreateAsync(new ShopifyCollect() | ||
{ | ||
CollectionId = CollectCreation.CollectionId, | ||
ProductId = Product.Id.Value | ||
}).Await().AsTask.Result; | ||
}; | ||
|
||
It should_create_a_collect = () => | ||
{ | ||
Collect.ShouldNotBeNull(); | ||
Collect.Id.Value.ShouldNotBeNull(); | ||
}; | ||
|
||
Cleanup after = () => | ||
{ | ||
Service.DeleteAsync(Collect.Id.Value).Await(); | ||
CollectCreation.DeleteProduct(Product.Id.Value).Await(); | ||
}; | ||
|
||
static ShopifyCollectService Service; | ||
|
||
static ShopifyCollect Collect; | ||
|
||
static ShopifyProduct Product; | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
ShopifySharp.Tests/ShopifyCollectService Tests/When_deleting_a_collect.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 ShopifySharp.Tests.ShopifyCollectService_Tests.Test_Data; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace ShopifySharp.Tests.ShopifyCollectService_Tests | ||
{ | ||
[Subject(typeof(ShopifyCollectService))] | ||
class When_deleting_a_collect | ||
{ | ||
Establish context = () => | ||
{ | ||
Service = new ShopifyCollectService(Utils.MyShopifyUrl, Utils.AccessToken); | ||
Product = CollectCreation.CreateProduct().Await().AsTask.Result; | ||
Id = Service.CreateAsync(new ShopifyCollect() | ||
{ | ||
CollectionId = CollectCreation.CollectionId, | ||
ProductId = Product.Id.Value | ||
}).Await().AsTask.Result.Id.Value; | ||
}; | ||
|
||
Because of = () => | ||
{ | ||
Service.DeleteAsync(Id).Await(); | ||
}; | ||
|
||
It should_delete_a_collect = () => | ||
{ | ||
//Passes if no exception was thrown. | ||
}; | ||
|
||
Cleanup after = () => | ||
{ | ||
CollectCreation.DeleteProduct(Product.Id.Value).Await(); | ||
}; | ||
|
||
static ShopifyCollectService Service; | ||
|
||
static long Id; | ||
|
||
static ShopifyProduct Product; | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
ShopifySharp.Tests/ShopifyCollectService Tests/When_getting_a_collect.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 ShopifySharp.Tests.ShopifyCollectService_Tests.Test_Data; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace ShopifySharp.Tests.ShopifyCollectService_Tests | ||
{ | ||
[Subject(typeof(ShopifyCollectService))] | ||
class When_getting_a_collect | ||
{ | ||
Establish context = () => | ||
{ | ||
Service = new ShopifyCollectService(Utils.MyShopifyUrl, Utils.AccessToken); | ||
Product = CollectCreation.CreateProduct().Await().AsTask.Result; | ||
Id = Service.CreateAsync(new ShopifyCollect() | ||
{ | ||
CollectionId = CollectCreation.CollectionId, | ||
ProductId = Product.Id.Value | ||
}).Await().AsTask.Result.Id.Value; | ||
}; | ||
|
||
Because of = () => | ||
{ | ||
Collect = Service.GetAsync(Id).Await().AsTask.Result; | ||
}; | ||
|
||
It should_get_a_collect = () => | ||
{ | ||
Collect.ShouldNotBeNull(); | ||
Collect.Id.Value.ShouldNotBeNull(); | ||
}; | ||
|
||
Cleanup after = () => | ||
{ | ||
Service.DeleteAsync(Id).Await(); | ||
CollectCreation.DeleteProduct(Product.Id.Value).Await(); | ||
}; | ||
|
||
static ShopifyCollectService Service; | ||
|
||
static ShopifyCollect Collect; | ||
|
||
static long Id; | ||
|
||
static ShopifyProduct Product; | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
ShopifySharp.Tests/ShopifyCollectService Tests/When_listing_collects.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,65 @@ | ||
using Machine.Specifications; | ||
using ShopifySharp.Tests.ShopifyCollectService_Tests.Test_Data; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace ShopifySharp.Tests.ShopifyCollectService_Tests | ||
{ | ||
[Subject(typeof(ShopifyCollectService))] | ||
class When_listing_collects | ||
{ | ||
Establish context = () => | ||
{ | ||
Service = new ShopifyCollectService(Utils.MyShopifyUrl, Utils.AccessToken); | ||
for (var i = 0; i < 3; i++) | ||
{ | ||
var product = CollectCreation.CreateProduct().Await().AsTask.Result; | ||
var collect = Service.CreateAsync(new ShopifyCollect() | ||
{ | ||
CollectionId = CollectCreation.CollectionId, | ||
ProductId = product.Id.Value | ||
}).Await().AsTask.Result; | ||
Products.Add(product); | ||
Created.Add(collect); | ||
} | ||
}; | ||
|
||
Because of = () => | ||
{ | ||
Result = Service.ListAsync().Await().AsTask.Result; | ||
}; | ||
|
||
It should_list_collects = () => | ||
{ | ||
Result.ShouldNotBeNull(); | ||
Result.Count().ShouldBeGreaterThanOrEqualTo(3); | ||
}; | ||
|
||
Cleanup after = () => | ||
{ | ||
foreach (var collect in Created) | ||
{ | ||
Service.DeleteAsync(collect.Id.Value).Await(); | ||
} | ||
foreach (var product in Products) | ||
{ | ||
CollectCreation.DeleteProduct(product.Id.Value).Await(); | ||
} | ||
}; | ||
|
||
static ShopifyCollectService Service; | ||
|
||
static List<ShopifyCollect> Created = new List<ShopifyCollect>(); | ||
|
||
static List<ShopifyProduct> Products = new List<ShopifyProduct>(); | ||
|
||
static IEnumerable<ShopifyCollect> Result; | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
ShopifySharp.Tests/ShopifyCollectService Tests/When_listing_collects_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,65 @@ | ||
using Machine.Specifications; | ||
using ShopifySharp.Tests.ShopifyCollectService_Tests.Test_Data; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace ShopifySharp.Tests.ShopifyCollectService_Tests | ||
{ | ||
[Subject(typeof(ShopifyCollectService))] | ||
class When_listing_collects_with_a_filter | ||
{ | ||
Establish context = () => | ||
{ | ||
Service = new ShopifyCollectService(Utils.MyShopifyUrl, Utils.AccessToken); | ||
for (var i = 0; i <3 ; i++) | ||
{ | ||
var product = CollectCreation.CreateProduct().Await().AsTask.Result; | ||
var collect = Service.CreateAsync(new ShopifyCollect() | ||
{ | ||
CollectionId = CollectCreation.CollectionId, | ||
ProductId = product.Id.Value | ||
}).Await().AsTask.Result; | ||
Products.Add(product); | ||
Created.Add(collect); | ||
} | ||
}; | ||
|
||
Because of = () => | ||
{ | ||
Result = Service.ListAsync(new ShopifyCollectFilterOptions() | ||
{ | ||
ProductId = Products[0].Id.Value | ||
}).Await().AsTask.Result; | ||
}; | ||
|
||
It should_list_collects_with_a_filter = () => | ||
{ | ||
Result.ShouldNotBeNull(); | ||
Result.Count().ShouldBeGreaterThanOrEqualTo(1); | ||
Result.All(c => c.ProductId == Products[0].Id.Value).ShouldBeTrue(); | ||
}; | ||
|
||
Cleanup after = () => | ||
{ | ||
foreach (var collect in Created) | ||
{ | ||
Service.DeleteAsync(collect.Id.Value).Await(); | ||
} | ||
foreach (var product in Products) | ||
{ | ||
CollectCreation.DeleteProduct(product.Id.Value).Await(); | ||
} | ||
}; | ||
|
||
static ShopifyCollectService Service; | ||
|
||
static List<ShopifyCollect> Created = new List<ShopifyCollect>(); | ||
|
||
static List<ShopifyProduct> Products = new List<ShopifyProduct>(); | ||
|
||
static IEnumerable<ShopifyCollect> Result; | ||
} | ||
} |
Oops, something went wrong.