Skip to content

Instantly share code, notes, and snippets.

@jamesrcounts
jamesrcounts / verifylogs.cs
Last active August 29, 2015 14:06
Verify Log4Net logs
public static void VerifyLog(Action code)
{
var memoryAppender = new MemoryAppender();
BasicConfigurator.Configure(memoryAppender);
code.Invoke();
var aggregate = memoryAppender.GetEvents().Aggregate(
string.Empty,
(s, @event) => s + Environment.NewLine + @event.RenderedMessage);
Approvals.Verify(aggregate);
@jamesrcounts
jamesrcounts / boot.bat
Last active June 26, 2023 06:36
Scripted rabbitmq install
@powershell -ExecutionPolicy unrestricted .\bootmq.ps1
@jamesrcounts
jamesrcounts / WebApiApprovals.cs
Created September 8, 2014 21:12
WebApi Route Test
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text;
using System.Web.Http;
using ApprovalTests;
using ApprovalUtilities.Utilities;
@jamesrcounts
jamesrcounts / EF6.cs
Created August 14, 2014 16:10
EF6 Adapter, works with CodeFirst. Main difference is the namespaces. Also, better error checking
namespace ApprovalTests.Persistence.EntityFramework.Version6
{
using System;
using System.Data.Common;
using System.Data.Entity;
using System.Data.Entity.Core.EntityClient;
using System.Data.Entity.Core.Objects;
using System.Data.Entity.Infrastructure;
using System.Linq;
using System.Reflection;
@jamesrcounts
jamesrcounts / DataQueryAdaptor.cs
Created August 11, 2014 21:54
LINQ to SQL adapter for ApprovalTests
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data.Common;
using System.Data.Linq;
using System.Data.Linq.SqlClient;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
@jamesrcounts
jamesrcounts / IAsyncSaver.cs
Created July 25, 2014 16:12
A more convenient way to write a saver when you want async
// New interface...
using System.Threading.Tasks;
public interface IAsyncSaver<T>
{
Task<T> Save(T item);
}
// Old way...
@jamesrcounts
jamesrcounts / NotNullable.cs
Created October 16, 2013 21:14
Something guaranteed not to be null, opposite of Nullable<T>
using System;
using System.Diagnostics.Contracts;
public struct NonNullable<T> where T : class
{
private readonly T data;
public NonNullable(T data)
{
if (data == null)
@jamesrcounts
jamesrcounts / StackTraceScrubber.cs
Last active December 23, 2015 07:39
Methods to scrub stack traces, and a Verifier that applies the scrubbers as a workaround until Approvals.Verify gets support for scrubbers.
public static class StackTraceScrubber
{
public static string ScrubAnonymousIds(string source)
{
var regex = new Regex(@"\w+__\w+");
return regex.Replace(source, string.Empty);
}
public static string ScrubLineNumbers(string source)
{
@jamesrcounts
jamesrcounts / EmptyIfNull.cs
Created August 20, 2013 17:15
Don't get bit by null collections
public static IEnumerable<TMembers> EmptyIfNull<TMembers>(this IEnumerable<TMembers> source)
{
return source ?? Enumerable.Empty<TMembers>();
}
@jamesrcounts
jamesrcounts / AutoTestReporter.cs
Created February 14, 2013 22:01
A MightyMoose reporter suitable for front loading.
using System.Linq;
using ApprovalTests.Core;
namespace ApprovalTests.Reporters
{
public class AutoTestReporter : IEnvironmentAwareReporter
{
public static readonly AutoTestReporter INSTANCE = new AutoTestReporter();
public void Report(string approved, string received)