Skip to content

Instantly share code, notes, and snippets.

@heemskerkerik
heemskerkerik / Calculator.fs
Created Jan 24, 2020
A simple string calculator in F#
View Calculator.fs
namespace Calculator
open System
module Calculator =
type Operator =
| Add
| Subtract
| Multiply
| Divide
@heemskerkerik
heemskerkerik / Calculator.feature
Created May 2, 2019
F# BDD tests using TickSpec and FsUnit
View Calculator.feature
Feature: Calculator
Scenario: Adding numbers
Given there is a calculator
And the user entered 2 in the calculator
And the user selected + as the operation
And the user entered 2 in the calculator
When the user presses the = button
Then the calculator shows 4 as the result
@heemskerkerik
heemskerkerik / ForwardedHeadersTest.csproj
Last active Mar 13, 2019
Test program to reproduce an issue with the way X-Forwarded-For is handled by ForwardedHeadersMiddleware
View ForwardedHeadersTest.csproj
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" />
</ItemGroup>
@heemskerkerik
heemskerkerik / TestHang.csproj
Last active Jul 30, 2018
Test Hang Repro Project
View TestHang.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net462</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
<PackageReference Include="NUnit" Version="3.10.1" />
<PackageReference Include="NUnit3TestAdapter" Version="3.10.0" />
@heemskerkerik
heemskerkerik / DispatchBenchmark.cs
Created Nov 24, 2017
Benchmark of different double dispatch methods in C#
View DispatchBenchmark.cs
// depends on BenchmarkDotNet 0.10.10
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Attributes.Jobs;
using BenchmarkDotNet.Running;
@heemskerkerik
heemskerkerik / EventSourcedBase.cs
Created Jan 16, 2017
A number of ways to implement an event-sourced base class
View EventSourcedBase.cs
public interface IEventSourced
{
IReadOnlyCollection<object> AppendedEvents { get; }
void ReplayEvent(object @event);
}
public abstract class EventSourcedBase: IEventSourced
{
protected void AppendEvent<T>(T @event)
{
@heemskerkerik
heemskerkerik / AppointmentRescheduling.feature
Last active Nov 3, 2016
Testing an event-sourced object's behavior using Cucumber
View AppointmentRescheduling.feature
Scenario: Reschedule an appointment
Given an appointment was created for 2016-11-03T13:00 until 2016-11-03T14:00 called Appointment
And the appointment was renamed to Renamed appointment
When we reschedule the appointment to 2016-11-03T15:00 until 2016-11-03T16:00
Then an AppointmentRescheduled event is appended with the following properties:
| Start time | End time |
| 2016-11-03T15:00 | 2016-11-03T16:00 |
@heemskerkerik
heemskerkerik / EventSourcedBehaviorTest.cs
Last active Nov 3, 2016
Testing an event-sourced object's behavior
View EventSourcedBehaviorTest.cs
private AppointmentCreated CreateAppointmentCreatedEvent()
{
return new AppointmentCreated(
appointmentId: Guid.NewGuid(),
startTime: DateTimeOffset.Now.AddHours(3),
endTime: DateTimeOffset.Now.AddHours(4),
title: "Appointment");
}
private AppointmentRenamed CreateAppointmentRenamedEvent()
@heemskerkerik
heemskerkerik / FluentAssertionsShouldBeEquivalentToTest.cs
Created Dec 16, 2015
Failing test for FluentAssertions (tested with 4.1.1, but seen in earlier versions as well). When explicitly using Including(), another property with a similar name is also matched, and the match subsequently fails.
View FluentAssertionsShouldBeEquivalentToTest.cs
using FluentAssertions;
using Xunit;
// ReSharper disable InconsistentNaming
namespace FluentAssertionsBugProof
{
public class ShouldBeEquivalentToTest
{
[Fact]
@heemskerkerik
heemskerkerik / OAuthReadOnlyAuthenticationBatchLoadTest.cs
Last active Oct 29, 2015
RavenDB test: Batch-loading when using read-only API key authentication
View OAuthReadOnlyAuthenticationBatchLoadTest.cs
using System.Linq;
using Raven.Abstractions.Data;
using Raven.Client.Document;
using Raven.Database.Config;
using Raven.Tests.Helpers;
using Xunit;
// ReSharper disable InconsistentNaming
namespace Raven.ReadOnlyBatchLoadFailure
You can’t perform that action at this time.