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 characters
public AccountHandler() | |
{ | |
Get["/accounts/{id}"] = x => { return GetById(x.id); }; | |
Get["/accounts"] = x => { return GetListing(); }; | |
Post["/accounts", req => CanPost(req)] = x => { return CreateNewAccount(Request.Body.FromJson<NewAccountForm>()); }; | |
} |
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 characters
public class AuthenticationInterceptor : IInterceptor | |
{ | |
bool CanIntercept(IInvocation invocation) { return invocation.Method.GetCustomAttributes(true).Any(a => a is RequiresAuthenticationAttribute); } | |
public void Intercept(IInvocation invocation) | |
{ | |
if (!CanIntercept(invocation)) invocation.Proceed(); | |
else | |
{ | |
var module = invocation.InvocationTarget as NancyModule; |
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 characters
using System; | |
using System.Collections.Generic; | |
using System.Dynamic; | |
using System.Linq.Expressions; | |
using Microsoft.CSharp.RuntimeBinder; | |
namespace Nancy | |
{ | |
public class DynamicDictionary : DynamicObject, IEquatable<DynamicDictionary> | |
{ |
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 characters
public class when_updating_a_feature_for_a_product : domain_context<SetFeaturesForProduct, SetFeaturesForProductHandler> | |
{ | |
static Product _product; | |
Establish context = () => | |
{ | |
_product = Given<Product>(History.product_created, History.product_feature_added); | |
ExpectedEvents = 1; | |
}; |
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 characters
public static class DomainSpecificationExtensions | |
{ | |
public static void ShouldHave<T>(this IEnumerable<ISourcedEvent> source, params Predicate<T>[] conditions) where T : class, ISourcedEvent | |
{ | |
T actualEvent = (T) source.FirstOrDefault(x => x is T); | |
if (actualEvent == null) | |
throw new SpecificationException(string.Format("{0} did not happen as expected", typeof (T).Name)); | |
actualEvent.ShouldMatch(conditions); | |
} |
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 characters
public class when_an_array_is_updated_internally : mongo_repository_context<CategoryModel> | |
{ | |
static CategoryModel model = new CategoryModel { Name = "Test", FeatureTypes = new[] { | |
new FeatureTypeModel{ Name = "feature1", DefaultValue = "Test1" }, | |
new FeatureTypeModel{ Name = "feature2", DefaultValue = "Test2" }, | |
}}; | |
Establish context = () => { | |
InternalCollection.Save(model); | |
cursor = InternalCollection.Find(Query.EQ("_id", "Test")); |
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 characters
/// <summary> | |
/// An entity which references a Category | |
/// </summary> | |
public class CategoryRef : Entity<Catalog> | |
{ | |
string _slug; | |
public CategoryRef(Catalog catalog, Category category, Category parentCategory) : base(catalog, Guid.NewGuid()) | |
{ | |
ApplyEvent(new CategoryAddedToCatalog {Category = category, Slug = category.Name.ToSlug() }); |
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 characters
public RetailStreamHandler(IDocumentRepository<ShoppingCart> cartRepository) | |
{ | |
_cartRepository = cartRepository; | |
Get["/cart"] = x => GetListing(); | |
Post["/cart"] = x => PostNewShoppingCart(Request.Body.FromJson<ShoppingCartForm>()); | |
Get["/cart/{id}"] = x => GetById(x.id); | |
} | |
[RequiresAuthentication] | |
public virtual Response PostNewShippingCart(ShoppingCartForm form) |
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 characters
[core] | |
editor = vim | |
excludesfile = ~/.gitignore | |
[user] | |
name = chris.nicola | |
email = [email protected] | |
[color] | |
diff = auto | |
branch = auto | |
status = auto |
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 characters
/* A JSON gzip compression filter, which could easily be adapted to any pattern needed. This uses a custom AfterFilter | |
* type which is just a fancy wrapper of Action<NancyContext>. It's useful for convention based loading of filters | |
*/ | |
public class GzipCompressionFilter : AfterFilter | |
{ | |
protected override void Handle(NancyContext ctx) | |
{ | |
if ((ctx.Response.ContentType == "application/json") && ctx.Request.Headers.AcceptEncoding.Any( |