Skip to content

Instantly share code, notes, and snippets.

View DaveGreasley's full-sized avatar

Dave Greasley DaveGreasley

View GitHub Profile
@DaveGreasley
DaveGreasley / UnitTesting.NoClassLevelVariables.TestContext.cs
Last active October 30, 2015 00:36
An example of how to use a TestContext class to reuse test setup code
[TestClass]
public class CacheTests
{
[TestMethod]
public void TestCountReturnsTwoWhenTwoOjectsAdded()
{
var testContext = new TestContext();
var testData1 = new object();
var testData2 = new object();
@DaveGreasley
DaveGreasley / UnitTesting.NoClassLevelVariables.BadExample.Tests.cs
Last active October 30, 2015 01:28
An example of why not to use class level variables in unit tests
[TestClass]
public class CacheTests
{
private Cache testCache;
public CacheTests()
{
this.testCache = new Cache();
}
@DaveGreasley
DaveGreasley / BackofficeUserHelper.cs
Last active December 29, 2017 19:08
A helper class for Umbraco 7+ to get the currently logged on back office user from a non-backoffice context.
/// <summary>
/// A helper class for Umbraco 7+ to get the currently logged on back office user from a non-backoffice context.
/// </summary>
public static class BackofficeUserHelper
{
const string BackofficeIdentityKey = "UmbracoBackofficeIdentity";
/// <summary>
/// The <c>UmbracoBackOfficeIdentity</c> representing the currently logged on Back Office user
/// </summary>