Skip to content

Commit

Permalink
Tests, bug fix and Readme update for #20 ShopifyCollectService.
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Harms committed Dec 25, 2015
1 parent 0067198 commit 4d274c0
Show file tree
Hide file tree
Showing 14 changed files with 462 additions and 8 deletions.
1 change: 1 addition & 0 deletions ShopifySharp.Tests/Playlists/Collects.playlist
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>
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);
}
}
}
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;
}
}
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;
}
}
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;
}
}
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;
}
}
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;
}
}
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;
}
}
Loading

0 comments on commit 4d274c0

Please sign in to comment.