Skip to content

Instantly share code, notes, and snippets.

public class Approvals
{
public static void Verify(string text, [CallerFilePath] string callerFilePath = null, [CallerMemberName] string callerName = null)
{
string approvedText = null;
string filePath = BuildApprovalFilePath(callerFilePath, callerName);
var approvedFilePath = filePath + ".approved.txt";
var receivedFilePath = filePath + ".received.txt";
if (File.Exists(approvedFilePath))
{
public struct AllocatedLock : IDisposable
{
private readonly object _toLock;
public AllocatedLock(object toLock)
{
_toLock = toLock;
}
public void Dispose()
@mscottreed
mscottreed / ActualTest.cs
Last active November 28, 2015 18:36
EF Logging
public void TestIndex()
{
var memoryTarget = TestLoggingExtensions.SetupNLogMemoryTarget();
var controller = new PollsController();
controller.Index();
Approvals.VerifyAll(memoryTarget.Logs.FilterOutMigrationLogs(), "log");
}
@mscottreed
mscottreed / DateTimeProvider.cs
Last active October 10, 2015 00:38
DateTimeProvider and friends
public abstract class DateTimeProvider
{
public static DateTimeProvider Current = new DefaultDateTimeProvider();
public abstract DateTime UtcNow { get; }
}
public class DefaultDateTimeProvider : DateTimeProvider
{
public override DateTime UtcNow
{
@mscottreed
mscottreed / DelegateCommand.cs
Created June 24, 2015 11:20
DelegateCommand
public class DelegateCommand<T> : ICommand
{
readonly Func<T, bool> canExecute = _ => true;
readonly Action<T> executeAction;
bool canExecuteCache;
public DelegateCommand(Action<T> executeAction, Func<T, bool> canExecute)
{
this.executeAction = executeAction;
@mscottreed
mscottreed / index.html
Created April 21, 2015 21:43
Angular - Highlight Using Filter
<!DOCTYPE html>
<html>
<head>
<title>AngularJS Tutorials</title>
<link rel="stylesheet" href="//cdn.jsdelivr.net/foundation/5.4.7/css/foundation.css">
<style>
.highlight {
color:red;
background-color:yellow;
}