Skip to content

Instantly share code, notes, and snippets.

View bradwilson's full-sized avatar
🤘
All metal, all the time!

Brad Wilson bradwilson

🤘
All metal, all the time!
View GitHub Profile
@bradwilson
bradwilson / Example Output (grouped)
Created November 8, 2012 20:50
find-string.ps1: A PowerShell script to find strings
src\xunit\Sdk\Executor.cs
15: /// ExecutorWrapper instead.
src\xunit.runner.msbuild\Utility\XmlTestRunner.cs
8: public XmlTestRunner(IExecutorWrapper executorWrapper, IRunnerLogger logger)
10: testRunner = new TestRunner(executorWrapper, logger);
src\xunit.runner.msbuild\xunit.cs
98: using (ExecutorWrapper wrapper = new ExecutorWrapper(assemblyFilename, configFilename, ShadowCopy))
src\xunit.runner.msbuild\xunitproject.cs
48: using (ExecutorWrapper wrapper = new ExecutorWrapper(assembly.AssemblyFilename, assembly.ConfigFilename, assembly.ShadowCopy))
src\xunit.runner.tdnet\TdNetRunner.cs
[Fact]
public void Monkey()
{
string schema =
@"{
""id"": ""System.Version"",
""type"": ""object"",
""additionalProperties"": false,
""properties"": {
""Major"": {
@bradwilson
bradwilson / NameTaskReturningMethodAppropriately.cs
Last active December 15, 2015 11:09
FxCop rule to ensure that Task-returning methods are suffixed with 'Async'
using System.Runtime.CompilerServices;
using Microsoft.FxCop.Sdk;
namespace Tier3.FxCop.TaskRules
{
public class NameTaskReturningMethodAppropriately : BaseIntrospectionRule
{
public NameTaskReturningMethodAppropriately() :
base("NameTaskReturningMethodAppropriately",
"Tier3.FxCop.Rules",
@bradwilson
bradwilson / gist:6232391
Created August 14, 2013 15:53
IIndexedEnumerable (a non-grouped replacement for ILookup)
using System;
using System.Collections.Generic;
using System.Linq;
public interface IIndexedEnumerable<TKey, TValue>
{
TValue this[TKey key] { get; }
int Count { get; }
@bradwilson
bradwilson / AutoMockWebApiAttribute.cs
Created August 22, 2013 17:56
Auto-mock setup for Web API
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Web.Http;
using System.Web.Http.Controllers;
using System.Web.Http.Hosting;
using System.Web.Http.Routing;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
using NSubstitute;
Unhandled Exception: System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
at System.Collections.Generic.List`1.Enumerator.MoveNext()
at Ninject.Infrastructure.Language.ExtensionsForIEnumerableOfT.Map[T](IEnumerable`1 series, Action`1 action) in c:\Projects\Ninject\Maintenance2.2\ninject\src\Ninject\Infrastructure\Language\ExtensionsForIEnumerableOfT.cs:line 22
at Ninject.Activation.Caching.GarbageCollectionCachePruner.PruneCacheIfGarbageCollectorHasRun(Object state) in c:\Projects\Ninject\Maintenance2.2\ninject\src\Ninject\Activation\Caching\GarbageCollectionCachePruner.cs:line 83
at System.Threading.TimerQueueTimer.CallCallbackInContext(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at
@bradwilson
bradwilson / StandardTestKernel.cs
Created September 24, 2013 23:25
This is a very hacked together replacement kernel for when your tests are making lots of kernels across many threads, and you hit stack traces like these: https://gist.github.com/bradwilson/6691434 . It's not pretty, but it does the job. It steals the implementation of the cache pruner that's built into Ninject and wraps locks around manipulatio…
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using Ninject.Activation.Caching;
using Ninject.Components;
using Ninject.Modules;
namespace Ninject
{
@bradwilson
bradwilson / vs2013-normal-menus.ps1
Created November 2, 2013 16:55
Say goodbye to VS2013's SHOUTING MENUS
Set-ItemProperty -Path HKCU:\Software\Microsoft\VisualStudio\12.0\General -Name SuppressUppercaseConversion -Type DWord -Value 1
@bradwilson
bradwilson / gist:7997819
Created December 17, 2013 00:30
WTF is this supposed to mean!?
Test 'YourTestNameHere' failed:
System.ObjectDisposedException : Safe handle has been closed
at System.Runtime.InteropServices.SafeHandle.DangerousAddRef(Boolean& success)
at System.StubHelpers.StubHelpers.SafeHandleAddRef(SafeHandle pHandle, Boolean& success)
at System.Security.Cryptography.Utils.HashData(SafeHashHandle hHash, Byte[] data, Int32 cbData, Int32 ibStart, Int32 cbSize)
at System.Security.Cryptography.MD5CryptoServiceProvider.HashCore(Byte[] rgb, Int32 ibStart, Int32 cbSize)
at System.Security.Cryptography.HashAlgorithm.ComputeHash(Byte[] buffer)
@bradwilson
bradwilson / ModelStateDictionaryExtensions.cs
Last active January 4, 2016 12:59
Testing ModelStateDictionary with xUnit.net v2
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;
public static class ModelStateDictionaryExtensions
{
public static IEnumerable<string> ToErrors(this ModelStateDictionary dict)
{
return dict.OrderBy(kvp => kvp.Key)