Skip to content

Instantly share code, notes, and snippets.

View damianh's full-sized avatar
💥

Damian Hickey damianh

💥
View GitHub Profile
namespace Microsoft.Owin.Testing.Tests
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Xunit;
public class TestServerTests
{
@damianh
damianh / FastInMemoryPersistenceEngine.cs
Last active December 14, 2015 22:49
Alternative InMemory Eventstore persistence engine that does not contain statics and better performing. For the log statements, supply your own resources or remove them.
/*
Usage:
_storeEvents = Wireup
.Init()
.UsingFastInMemoryPersistence()
.InitializeStorageEngine()
.etc...
*/
// ReSharper disable CheckNamespace
@damianh
damianh / WebApplication.cs
Last active December 11, 2015 04:39
WebApplication.Start suggestion
public interface IWebApplication : IDisposable
{
public Func<IDictionary<string, object>, Task> AppFunc { get; }
public string Url { get; }
}
// Start an app listen = false so that it is pure in-proc for testing.
using(IWebApplication webApp = WebApplication.Start(
builder => builder.UseThing(_foo),
@damianh
damianh / gist:4215137
Created December 5, 2012 12:26
RavenDB Contains Query Test
public class ContainsQueryTests : IDisposable
{
private readonly IDocumentStore _documentStore;
public ContainsQueryTests()
{
_documentStore = new EmbeddableDocumentStore {RunInMemory = true}.Initialize();
using (IDocumentSession session = _documentStore.OpenSession())
{
session.Store(new TestDocument
@damianh
damianh / gist:4214487
Created December 5, 2012 10:14 — forked from SimonCropp/gist:4214439
LogParamsOnException
Before
public class SimpleClass
{
[LogParamsOnException(LogLevel.Info)]
void Method(string param1, int param2)
{
//Do Stuff
}
@damianh
damianh / gist:3839789
Created October 5, 2012 13:23
Send all Raven logs to null target
var config = new LoggingConfiguration();
var nullTarget = new NullTarget();
config.AddTarget("NullTarget", nullTarget);
config.LoggingRules.Add(new LoggingRule("Raven.*", LogLevel.Debug, nullTarget) { Final = true });
@damianh
damianh / gist:3722548
Created September 14, 2012 15:15
Nancy on Microsoft.HttpListener.Owin
using System;
using System.Collections.Generic;
using Microsoft.HttpListener.Owin;
using Nancy.Hosting.Owin;
namespace Spike
{
internal class Program
{
private static void Main(string[] args)
@damianh
damianh / gist:1825986
Created February 14, 2012 11:22
Storage (Repository Discussion)
//Guard clauses / contracts omitted for berivity
//Thread safety not considered.
public interface IKeyValueStore
{
void Add<T>(string key, T item);
void AddOrUpdate<T>(string key, T item);
bool Remove(string key);
@damianh
damianh / gist:1825707
Created February 14, 2012 10:42
Storage (Repository Discussion)
namespace WinPhoneKit.Storage
{
using System;
using System.IO.IsolatedStorage;
public static class IsolatedStorage
{
private static readonly IsolatedStorageSettings isolatedStorage = IsolatedStorageSettings.ApplicationSettings;
public static void Add<TEntity>(string key, TEntity entity)
@damianh
damianh / gist:1673072
Created January 24, 2012 22:17
Fleck and WebSocket4Net
private static void Main(string[] args)
{
var server = new WebSocketServer("ws://127.0.0.1:8181");
server.Start(socket =>
{
socket.OnOpen = () => Console.WriteLine("Open!");
socket.OnClose = () => Console.WriteLine("Close!");
socket.OnError = ex => Console.WriteLine("Server: " + ex);
socket.OnMessage = message =>
{