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 / 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 / DictionaryAsserts.cs
Created December 4, 2013 23:23
New custom assertions for xUnit.net v2, for developers using the source-based (extensible) assert library via the xunit.assert.source NuGet package
using System;
using System.Collections.Generic;
using System.Linq;
using Xunit.Sdk;
namespace Xunit
{
public partial class Assert
{
/// <summary>
@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 / Test Collections.md
Last active October 8, 2022 04:12
Using test collections in xUnit.net v2

Test collections are the test grouping mechanism in xUnit.net v2. They serve two purposes:

  1. They delineate the "parallelism" boundary; that is, tests in the same collection will not be run in parallel against each other;
  2. They offer collection-wide fixtures through the use of ICollectionFixture<TFixtureType>.

The simplest way to use test collections is simply by name. Put two classes into the same named collection, and they can derive benefit #1 above:

[Collection("MyCollection")]
public class TestClass1
@bradwilson
bradwilson / Cacheability.cs
Created January 23, 2014 20:53
Using chaining to create cached results in ASP.NET Web API v2
public enum Cacheability
{
NoCache,
Private,
Public,
}
@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)
public struct Maybe<T>
{
public static readonly Maybe<T> NoValue;
public Maybe(T value, bool hasValue = true) : this()
{
HasValue = hasValue;
Value = value;
}
@bradwilson
bradwilson / gist:9276064
Created February 28, 2014 17:53
Using Expression<T> with data theories for better output display in xUnit.net
public static IEnumerable<object[]> ExpirationMethods
{
get
{
return new TheoryDataSet<Expression<Action<Cache>>>
{
cache => cache.Clock.UtcNow.Returns(BaseTime + cache.Duration),
cache => cache.Expire()
};
}
@bradwilson
bradwilson / gist:9457177
Last active August 29, 2015 13:57
Release notes for xUnit.net v2 Build 2595

There have been significant changes in the latest alpha build of xUnit.net. Some of these changes will cause compilation errors for developers upgrading from previous alpha builds (as well as v1).

New Features for Test Authors

Support for tests in Windows 8, Windows Phone 8, and PCLs

This release has added support for writing unit tests in several new class library formats: Windows 8 class libraries, Windows Phone 8 class libraries, and Portable Class Libraries that target either of those (plus Desktop .NET 4.5). The runners that we supply can run those tests, although they are currently run in the desktop CLR. Three assemblies have been converted to PCLs as a result: xunit.abstractions.dll, xunit.assert.dll, and xunit.core.dll. The rest of the DLLs remain in their current configuration of supporting either Desktop .NET 3.5 or 4.5.

Adding support for MaxParallelThreads

@bradwilson
bradwilson / gist:11388191
Last active August 29, 2015 14:00
Release notes for xUnit.net v2 Beta 2