Skip to content

Instantly share code, notes, and snippets.

View tugberkugurlu's full-sized avatar
:shipit:
💥 shakalaka

Tugberk Ugurlu tugberkugurlu

:shipit:
💥 shakalaka
View GitHub Profile
@tugberkugurlu
tugberkugurlu / fake-http-context.cs
Created November 5, 2012 23:07 — forked from frankshearar/fake-http-context.cs
A Moq-using fake HTTP context to test controllers.
public HttpContextBase FakeHttpContext() {
var context = new Mock<HttpContextBase>();
var files = new Mock<HttpFileCollectionBase>();
var request = new Mock<HttpRequestBase>();
var response = new Mock<HttpResponseBase>();
var session = new Mock<HttpSessionStateBase>();
var server = new Mock<HttpServerUtilityBase>();
var user = new Mock<IPrincipal>();
var identity = new Mock<IIdentity>();
request.Setup(req => req.ApplicationPath).Returns("~/");
@tugberkugurlu
tugberkugurlu / gist:3989706
Created October 31, 2012 20:38 — forked from maartenba/CloudBlobExtensions.cs
Some common ICloudBlob extension methods
public static class CloudBlobExtensions
{
/// <summary>
/// Uploads a string of text to a block blob.
/// </summary>
/// <param name="content">The text to upload, encoded as a UTF-8 string.</param>
public static void UploadText(this ICloudBlob blob, string content)
{
UploadText(blob, content, Encoding.UTF8, null);
}
@tugberkugurlu
tugberkugurlu / gist:3949100
Created October 24, 2012 21:43 — forked from pmhsfelix/gist:3949044
Canonicalized Header and Resource String
private static string[] GetCanonicalizedHeaders(HttpRequestHeaders headers)
{
return headers
.Where(p => p.Key.StartsWith("x-ms-", StringComparison.InvariantCultureIgnoreCase))
.Select(p => new { Name = p.Key.ToLower(), Value = p.Value.First() })
.OrderBy(p => p.Name)
.Select(p => string.Format("{0}:{1}", p.Name, p.Value))
.ToArray();
}
@tugberkugurlu
tugberkugurlu / promises.md
Created October 22, 2012 10:55 — forked from domenic/promises.md
You're Missing the Point of Promises

You're Missing the Point of Promises

Promises are a software abstraction that makes working with asynchronous operations much more pleasant. In the most basic definition, your code will move from continuation-passing style:

getTweetsFor("domenic", function (err, results) {
    // the rest of your code goes here.
});
@tugberkugurlu
tugberkugurlu / gist:3924324
Created October 20, 2012 18:49 — forked from benfoster/gist:3924025
LESS CSS Support in System.Web.Optimization
public class LessTransform : IBundleTransform
{
public void Process(BundleContext context, BundleResponse bundle)
{
if (context == null)
{
throw new ArgumentNullException("context");
}
if (bundle == null)
@tugberkugurlu
tugberkugurlu / gist:3905671
Created October 17, 2012 14:05 — forked from benfoster/gist:3905658
jQuery UI Autocomplete, Twitter Bootstrap Style
.ui-autocomplete {
position: absolute;
cursor: default;
list-style: none;
display: block;
outline: none;
padding: 5px 0;
margin: 2px 0 0;
background-color: @dropdownBackground;
border: 1px solid #ccc; // Fallback for IE7-8
@tugberkugurlu
tugberkugurlu / gist:3868580
Created October 10, 2012 21:34 — forked from benfoster/gist:3867583
A production useless version of an OAuth request
namespace OAuthDemo.Controllers
{
public static class SecurityConfig
{
public static void Configure(HttpConfiguration httpConfiguration)
{
var config = new AuthenticationConfiguration();
config.DefaultAuthenticationScheme = "Basic";
@tugberkugurlu
tugberkugurlu / gist:3860947
Created October 9, 2012 19:36 — forked from JefClaes/gist:3860582
Command an query handlers
[TestMethod()]
public void Foo_should_start_mspaint()
{
var cmdHandler = new Mock<ICommandHandler>();
var qryHandler = new Mock<IQueryHandler>();
var controller = new Controller(cmdHandler.Object, qryHandler.Object);
controller.Foo("mspaint.exe");

Assuming you have the following object:

public class Person { 
    
    public string Name { get; set; }
    public string Surname { get; set; }
    public int Age { get; set; }
}

and got a PATCH request as below:

@tugberkugurlu
tugberkugurlu / gist:3852195
Created October 8, 2012 12:11 — forked from benfoster/gist:3848727
A custom DataAnnotationsModelValidatorProvider that injects IServiceProvider into ValidationContext
public class CustomDataAnnotationsModelValidatorProvider : DataAnnotationsModelValidatorProvider
{
private readonly IServiceProvider serviceProvider;
public CustomDataAnnotationsModelValidatorProvider(IServiceProvider serviceProvider)
{
this.serviceProvider = serviceProvider;
DataAnnotationsModelValidatorProvider.RegisterDefaultAdapterFactory(
(metadata, context, attribute) =>