Skip to content

Instantly share code, notes, and snippets.

@ColinScott
ColinScott / gist:3e6668b4607403c9b8d0
Created July 6, 2015 05:11
Fix SQL mangling when encoded in stupid format
var filename = @"<file path>";
var bytes = File.ReadAllBytes(filename);
var newBytes = new List<byte>();
for (var i = 0; i < bytes.Length; i++)
{
if (bytes[i] == 0x0D && bytes[i+1] == 0x0A)
{
void Main()
{
var thing = Substitute.For<IThing>();
thing.Thing(new [] { 1 });
thing.Received().Thing(new [] { 1 });
}
public interface IThing
@ColinScott
ColinScott / gist:8419e167c6e419099bd3
Created August 21, 2014 01:41
Ending with incorrect binding redirects
Create an Azure Worker Role (SDK 2.4 was used)
Run update-package to update everything
Newtonsoft.json now version 6.0.4 and binding redirects reflect this
Run update-package windowsazure.storage -reinstall
Newtonsoft.json is reverted to 5.0.6.
Binding redirects not updated, still redirect to version 6.0.0.0 (assembly version in 6.0.4 package)
Also issue with Microsoft.Data.Edm, Microsoft.Data.OData and System.Spatial packages.
@ColinScott
ColinScott / gist:9443227
Created March 9, 2014 05:22
Adding ExpectedObjects to NSubstitute
This adds a new Arg.ShouldMatch<T> method that uses expected objects to verify the received argument matches the expected object. For example the code below gives an error message of "ReceivedCallsException: Expected to receive exactly 1 call matching:
Blah(For Thing.Stuff, expected "Whatever2" but found "Whatever".
For Thing.OtherStuff, expected "abcd2" but found "abcd".
)
Actually received no matching calls.
Received 1 non-matching call (non-matching arguments indicated with '*' characters):
Blah(*Thing*)"
void Main()
{
@ColinScott
ColinScott / FooActionFilter.cs
Created November 24, 2012 05:16
Providing Context with interfaces and ASP.NET MVC Filter Providers
public class FooActionFilter : IActionFilter
{
public void OnActionExecuting(ActionExecutingContext filterContext)
{
var fooController = (IFoo) filterContext.Controller;
fooController.Context = new FooContext();
}
public void OnActionExecuted(ActionExecutedContext filterContext)