Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
Coding!

Jeroen Heijmans jeroenheijmans

💭
Coding!
View GitHub Profile
@jeroenheijmans
jeroenheijmans / NHibernateUnitTests.cs
Last active Mar 20, 2016
Minmal Repro for NHibernate issues (SSCCE / MCVE)
View NHibernateUnitTests.cs
/* Gist for minimal repro for NHibernate issues
*
* 1. Create new (e.g. .NET 4.5.1) class library;
* 2. Add NHibernate (e.g. 4.0.3) via NuGet;
* 3. Add FluentNHibernate (e.g. 2.0.1) via NuGet;
* 4. Add NUnit (e.g. 2.6.4) via NuGet;
* 5. Create database "NhTestDb" on Sql Server "localhost" (or adjust for your specific situation);
* 6. Compile;
* 7. Run tests (should be green).
*
@jeroenheijmans
jeroenheijmans / DtoTests.cs
Created Mar 20, 2016
All Collection properties should be instantiated for types with empty constructors
View DtoTests.cs
using NUnit.Framework;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
namespace MyProject.Dto.Tests
{
[TestFixture]
View RegexForBadRethrows.txt
// This regex is a basic check to find all Catch{} blocks
// where a suspect throw statement is found (e.g. a state-
// ment that mucks up the call stack by doing `throw ex;`
// instead of `throw;`.
//
// It'll probably give false positives and have misses too.
catch[^{]*\{[^{]*throw[^;][^}]*}
@jeroenheijmans
jeroenheijmans / StringExtensions-Truncate.cs
Last active Nov 28, 2016
String Truncate method with test coverage
View StringExtensions-Truncate.cs
// CC-BY-SA 3.0, implementation by @LBushkin from http://stackoverflow.com/a/2776689/419956
public static class StringExtensions
{
public static string Truncate(this string value, int maxLength)
{
if (maxLength < 0) throw new ArgumentOutOfRangeException("maxLength");
if (string.IsNullOrEmpty(value)) return value;
return value.Length <= maxLength ? value : value.Substring(0, maxLength);
}
}
@jeroenheijmans
jeroenheijmans / windbg-commands.md
Last active Sep 2, 2016
WinDbg-ManagedThreads-Listing
View windbg-commands.md

Run these on the crash dump to get a listing of all CLR threads at the moment of the dump.

.loadby sos clr
~*e!clrstack
@jeroenheijmans
jeroenheijmans / DoubleVsDecimal.cs
Last active Dec 29, 2016
DoubleVsDecimal Test-Driven-Description
View DoubleVsDecimal.cs
namespace DoubleVsDecimal
{
using System;
using NUnit.Framework;
[TestFixture]
public class RangeTests
{
static readonly decimal[] interestingDecimals = new decimal[] {
decimal.MinValue,
@jeroenheijmans
jeroenheijmans / UploadMultipartForm.psm1
Created Jan 5, 2017
Powershell Module with cmdlet to upload files in a multipart-form POST
View UploadMultipartForm.psm1
<#
# It can be called like this:
$url ="http://localhost:12345/home/upload"
$form = @{ description = "Test 123." }
$pwd = ConvertTo-SecureString "s3cr3t" -AsPlainText -Force
$creds = New-Object System.Management.Automation.PSCredential ("john", $pwd)
Get-ChildItem *.txt | Send-MultiPartFormToApi $url $form $creds -Verbose -WhatIf
#>
@jeroenheijmans
jeroenheijmans / WCF-Minimal-Repro.cs
Created Jan 6, 2017
Minimal WCF host and client setup for WCF repros
View WCF-Minimal-Repro.cs
using System;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.Threading.Tasks;
namespace WcfMinimalTest
{
// WARNING! This minimal repro does no cleanup or error handling whatsoever!!
// Loosely based on http://stackoverflow.com/a/7833188/419956 by @Anuraj
View Microsoft.PowerShell_profile.ps1
# Normal, colored prompt:
#function Prompt
#{
# $promptString = "PS " + $(Get-Location) + ">"
# Write-Host $promptString -NoNewline -ForegroundColor Yellow
# return " "
#}
# Posh-Git prompt
function prompt {
@jeroenheijmans
jeroenheijmans / EntityFrameworkIntegrationTests.cs
Last active May 5, 2017
Entity Framework minimal integration tests setup
View EntityFrameworkIntegrationTests.cs
/*
* Create a new Class Library and copy/paste this file over the class1.cs file.
*
* On Package Mananager Console:
*
* @("MSTest.TestFramework","MSTest.TestAdapter","EntityFramework") | foreach { Install-Package $_ }
*
* Run `sqllocaldb c soquestion` to create the instance.
* Afterwards create database `TestDb` e.g. with SSMS on that instance.
*/