Skip to content

Instantly share code, notes, and snippets.

@jamesrcounts
jamesrcounts / TheoryApprover.cs
Created October 2, 2012 03:25
A dumbed down version of FileApprover, that makes Verifying two arbitrary text files easier.
public class TheoryApprover : IApprovalApprover
{
private readonly string approved;
private readonly string received;
private ApprovalException failure;
public TheoryApprover(string approved, string received)
{
this.received = received;
this.approved = approved;
@jamesrcounts
jamesrcounts / FormatCommand.cs
Created September 7, 2012 17:11
A text formatter for SqlCommand instances
/// <summary>
/// Formats the command.
/// </summary>
/// <param name="command">The command.</param>
/// <returns>A formatted <see cref="SqlCommand"/></returns>
private static string FormatCommand(SqlCommand command)
{
string result = command.CommandText + Environment.NewLine;
result = string.Format("{0}{{{1}", result, Environment.NewLine);
foreach (var item in command.Parameters)
@jamesrcounts
jamesrcounts / DemoForm.cs
Created August 8, 2012 15:29
WinForms+EventApprovals
using System;
using System.Windows.Forms;
namespace ApprovalUtilities.Tests.Reflection
{
public partial class DemoForm : Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.CheckBox checkBox1;
@jamesrcounts
jamesrcounts / CassiniReporter.cs
Created July 20, 2012 13:49
MvcReporter for MvcApprovals which use self-hosted webserver
namespace ApprovalTests.Reporters
{
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using ApprovalTests.Asp.CassiniDev;
using ApprovalTests.Core;
@jamesrcounts
jamesrcounts / README.md
Created July 7, 2012 01:32
String.Contains, C# Finite State Machine Implementation

String.Contains C# Edition

I enjoy playing with state machines. They are simple enough to implement quickly, and complex enough to give the implementation language a little workout. Followers of this blog will know that I've enjoyed using Finite State Machines to explore CoffeeScript.

But, when I look at the search terms leading to my blog, I see that people want to see FSMs implemented in C#, C++, or even VB. About the only language I haven't seen people looking for is CoffeeScript. I'm not too suprised, since most people searching for FSM implementations are probably students trying to cheat on thier homework. I doubt any professors are accepting CoffeeScript implemenations.

When I see these search results, I consider quickly posting a solution in the requested language. I don't mind if students crib solutions from me. I'm a big believer in learning by example. Certainly if by looking at my FSMs I can save one student from writing a switch statement, then I'll consider it a public serv

@jamesrcounts
jamesrcounts / README.md
Created July 2, 2012 01:52
Patch for VisualStudioReporter

Alternate method seems to work more reliably. Old version only works under MSTEST, since the module we looked for was an MSTEST module. This version gets the parent process and checks if the parent process was VS11. Actually old version isn't working for me under MSTEST either, not sure when it stopped working since I haven't been using VS2012 much.

I should say that it doesn't work with FirstWorkingReporter. It works when used directly.

@jamesrcounts
jamesrcounts / .gitattributes
Created June 25, 2012 01:35
A Finite State Machine to accept even length strings of 0s and 1s. Written at SoCalCodeCamp San Diego, 6/24/2012. Details, Video, Slides: http://wp.me/p1HYUa-80
# Disable LF normalization for all files
* -text
@jamesrcounts
jamesrcounts / InlineTask.targets.xml
Created June 22, 2012 11:53 — forked from bradwilson/InlineTask.targets.xml
Inline MSBuild task to download NuGet.exe
<UsingTask TaskName="DownloadNuGet" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<ParameterGroup>
<OutputFilename ParameterType="System.String" Required="true" />
</ParameterGroup>
<Task>
<Reference Include="System.Core" />
<Reference Include="System.Xml" />
<Reference Include="WindowsBase" />
<Using Namespace="System" />
<Using Namespace="System.IO" />
@jamesrcounts
jamesrcounts / 1-ndc2011.coffee
Created June 21, 2012 21:03 — forked from anoras/1-ndc2011.coffee
NDC 2011 - Wake Up and Smell The Coffee
# This file contains brushed up version of all the examples [Anders Norås] programmed live during the talk.
# CoffeeScript compiles to JavaScript
numbers = [1,2,3,4] # No need for semicolons!
location = conference = "NDC 2011" # Multiple assigns.
awake = false
console.log location # No need for parens!
# Run, Build
@jamesrcounts
jamesrcounts / Examples.txt
Created June 12, 2012 22:53
A patch that updates ScrubPath to handle when the "text" parameter is null.
// I expected scrub path to handle null input. There is no reason to let the
// NullReferenceException to propogate, since Verify can handle nulls.
// This test will pass or fail based on the contents of approved.txt
[TestMethod]
public void MyTestMethod()
{
string file = null;
ApprovalTests.Approvals.Verify(file);
}