Skip to content

Instantly share code, notes, and snippets.

View mjul's full-sized avatar

Martin Jul mjul

View GitHub Profile
@mjul
mjul / IntegrationAttribute.cs
Last active December 16, 2015 22:29
Attributes to mark NUnit tests by category, so you can see how much environment they need set up and run them in the right order, for example: * Unit test (in-process), * Integration test (needs files, databases, network, services, or other out-of-process resources, but the System Under Test is limited to our own system) * SystemIntegrationTest …
using NUnit.Framework;
namespace DeveloperTest.TestHelpers
{
public class IntegrationAttribute : CategoryAttribute
{
public IntegrationAttribute()
: base("Integration")
{
}
@mjul
mjul / EqualityTesting.cs
Last active December 16, 2015 22:39
Test Helper for Equals and GetHashCode, checking that the Equals relation is an equivalence relation, meaning that it is Reflexive, Transitive and Symmetrical. Also tests equality operator overloading.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework;
namespace TestHelpers
{
public class EqualityTesting
@mjul
mjul / CompileModel.tt
Created May 23, 2013 16:00
Visual Studio T4 template that invokes an external compiler on a file in the project to generate a C# code file.
<#@ template debug="false" hostspecific="true" language="C#" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="System.Diagnostics" #>
<#@ assembly name="EnvDTE" #>
<#@ import namespace="EnvDTE" #>
<#@ output extension=".cs" #>
@mjul
mjul / DynamicLookup.cs
Created May 28, 2013 09:07
Using C# dynamic type to navigate a dictionary via dynamically generated properties corresponding to the dictionary's keys.
protected override University MapFromRow(Row input)
{
// Using dynamic so we can hit the TryGetMember on Row to look up
// missing properties (here: all of them) in the key-value map.
dynamic row = input;
return new University()
{
UniversityNumber = Int32.Parse(row.UniversityNumber),
Name = row.UniversityName,
};
@mjul
mjul / configure-sql-server.ps1
Created May 31, 2013 14:57
Limit the memory usage of SQL Server. We use it to set up developer PCs and other instances where a SQL Server should share the machine with other applications.
## Configure a SQL Server for running on a shared machine (set max memory)
Function Configure-SqlServer
{
<#
.Synopsis
Configure a SQL Server for use with Panda.
.Example
Configure-SqlServer .\SQLExpress
Configure the local SQL Server Express
@mjul
mjul / Microsoft.PowerShell_profile.ps1
Last active November 15, 2018 18:31
Visual Studio 2013 developer prompt for PowerShell
pushd 'c:\Program Files (x86)\Microsoft Visual Studio 12.0\VC'
cmd /c "vcvarsall.bat&set" |
foreach {
if ($_ -match "=") {
$v = $_.split("="); set-item -force -path "ENV:\$($v[0])" -value "$($v[1])"
}
}
popd
write-host "`nVisual Studio 2013 Command Prompt variables set." -ForegroundColor Yellow
@mjul
mjul / configure_cqrs_permissions.sql
Created June 28, 2013 11:29
SQL Server set up logins, users and roles for CQRS
--
-- http://dba.stackexchange.com/questions/2572/how-do-i-assign-an-entire-active-directory-group-security-access-in-sql-server-2
--
use master;
CREATE LOGIN [MyDomain\MyCoolApp Administrators] FROM WINDOWS WITH DEFAULT_DATABASE=[MyCoolApp];
GO
USE [MyCoolApp];
GO
@mjul
mjul / .gitattributes
Last active December 21, 2015 03:08
GIT .gitignore and .gitattributes for NuGet packages, ensuring that they are checked in completely and exactly as they are downloaded.
# Treat everything under packages as binary, except the config and git config files
* -text
/.gitattributes text=auto
/.gitignore text=auto
/repositories.config text=auto
@mjul
mjul / SQLxmlquery
Created September 24, 2013 14:41
From an XML document in SQL Server, extract the value of an XML node via an XML query. For example, to extract the TransactionId value as a Guid from the Metadata node on an XML document, do this:
SELECT
[Id]
,cast([EventData] as xml)
.value('(/*/*[local-name() = "Metadata"]/*[local-name() = "TransactionId"])[1]', 'uniqueidentifier') as txid
FROM [Playground].[command].[Events]
@mjul
mjul / gist:6932208
Created October 11, 2013 09:43
Base class (shudder) for unit testing .NET exceptions against the exception design guidelines
using System;
using DeveloperTest.TestHelpers;
using NUnit.Framework;
namespace DeveloperTest.Utilities
{
[TestFixture, Unit]
public abstract class ExceptionTestBase<TException> where TException : Exception
{
// According to the design guidelines for exceptions