This file contains 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
void Main() | |
{ | |
var data = @"{'id':'528c97b12314dcac5c0021b0','name':'Query','idBoard':'5268f13aa63b12236e0051d2','idCard': | |
'528c97aa3a003a4a0c00339a','pos':16384,'checkItems':[{'state':'incomplete','id':'528c97bf7a14af624e00228d', | |
'name':'What ares are on or off in what page for pocket hub section','nameData':{'emoji':{}},'pos':16970}, | |
{'state':'incomplete','id':'528c97d3e790ecc25c0035f6', | |
'name':'Buy now integration','nameData':null,'pos':33467}, | |
{'state':'incomplete','id':'528c97d9205dd7a54c003598', | |
'name':'Buys now quantitiy integration','nameData':null,'pos':50628}, | |
{'state':'incomplete','id':'528c97f0b52fd8ab2f003227','name':'Vote functionality integration','nameData':null,'pos':67217}, |
This file contains 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
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] | |
public class CurrentVersionHeaderAttribute : ActionFilterAttribute | |
{ | |
private const string _xVersion = "X-Version"; | |
private static readonly string _version = Assembly.GetExecutingAssembly().GetName().Version.ToString(); | |
public override void OnResultExecuted(ResultExecutedContext filterContext) | |
{ | |
var headers = filterContext.HttpContext.Response.Headers; |
This file contains 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> | |
/// Select distinct elements in collection on a given property | |
/// </summary> | |
/// <typeparam name="TSource"></typeparam> | |
/// <typeparam name="TKey"></typeparam> | |
/// <param name="source">The collection to filter</param> | |
/// <param name="keySelector">The property to distinct collection by</param> | |
/// <returns></returns> | |
public static IEnumerable<TSource> DistinctBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector) | |
{ |
This file contains 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 string DaySuffix(this DateTime dateTime) | |
{ | |
return (dateTime.Day == 1) | |
? "st" | |
: (dateTime.Day == 2) | |
? "nd" | |
: (dateTime.Day == 3) | |
? "rd" | |
: "th"; | |
} |
This file contains 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> | |
/// Postcode validation attribute | |
/// Must be uppercase with a single optional space | |
/// </summary> | |
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = false)] | |
public class PostcodeAttribute : DataTypeAttribute | |
{ | |
private static readonly Regex _regex = new Regex(@"^(GIR ?0AA|[A-PR-UWYZ]([0-9]{1,2}|([A-HK-Y][0-9]([0-9ABEHMNPRV-Y])?)|[0-9][A-HJKPS-UW]) ?[0-9][ABD-HJLNP-UW-Z]{2})$"); | |
//if you need lowercase and multi space use this one |
This file contains 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 ValidateObjectAttribute: ValidationAttribute { | |
protected override ValidationResult IsValid(object value, ValidationContext validationContext) { | |
var results = new List<ValidationResult>(); | |
var context = new ValidationContext(value, null, null); | |
Validator.TryValidateObject(value, context, results, true); | |
if (results.Count != 0) { | |
var compositeResults = new CompositeValidationResult(String.Format("Validation for {0} failed!", validationContext.DisplayName)); | |
results.ForEach(compositeResults.AddResult); |
This file contains 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> | |
/// Used to simplify testing routes and restful testing routes | |
/// <example> | |
/// This tests that incoming PUT on resource is handled by the update method of the Banner controller | |
/// "~/banner/1" | |
/// .WithMethod(HttpVerbs.Put) | |
/// .ShouldMapTo<BannerController>(action => action.Update(1)); | |
/// </example> | |
/// </summary> | |
public static class RouteTestingExtensions |
This file contains 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 HttpContextBuilder | |
{ | |
private Mock<HttpContextBase> _context; | |
private Mock<HttpRequestBase> _request; | |
private Mock<HttpResponseBase> _response; | |
private Mock<HttpSessionStateBase> _session; | |
private Mock<HttpServerUtilityBase> _server; | |
private Mock<IPrincipal> _user; | |
private Mock<IIdentity> _identity; |
This file contains 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 AttributeExtensions | |
{ | |
/// <summary> | |
/// Will return true if the attributeTarget is decorated with an attribute of type TAttribute. | |
/// Will return false if not. | |
/// </summary> | |
/// <typeparam name="TAttribute"></typeparam> | |
/// <param name="attributeTarget"></param> | |
/// <returns></returns> | |
public static bool IsDecoratedWith<TAttribute>(this ICustomAttributeProvider attributeTarget) where TAttribute : Attribute |
This file contains 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 MethodInfoExtensions | |
{ | |
/// <summary> | |
/// Will return the name of the action specified in the ActionNameAttribute for a method if it has an ActionNameAttribute. | |
/// Will return the name of the method otherwise. | |
/// </summary> | |
/// <param name="method"></param> | |
/// <returns></returns> | |
public static string ActionName(this MethodInfo method) | |
{ |