Last active
December 23, 2015 20:39
-
-
Save jbogard/6690905 to your computer and use it in GitHub Desktop.
Revisions
-
jbogard revised this gist
Sep 25, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -31,7 +31,7 @@ public void ThrowsException() { } } /* Collapsed before/act etc. It added no value. */ public class When_no_subscriptions_exist { public void Should_not_add_the_site() { -
jbogard revised this gist
Sep 25, 2013 . 1 changed file with 89 additions and 88 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -18,122 +18,123 @@ public void Generates_a_new_api_key() { } } } namespace adding_a_site { /* This is a bad test. It's coupled to the implementation of the object mother's factory method */ public class When_the_site_already_exists { public void ThrowsException() { Account account = ObjectMother.GetAccountWithSite(); typeof(InvalidOperationException).ShouldBeThrownBy(() => account.AddSite("sites/1")); } } /* Collapsed before/after etc. It added no value. */ public class When_no_subscriptions_exist { public void Should_not_add_the_site() { Account account = new Account(); account.AddSite("sites/1"); account.Sites.Count.ShouldEqual(0); } } /* see above. there's no need to split out AAA */ public class When_no_available_subscriptions_exist { public void Should_not_add_the_site() { Account account = GetAccountWithSite(); account.AddSite("sites/2"); account.Sites.Count.ShouldEqual(1); } } public class When_available_subscriptions_exist { public void Should_add_the_site() { Account account = new Account(); account.AddSubscription(ObjectMother.GetValidSubscription()); account.AddSite("sites/1"); account.Sites.Count.ShouldEqual(1); } } /* These previous tests should really be consolidated into one test class Separating out into indvidual classes doesn't add any value. */ } /* Also don't like this test. Change GetAccountWithSite with a different site, BOOM */ public class validating_sites { Account account = ObjectMother.GetAccountWithSite(); public void When_the_specified_site_is_mapped_to_the_account_should_be_valid { account.ValidateSite("sites/1").ShouldBeTrue(); } public void When_the_specified_site_is_not_mapped_to_the_account() { account.ValidateSite("sites/2").ShouldBeFalse(); } } /* Common act, also a bad idea. It adds nothing but needless indirection */ public class validating_subscriptions { public void When_the_account_has_a_valid_subscription_should_report_as_valid { Account account = new Account(); account.AddSubscription(GetValidSubscription()); account.HasValidSubscription().ShouldBeTrue(); } public void When_the_account_has_no_valid_subscriptions_should_report_as_invalid { Account account = new Account(); account.AddSite("sites/1"); var subscription = new Subscription( "products/1", "Fabrik Subscription", 69M, DateTime.UtcNow.AddMonths(-13), // expired by one month new SubscriptionDuration(1, SubscriptionPeriod.Yearly)); account.AddSubscription(subscription); account.HasValidSubscription().ShouldBeFalse(); } } public static class ObjectMother { public Subscription GetValidSubscription() { return new Subscription( "products/1", "Fabrik Subscription", 69M, DateTime.UtcNow, new SubscriptionDuration(1, SubscriptionPeriod.Yearly) ); } public Account GetAccountWithSite() { var account = new Account(); account.AddSubscription(GetValidSubscription()); account.AddSite("sites/1"); return account; } } } -
jbogard revised this gist
Sep 25, 2013 . 1 changed file with 7 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -2,23 +2,23 @@ namespace Accounts { namespace NewAccounts { public class When_creating_a_new_account { Account account = new Account(); public void Does_not_have_any_subscriptions() { account.Subscriptions.Count.ShouldEqual(0); } public void Does_not_have_any_sites() { account.Subscriptions.Count.ShouldEqual(0); } public void Generates_a_new_api_key() { account.ApiKeys.First().ShouldNotBeEmpty(); } } } /* namespace adding_a_site { context["when the site already exists"] = () => @@ -134,4 +134,6 @@ Account GetAccountWithSite() account.AddSite("sites/1"); return account; } */ } -
jbogard revised this gist
Sep 24, 2013 . 1 changed file with 18 additions and 18 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,25 +1,25 @@ namespace Accounts { namespace NewAccounts { class When_creating_a_new_account { Account account = new Account(); void Does_not_have_any_subscriptions() { account.Subscriptions.Count.ShouldEqual(0); } void Does_not_have_any_sites() { account.Subscriptions.Count.ShouldEqual(0); } void Generates_a_new_api_key() { account.ApiKeys.First().ShouldNotBeEmpty(); } } } namespace adding_a_site { context["when the site already exists"] = () => { -
amirrajan revised this gist
Oct 6, 2012 . 1 changed file with 106 additions and 157 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,188 +1,137 @@ class describe_Accounts : nspec { Account account; void before_each() { account = new Account(); //agree that moving this up doesn't hurt readability? } void when_creating_a_new_account() { it["doesn't have any subscriptions"] = () => account.Subscriptions.Count.ShouldEqual(0); it["doesn't have any sites"] = () => account.Sites.Count.ShouldEqual(0); it["generates a new api key"] = () => account.ApiKeys.First().ShouldNotBeEmpty(); } void adding_a_site { context["when the site already exists"] = () => { before = () => account = GetAccountWithSite(); act = () => account.AddSite("sites/1"); it["throws excepton"] = expect<InvalidOperationException>(); }; context["when no subscriptions exist"] = () => { before = () => account.AddSite("sites/1"); it["doesn't add the site"] = () => account.Sites.Count.ShouldEqual(0); }; context["when no available subscriptiosn exist"] = () => { before = () => account = GetAccountWithSite(); act = () => account.AddSite("sites/2"); it["doesn't add the site"] = () => account.Sites.Count.ShouldEqual(1); } context["when available subscriptions exists"] = () => { before = () => account.AddSubscription(GetValidSubscription()); act = () => account.AddSite("sites/1"); it["adds the site"] = () => account.Sites.Count.ShouldEqual(1); }; } bool result; void validating_sites() { before = () => account = GetAccountWithSite(); //common before move it up a context (shouldnt hurt redability)? context["when the specified site is mapped to the account"] = () => { act = () => result = account.ValidateSite("sites/1"); it["is valid"] = () => result.should_be_false(); }; context["when the specified site is not mapped to the account { act = () => result = account.ValidateSite("sites/2"); it["is invalid"] = () => result.should_be_false(); } } void validating_subscriptions() { act = () => result = account.HasValidSubscription(); //common act, move it up a context (shouldnt hurt redability)? context["when the account has a valid subscription"] = () => { before = () => account.AddSubscription(GetValidSubscription()); it["returns true"] = () => result.ShouldBeTrue(); }; context["when the account has no valid subscriptions"] = () => { before = () => { account.AddSite("sites/1"); var subscription = new Subscription( "products/1", "Fabrik Subscription", 69M, DateTime.UtcNow.AddMonths(-13), // expired by one month new SubscriptionDuration(1, SubscriptionPeriod.Yearly)); account.AddSubscription(subscription); }; it["returns false"] = () => result.ShouldBeFalse(); } } Subscription GetValidSubscription() { return new Subscription( "products/1", "Fabrik Subscription", 69M, DateTime.UtcNow, new SubscriptionDuration(1, SubscriptionPeriod.Yearly) ); } Account GetAccountWithSite() { var account = new Account(); account.AddSubscription(GetValidSubscription()); account.AddSite("sites/1"); return account; } } -
benfoster created this gist
Oct 6, 2012 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,188 @@ [Subject(typeof(Account))] public class AccountSpecs { static Account account; public class When_creating_a_new_account { Because of = () => account = new Account(); It Should_not_have_any_subscription = () => account.Subscriptions.Count.ShouldEqual(0); It Should_not_have_any_sites = () => account.Sites.Count.ShouldEqual(0); It Should_generate_a_new_api_key = () => account.ApiKeys.First().ShouldNotBeEmpty(); } [Subject(typeof(Account), "Adding sites")] public class Adding_a_site { static Exception exception; public class When_the_site_already_exists { Establish ctx = () => account = GetAccountWithSite(); Because of = () => exception = Catch.Exception(() => account.AddSite("sites/1")); It Should_throw = () => exception.ShouldBeOfType<InvalidOperationException>(); } public class When_no_subscriptions_exist { Establish ctx = () => account = new Account(); Because of = () => account.AddSite("sites/1"); It Should_not_add_the_site = () => account.Sites.Count.ShouldEqual(0); } public class When_no_available_subscriptions_exist { Establish ctx = () => account = GetAccountWithSite(); Because of = () => account.AddSite("sites/2"); It Should_not_add_the_site = () => account.Sites.Count.ShouldEqual(1); } public class When_an_available_subscription_exists { Establish ctx = () => { account = new Account(); account.AddSubscription(GetValidSubscription()); }; Because of = () => account.AddSite("sites/1"); It Should_add_the_site = () => account.Sites.Count.ShouldEqual(1); } } [Subject(typeof(Account), "Validating sites")] public class Validating_sites { static bool result; public class When_the_specified_site_is_mapped_to_the_account { Establish ctx = () => account = GetAccountWithSite(); Because of = () => result = account.ValidateSite("sites/1"); It Should_return_true = () => result.ShouldBeTrue(); } public class When_the_specified_site_is_not_mapped_to_the_account { Establish ctx = () => account = GetAccountWithSite(); Because of = () => result = account.ValidateSite("sites/2"); It Should_return_false = () => result.ShouldBeFalse(); } } [Subject(typeof(Account), "Validating subscriptions")] public class Validating_subscriptions { static bool result; public class When_the_account_has_a_valid_subscription { Establish ctx = () => { account = new Account(); account.AddSubscription(GetValidSubscription()); }; Because of = () => result = account.HasValidSubscription(); It Should_return_true = () => result.ShouldBeTrue(); } public class When_the_account_has_no_valid_subscriptions { Establish ctx = () => { account = new Account(); account.AddSite("sites/1"); var subscription = new Subscription( "products/1", "Fabrik Subscription", 69M, DateTime.UtcNow.AddMonths(-13), // expired by one month new SubscriptionDuration(1, SubscriptionPeriod.Yearly)); account.AddSubscription(subscription); }; Because of = () => result = account.HasValidSubscription(); It Should_return_false = () => result.ShouldBeFalse(); } } public class When_resetting_api_key { static string currentKey; Establish ctx = () => { account = new Account(); currentKey = account.ApiKeys.First(); }; Because of = () => account.ResetApiKey(); It Should_generate_a_new_key = () => currentKey.ShouldNotEqual(account.ApiKeys.First()); } private static Subscription GetValidSubscription() { return new Subscription( "products/1", "Fabrik Subscription", 69M, DateTime.UtcNow, new SubscriptionDuration(1, SubscriptionPeriod.Yearly) ); } private static Account GetAccountWithSite() { var account = new Account(); account.AddSubscription(GetValidSubscription()); account.AddSite("sites/1"); return account; } }