Skip to content

Instantly share code, notes, and snippets.

@robfe
robfe / SomethingDataContext.cs
Created March 5, 2014 22:38
EF Datacontext.WaitForMicroOutageToPass (for sql on azure)
void WaitForMicroOutageToPass() //call this from your constructor
{
if (!Database.Exists())
{
return;
}
var connection = Database.Connection;
for (int i = 0; i < 10; i++)
{
public static TValue GetValueOrDefault<TKey, TValue> (this Dictionary<TKey, TValue> d, TKey key, TValue defaultValue = default(TValue))
{
TValue value;
return d.TryGetValue(key, out value) ? value : defaultValue;
}
[Trait("Category", "Spike")]
public class OomBuilder
{
const string StaticConverter = @"
public static {{To}} To{{To}}({{From}} src)
{
return new {{To}}
{
{{#each Matches}}
{{this}} = src.{{this}},{{/each}}
ALTER PROC sp_generate_inserts
(
@table_name varchar(776), -- The table/view for which the INSERT statements will be generated using the existing data
@target_table varchar(776) = NULL, -- Use this parameter to specify a different table name into which the data will be inserted
@include_column_list bit = 1, -- Use this parameter to include/ommit column list in the generated INSERT statement
@from varchar(800) = NULL, -- Use this parameter to filter the rows based on a filter condition (using WHERE)
@include_timestamp bit = 0, -- Specify 1 for this parameter, if you want to include the TIMESTAMP/ROWVERSION column's data in the INSERT statement
@debug_mode bit = 0, -- If @debug_mode is set to 1, the SQL statements constructed by this procedure will be printed for later examination
@owner varchar(64) = NULL, -- Use this parameter if you are not the owner of the table
@robfe
robfe / SpecAttribute.cs
Last active August 29, 2015 14:10
Make XUnit tests dynamically skippable for SpecLight
/// <summary>
/// Speclight users like to see "Pending" steps (that throw NotImplementedException) as "skip" not "fail"
/// </summary>
public class SpecAttribute : FactAttribute
{
protected override IEnumerable<ITestCommand> EnumerateTestCommands(IMethodInfo method)
{
yield return new SkipIfNotImplemented(method);
}
@robfe
robfe / ApprovalNameEnhancer.cs
Created November 28, 2014 03:09
Adds step names to Approvals.Net file names, so you can have multiple asserts in one unit test
public class ApprovalNameEnhancer : SpecFixtureBase
{
public override void StepSetup(Step step)
{
//tack the step description onto the approval file name:
NamerFactory.AdditionalInformation = step.Description;
//ok, but what if the step used twice in the same spec (with the same arguments)?
var dupes = step.Spec.Steps.Where(x => x.Description == step.Description);
var index = dupes.ToList().IndexOf(step);
@robfe
robfe / DynamicBDDBase.cs
Created May 19, 2010 14:48
Dynamic dispatch + printing of BDD steps
// Complementary to http://gist.github.com/406014. Just swap your BDD<T> base class for DBDD
// Also licensed under MSPL/FreeBSD/ISC
public abstract class DBDD
{
public readonly dynamic Given;
public readonly dynamic When;
public readonly dynamic Then;
public readonly dynamic And;
@robfe
robfe / Regionator.cs
Created June 26, 2010 15:07
Extract #regions into individual txt files for INCLUDETEXT in word...
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace Regionator
{
public class Program
{
const int TargetSpacesPerIndent = 3;
@robfe
robfe / CodeTimer.cs
Created July 1, 2010 15:18
using(new CodeTimer("connecting")){connect();}
public class CodeTimer : IDisposable
{
private readonly string _message;
private readonly Stopwatch _sw = new Stopwatch();
public CodeTimer(string message)
{
_message = message;
_sw.Start();
}
@robfe
robfe / FillingLine.cs
Created October 11, 2010 12:07
Path subclass for drawing a line that fills its available space in silverlight
public class FillingLine : Path
{
Size lastFinalSize;
protected override Size MeasureOverride(Size availableSize)
{
return new Size(0, 0);
}
protected override Size ArrangeOverride(Size finalSize)