Skip to content

Instantly share code, notes, and snippets.

View feanz's full-sized avatar

Richard Forrest feanz

View GitHub Profile
@feanz
feanz / CacheAttribute.cs
Created January 2, 2014 09:14
Cache Infrastucture
[AttributeUsage(AttributeTargets.Class,AllowMultiple = false, Inherited = false)]
public class CacheAttribute : Attribute
{
/// <summary>
/// The name of the cache profile to be used
/// </summary>
public string ProfileName { get; set; }
/// <summary>
/// Lifespan of the response in the cache
@feanz
feanz / AutoMoqControllerDataAttribute.cs
Created January 2, 2014 09:18
AutoMoqDataAttributeVersions Uses Autofixture and Xunit Data Theory attribute.
public class AutoMoqControllerDataAttribute : AutoDataAttribute
{
public AutoMoqControllerDataAttribute()
: base(new Fixture()
.Customize(new AutoMoqControllerCustomization()))
{
}
}
public class AutoMoqControllerCustomization : CompositeCustomization
@feanz
feanz / ApiIntegrationFixture.cs
Created January 2, 2014 09:22
Web API Integration Tests
public class ApiIntegrationFixture : IDisposable
{
public ApiIntegrationFixture()
{
var config = new HttpConfiguration();
WebApiConfig.Register(config);
config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
//remember to add all filters
config.Filters.Add(new ValidationActionFilter());
@feanz
feanz / DeployEnvironment.ps1
Created January 2, 2014 09:25
Sitecore Website deployment scripts
<#
.SYNOPSIS
Quick deploy to various environments.
.DESCRIPTION
Calls deploy.ps1 with relevant arguments for repeatable deployments.
.PARAMETER deployTo
Specify the environment to deploy to. Currently supports "Dev-CMS" and "Dev-CD"
@feanz
feanz / ApplicationManagement.cs
Created January 7, 2014 16:45
Application Management
public class ApplicationManagement : IApplicationManagement
{
private readonly IEnumerable<IApplicationSetting> _settings;
public ApplicationManagement(IEnumerable<IApplicationSetting> settings)
{
_settings = settings;
try
{
@feanz
feanz / Email.cs
Created January 20, 2014 13:33
Fluent Email
public class Email : IDisposable
{
private SmtpClient _client;
private bool? _useSsl;
private Email()
{
Message = new MailMessage();
_client = new SmtpClient();
}
@feanz
feanz / ValidateAntiForgeryTokenAttribute.cs
Created January 31, 2014 09:40
Validate AntiForgery Token Attribute that could be used for web api
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
public sealed class ValidateAntiForgeryTokenAttribute : FilterAttribute, IAuthorizationFilter
{
public Task<HttpResponseMessage> ExecuteAuthorizationFilterAsync(HttpActionContext actionContext, CancellationToken cancellationToken, Func<Task<HttpResponseMessage>> continuation)
{
try
{
//could add optional ajax header check here
AntiForgery.Validate();
}
@feanz
feanz / MethodOverrideHandler.cs
Created February 5, 2014 10:21
Way to use the method override header to route traffic to controller actions.
public class MethodOverrideHandler : DelegatingHandler
{
readonly string[] _methods = { "DELETE", "HEAD", "PUT" };
const string _header = "X-HTTP-Method-Override";
protected override Task<HttpResponseMessage> SendAsync(
HttpRequestMessage request, CancellationToken cancellationToken)
{
// Check for HTTP POST with the X-HTTP-Method-Override header.
if (request.Method == HttpMethod.Post && request.Headers.Contains(_header))
@feanz
feanz / NoneNavigateableAttribute.cs
Created March 17, 2014 11:33
Walk Object Graph
/// <summary>
/// A decoration only property used to determine if a property should be walked by specific graph walking functions
/// </summary>
[AttributeUsage(AttributeTargets.Property, Inherited = false, AllowMultiple = false)]
public class NoneNavigateableAttribute : Attribute{}
@feanz
feanz / Allowuploadsafefilesattribute.cs
Created April 2, 2014 10:30
MVC Action Filter Allow upload of safe files attribute
using System;
using System.linq;
using System.collections.generic;
using System.IO;
using System.web.mvc;
namespace Securitymodule
{
[Attributeusage (Attributetargets.method, Allowmultiple = false )]
public sealed class Allowuploadsafefilesattribute: Actionfilterattribute