Skip to content

Instantly share code, notes, and snippets.

@grumpydev
grumpydev / PathHelper.cs
Created January 4, 2011 15:26
Helper class to try to convert an absolute path to one relative to another path
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace AbsoluteToRelativePathTest
{
public static class PathHelper
{
@grumpydev
grumpydev / DefaultNancyBootStrapper.cs
Created January 17, 2011 12:50
Default types are now protected fields which, when the bootstrapper GetEngine is called, are turned into TRegisterType, TImplementation type combos which are then passed into the bootstrapper for the container to register. Changing a default implementatio
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TinyIoC;
using Nancy.BootStrapper;
using Nancy.Routing;
namespace Nancy
{
public interface IAbstractThings
{
dynamic DoThings(params dynamic[] arguments);
}
[TestMethod]
public void ProcessMessage_LowerPacketSequenceNumberWithDifferentHandsetUid_RaisesBothEvents()
{
var mockEventDispatcher = A.Fake<IDeviceEvents>();
var fakeMessage1 = new HardwareMessage(MessageType.ReportKeyValue, 0, GetButtonPressParameters(1, 2, HardwareButton.BlueCircle));
var fakeMessage2 = new HardwareMessage(MessageType.ReportKeyValue, 0, GetButtonPressParameters(2, 1, HardwareButton.BlueCircle));
_ReportKeyValueHandler.ProcessMessage(_FakeDevice, mockEventDispatcher, fakeMessage1);
_ReportKeyValueHandler.ProcessMessage(_FakeDevice, mockEventDispatcher, fakeMessage2);
[Fact]
public void Should_support_implicit_casting_of_properties_to_guids_in_method_params()
{
dynamic parameters = new DynamicDictionary();
var guid = Guid.NewGuid();
parameters["test"] = guid;
Guid value = this.GetGuid(parameters["test"]);
value.ShouldEqual(guid);
@grumpydev
grumpydev / RxAsyncTesting.cs
Created January 28, 2011 13:26
Using Rx to help Async testing
// The class under test (a "device") has one background thread which monitors the (fake) serial port for incoming
// data and places it on a queue for a second background thread to pickup, process and respond to.
//
// Normally I'd have to test this with Thread.Sleep, which is not only ugly, but also slows down every test as the
// sleep time would have to be long enough so machines under heavy load didn't fail.
//
// With Rx I can setup an observable on my fake serial port "Data Written" event and tell it to wait up to 5 seconds
// to receive and event of the correct type. Then I can simply pull those chunks of data out of the enumerable
// it produces and assert on them as normal.
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace IndexerTest
{
class Program
{
using Microsoft.Practices.Unity;
using Nancy.ViewEngines;
namespace Nancy.Bootstrappers.Unity
{
public class UnityEnumerableShim<T> : IEnumerable<T>
{
private IUnityContainer container;
public UnityEnumerableShim(IUnityContainer container)
namespace Pipelines
{
using System;
using System.Collections.Generic;
using System.Linq;
public class CancellablePipeline<TPipelineDelegateType, TReturnType>
where TReturnType : class
{
public CancellablePipeline()
namespace Nancy.Bootstrapper
{
using System;
using System.Collections.Generic;
using System.Linq;
using Nancy.Routing;
using Nancy.Extensions;
/// <summary>
/// Base class for container based Bootstrappers.