Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / boot.bat
Last active June 26, 2023 06:36
Scripted rabbitmq install
@powershell -ExecutionPolicy unrestricted .\bootmq.ps1
@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 / MySqlCommandAdapter.cs
Created October 3, 2014 02:42
IDatabaseToExecuteableQueryAdaptor for MySql
// Note: Connection string must include the following option: Allow User Variables=True
using System;
using System.Data.Common;
using System.Linq;
using ApprovalUtilities.Persistence.Database;
using MySql.Data.MySqlClient;
public class MySqlCommandAdapter : IDatabaseToExecuteableQueryAdaptor
@jamesrcounts
jamesrcounts / VerifyConfig.cs
Last active August 29, 2015 14:07
Approve app.config
private static void VerifyConfig(string path, Action<Configuration> action)
{
using (var t = new TempFile(Path.GetRandomFileName()))
{
File.Copy(path, t.File.FullName, true);
var fileMap = new ExeConfigurationFileMap { ExeConfigFilename = t.File.FullName };
var exeConfig = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
action.Invoke(exeConfig);
var config = File.ReadAllText(exeConfig.FilePath);
Approvals.Verify(config);
@jamesrcounts
jamesrcounts / starter.cmd
Last active August 29, 2015 14:10
My Boxstarter Script
Set-WindowsExplorerOptions -EnableShowHiddenFilesFoldersDrives -EnableShowProtectedOSFiles -EnableShowFileExtensions
choco install VisualStudio2013Ultimate
choco install googlechrome
choco install sublimetext2
choco install console2
choco install sourcecodepro
choco install resharper
choco install stylecop
choco install git-credential-winstore