Skip to content

Commit

Permalink
3.4.0 - ShopifyArticleService
Browse files Browse the repository at this point in the history
  • Loading branch information
nozzlegear committed Nov 15, 2016
1 parent 4a1aab5 commit ac05c89
Show file tree
Hide file tree
Showing 19 changed files with 784 additions and 6 deletions.
1 change: 1 addition & 0 deletions ShopifySharp.Tests/Playlists/Articles.playlist
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<Playlist Version="1.0"><Add Test="ShopifySharp.Tests.ShopifyArticleService_Tests.When_listing_articles::should_list_articles" /><Add Test="ShopifySharp.Tests.ShopifyArticleService_Tests.When_counting_articles::should_count_articles" /><Add Test="ShopifySharp.Tests.ShopifyArticleService_Tests.When_creating_an_article::should_create_an_article" /><Add Test="ShopifySharp.Tests.ShopifyArticleService_Tests.When_updating_an_article::should_update_an_article" /><Add Test="ShopifySharp.Tests.ShopifyArticleService_Tests.When_listing_tags::should_list_tags" /><Add Test="ShopifySharp.Tests.ShopifyArticleService_Tests.When_listing_tags_for_a_blog::should_list_tags_for_a_blog" /><Add Test="ShopifySharp.Tests.ShopifyArticleService_Tests.When_deleting_an_article::should_delete_an_article" /><Add Test="ShopifySharp.Tests.ShopifyArticleService_Tests.When_listing_authors::should_list_authors" /></Playlist>
50 changes: 50 additions & 0 deletions ShopifySharp.Tests/ShopifyArticleService Tests/Utils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System;
using System.Linq;

