Skip to content

Instantly share code, notes, and snippets.

View mcintyre321's full-sized avatar

Harry McIntyre mcintyre321

View GitHub Profile
@mcintyre321
mcintyre321 / gist:08b086153f17471b08ba
Last active September 24, 2020 15:03
Testing glossary

Test scopes

  • Unit test - an isolated test around a single 'unit' of code, although that can be anything from a method to a class to a series of (related) classes.
  • Component test - same as a unit test
  • Isolated test - a test that doesn't do any I/O, i.e. the Ports have been filled with in-memory Adapters
  • Integration test - a test that interacts with deployed instances of the code and related services, possiby with some Test Doubles (mocked/faked/stubbed etc).
  • End to End test - a test that entirely interacts with deployed instances using public interfaces
  • Test-per-class - a convention that there should be one unit test for each class

Uses of tests

@mcintyre321
mcintyre321 / gist:6294588
Last active October 4, 2019 00:02
Replacing a case-sensitive methods in an Expression Tree with a case-insensitive equivalents using QueryInterceptor. Very cool! This is runnable in LinqPad if you add the QueryInterceptor Nuget package
void Main()
{
var words = new []{"HELLO"}.AsQueryable().SetComparer(StringComparison.CurrentCultureIgnoreCase);
words.Where (x => x.StartsWith("hel")).Dump();
words.Where (x => x.Contains("ell")).Dump();
words.Where (x => x.EndsWith("llo")).Dump();
words.Where (x => x.Equals("hello")).Dump();
words.Where (x => x == "hello").Dump();
@mcintyre321
mcintyre321 / Comment.cs
Last active January 8, 2019 10:03
Siren from IQueryable
namespace _10PrintHello.Apps.Things.SirenTables
{
public class Comment
{
public int postId { get; set; }
[Sortable]
public int id { get; set; }
[Sortable]
@mcintyre321
mcintyre321 / gist:5bb6291dfe41054b7393394c46a792ff
Last active April 11, 2018 15:54
ways to improve your c# code
  • use nsdepcop instead of project dependencies for layering so you can keep things in the same project
  • generic action result in controllers instead of base type
  • explicitly register your controllers rather than letting Controller Activator use them
  • ditch your IOC container entirely
  • use ValueOf for ids instead of ints
  • hard code all non-secret config values each environment in your source code (using code, not json) and choose the right one based off a single 'env' variable
  • use OneOf instead of custom Result objects/ Exceptions for control flow
  • partition by feature vertical, not layer
  • use delegates for your ports/adapters
  • isolate your domain and use composition root
@mcintyre321
mcintyre321 / tryjsil.cs
Created December 13, 2016 11:44
JSIL LINQ error
using System;
using JSIL;
using JSIL.Meta;
using System.Collections.Generic;
using System.Linq;
public static class Program {
public static void Main () {
Dictionary<string, string[]> data = new Dictionary<string, string[]>(){
.request{
background-color: aliceblue;
}
.response.status200{
background-color: f5fff0
}
@mcintyre321
mcintyre321 / Linqpad script.cs
Last active May 18, 2016 14:58
Simple Event Sourcing using NMF
void Main()
{
var events = new ObservableCollection<Event>();
var state = new NotifyCollection<object>();
events.OnAdd(next =>
{
if (next is UserWasAdded)
{
void Main()
{
var x = XDocument.Load(@"...\packages.config")
.Document.Root.Elements().Select (r => r.Attribute("id").Value)
.Select (r => {
var cq = CsQuery.CQ.CreateFromUrl("https://www.nuget.org/packages/" + r);
return new{
Package = r,
License = cq[".licenseName"].Html(),
LicenseUrl = cq["a"].Single (el => el.InnerText == "License")["href"]
<?php
use
Sabre\DAV;
//ini_set('display_errors', '1');
if (isset($_SERVER['HTTP_X_ORIGINAL_URL']))
{
$_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_ORIGINAL_URL'];
if (!isset($_SERVER['REQUEST_URI'])) {
PROPFIND http://sabre.127.0.0.1.xip.io/ HTTP/1.1
Connection: TE
TE: trailers
Host: sabre.127.0.0.1.xip.io
Depth: 0
Content-Length: 159
Content-Type: application/xml
<?xml version="1.0" encoding="utf-8"?>
<propfind xmlns="DAV:"><prop>