namespace ShopifySharp.Tests.ShopifyArticleService_Tests
{
static class ArticleUtils
{
public static ShopifyArticleService Service = new ShopifyArticleService(Utils.MyShopifyUrl, Utils.AccessToken);

public static string Title = "My new Article title - ";

public static string Author = "John Smith";

public static string Tags = "This Post, Has Been Tagged";

public static string BodyHtml = "<h1>I like articles</h1>\n<p><strong>Yea</strong>, I like posting them through <span class=\"caps\">REST</span>.</p>";

static long? BlogId;

public static long GetBlogId()
{
if (BlogId.HasValue)
{
return BlogId.Value;
}

var service = new ShopifyBlogService(Utils.MyShopifyUrl, Utils.AccessToken);
var blogs = service.ListAsync().Result;

BlogId = blogs.First().Id;

return BlogId.Value;
}

public static ShopifyArticle CreateArticle()
{
return new ShopifyArticle()
{
Title = Title + Guid.NewGuid(),
Author = Author,
Tags = Tags,
BodyHtml = BodyHtml,
Image = new ShopifyArticleImage()
{
Attachment = "R0lGODlhAQABAIAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==\n"
}
};
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Machine.Specifications;

namespace ShopifySharp.Tests.ShopifyArticleService_Tests
{
[Subject(typeof(ShopifyArticleService))]
class When_counting_articles
{
Establish context = () =>
{
CreatedId = ArticleUtils.Service.CreateAsync(ArticleUtils.GetBlogId(), ArticleUtils.CreateArticle()).Await().AsTask.Result.Id;
};

Because of = () =>
{
Count = ArticleUtils.Service.CountAsync(ArticleUtils.GetBlogId()).Await();
};

It should_count_articles = () =>
{
Count.HasValue.ShouldBeTrue();
Count.Value.ShouldBeGreaterThanOrEqualTo(1);
};

Cleanup after = () =>
{
if (CreatedId.HasValue)
{
ArticleUtils.Service.DeleteAsync(ArticleUtils.GetBlogId(), CreatedId.Value).Await();
}
};

static int? Count;

static long? CreatedId;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Machine.Specifications;

namespace ShopifySharp.Tests.ShopifyArticleService_Tests
{
[Subject(typeof(ShopifyArticleService))]
class When_creating_an_article
{
Establish context = () =>
{
};

Because of = () =>
{
Article = ArticleUtils.Service.CreateAsync(ArticleUtils.GetBlogId(), ArticleUtils.CreateArticle()).Await();
};

It should_create_an_article = () =>
{
Article.Id.HasValue.ShouldBeTrue();
Article.Author.ShouldEqual(ArticleUtils.Author);
Article.BodyHtml.ShouldEqual(ArticleUtils.BodyHtml);
Article.BlogId.ShouldEqual(ArticleUtils.GetBlogId());
Article.Title.ShouldContain(ArticleUtils.Title);
Article.Handle.ShouldNotBeEmpty();
Article.Tags.ShouldNotBeEmpty();
};

Cleanup after = () =>
{
if (Article != null)
{
ArticleUtils.Service.DeleteAsync(ArticleUtils.GetBlogId(), Article.Id.Value).Await();
}
};

static ShopifyArticle Article;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Machine.Specifications;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ShopifySharp.Tests.ShopifyArticleService_Tests
{
[Subject(typeof(ShopifyArticleService))]
class When_deleting_an_article
{
Establish context = () =>
{
Id = ArticleUtils.Service.CreateAsync(ArticleUtils.GetBlogId(), ArticleUtils.CreateArticle()).Await().AsTask.Result.Id.Value;
};

Because of = () =>
{
ex = Catch.Exception(() => ArticleUtils.Service.DeleteAsync(ArticleUtils.GetBlogId(), Id).Await());
};

It should_delete_an_article = () =>
{
ex.ShouldBeNull();
};

Cleanup after = () =>
{
};

static long Id;

static Exception ex;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using Machine.Specifications;
using System.Collections.Generic;
using System.Linq;

namespace ShopifySharp.Tests.ShopifyArticleService_Tests
{
[Subject(typeof(ShopifyArticleService))]
class When_listing_articles
{
Establish context = () =>
{
};

Because of = () =>
{
Articles = ArticleUtils.Service.ListAsync(ArticleUtils.GetBlogId()).Await().AsTask.Result.ToList();
};

It should_list_articles = () =>
{
Articles.ShouldNotBeNull();
Articles.Count().ShouldBeGreaterThanOrEqualTo(0);
};

Cleanup after = () =>
{
};

static IEnumerable<ShopifyArticle> Articles;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Machine.Specifications;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace ShopifySharp.Tests.ShopifyArticleService_Tests
{
[Subject(typeof(ShopifyArticleService))]
class When_listing_authors
{
Establish context = () =>
{
CreatedId = ArticleUtils.Service.CreateAsync(ArticleUtils.GetBlogId(), ArticleUtils.CreateArticle()).Await().AsTask.Result.Id;
};

Because of = () =>
{
Authors = ArticleUtils.Service.ListAuthorsAsync().Await().AsTask.Result;
};

It should_list_authors = () =>
{
Authors.ShouldNotBeNull();
Authors.Any(a => a == ArticleUtils.Author).ShouldBeTrue();
};

Cleanup after = () =>
{
if (CreatedId.HasValue)
{
ArticleUtils.Service.DeleteAsync(ArticleUtils.GetBlogId(), CreatedId.Value).Await();
}
};

static long? CreatedId;

static IEnumerable<string> Authors;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using Machine.Specifications;
using System.Collections.Generic;
using System.Linq;

namespace ShopifySharp.Tests.ShopifyArticleService_Tests
{
[Subject(typeof(ShopifyArticleService))]
class When_listing_tags
{
Establish context = () =>
{
CreatedId = ArticleUtils.Service.CreateAsync(ArticleUtils.GetBlogId(), ArticleUtils.CreateArticle()).Await().AsTask.Result.Id;
};

Because of = () =>
{
Tags = ArticleUtils.Service.ListTagsAsync().Await().AsTask.Result;
};

It should_list_tags = () =>
{
Tags.ShouldNotBeNull();
Tags.Count().ShouldBeGreaterThanOrEqualTo(1);
};

Cleanup after = () =>
{
if (CreatedId.HasValue)
{
ArticleUtils.Service.DeleteAsync(ArticleUtils.GetBlogId(), CreatedId.Value).Await();
}
};

static long? CreatedId;

static IEnumerable<string> Tags;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using Machine.Specifications;
using System.Collections.Generic;
using System.Linq;

namespace ShopifySharp.Tests.ShopifyArticleService_Tests
{
[Subject(typeof(ShopifyArticleService))]
class When_listing_tags_for_a_blog
{
Establish context = () =>
{
CreatedId = ArticleUtils.Service.CreateAsync(ArticleUtils.GetBlogId(), ArticleUtils.CreateArticle()).Await().AsTask.Result.Id;
};

Because of = () =>
{
Tags = ArticleUtils.Service.ListTagsForBlogAsync(ArticleUtils.GetBlogId()).Await().AsTask.Result;
};

It should_list_tags_for_a_blog = () =>
{
Tags.ShouldNotBeNull();
Tags.Count().ShouldBeGreaterThanOrEqualTo(1);
};

Cleanup after = () =>
{
if (CreatedId.HasValue)
{
ArticleUtils.Service.DeleteAsync(ArticleUtils.GetBlogId(), CreatedId.Value).Await();
}
};

static long? CreatedId;

static IEnumerable<string> Tags;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Machine.Specifications;

namespace ShopifySharp.Tests.ShopifyArticleService_Tests
{
[Subject(typeof(ShopifyArticleService))]
class When_updating_an_article
{
Establish context = () =>
{
Article = ArticleUtils.Service.CreateAsync(ArticleUtils.GetBlogId(), ArticleUtils.CreateArticle()).Await();
};

Because of = () =>
{
Article.BodyHtml = Html;
Article = ArticleUtils.Service.UpdateAsync(ArticleUtils.GetBlogId(), Article).Await();
};

It should_update_an_article = () =>
{
Article.Id.HasValue.ShouldBeTrue();
Article.BodyHtml.ShouldEqual(Html);
Article.Author.ShouldEqual(ArticleUtils.Author);
Article.BlogId.ShouldEqual(ArticleUtils.GetBlogId());
Article.Title.ShouldContain(ArticleUtils.Title);
Article.Handle.ShouldNotBeEmpty();
Article.Tags.ShouldNotBeEmpty();
};

Cleanup after = () =>
{
if (Article != null)
{
ArticleUtils.Service.DeleteAsync(ArticleUtils.GetBlogId(), Article.Id.Value).Await();
}
};

static ShopifyArticle Article;

static string Html = "<h1>Updated!</h1>";
}
}
9 changes: 9 additions & 0 deletions ShopifySharp.Tests/ShopifySharp.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@
<Compile Include="ShopifyApplicationCreditService Tests\When_creating_an_application_credit.cs" />
<Compile Include="ShopifyApplicationCreditService Tests\When_getting_an_application_credit.cs" />
<Compile Include="ShopifyApplicationCreditService Tests\When_listing_application_charges.cs" />
<Compile Include="ShopifyArticleService Tests\Utils.cs" />
<Compile Include="ShopifyArticleService Tests\When_counting_articles.cs" />
<Compile Include="ShopifyArticleService Tests\When_creating_an_article.cs" />
<Compile Include="ShopifyArticleService Tests\When_deleting_an_article.cs" />
<Compile Include="ShopifyArticleService Tests\When_listing_articles.cs" />
<Compile Include="ShopifyArticleService Tests\When_listing_authors.cs" />
<Compile Include="ShopifyArticleService Tests\When_listing_tags.cs" />
<Compile Include="ShopifyArticleService Tests\When_listing_tags_for_a_blog.cs" />
<Compile Include="ShopifyArticleService Tests\When_updating_an_article.cs" />
<Compile Include="ShopifyAssetService Tests\AssetUtils.cs" />
<Compile Include="ShopifyAssetService Tests\When_copying_an_asset.cs" />
<Compile Include="ShopifyAssetService Tests\When_creating_an_asset.cs" />
Expand Down
Loading

0 comments on commit ac05c89

Please sign in to comment.