Skip to content

Instantly share code, notes, and snippets.

using System;
using System.ServiceModel;
using System.ServiceModel.Channels;
/// <summary>
/// Wraps a service client so you can use "using" without worrying of getting
/// your business exception swallowed. Usage:
/// <example>
/// <code>
/// using(var serviceClient = new ServiceClientWrapper&lt;IServiceContract&gt;)
/// <summary>
/// Resolves instances using the structure map object factory.
/// </summary>
public class StructureMapInstanceProvider : IInstanceProvider
{
/// <summary>
/// The service type
/// </summary>
private readonly Type serviceType;
@ewilde
ewilde / FooContainer.cs
Created January 23, 2013 16:03
How to test #structuremap configuration using #mspec
[Subject(typeof (CommonRegistry))]
public class When_add_common_registry_to_a_container
{
Because of = () => ObjectFactory.Configure(x=>x.Scan(scanner=>
{
scanner.AssemblyContainingType<ISerializer>();
scanner.LookForRegistries();
}));
It should_register_a_default_i_serializer = () => ObjectFactory.GetAllInstances<ISerializer>().Count.ShouldBeGreaterThan(0);
@ewilde
ewilde / WithConcreteSubject.cs
Created January 16, 2013 08:41
Machine.fakes class that enables you to program your tests against an interface, but have the SUT created as a concrete type with dependencies auto faked. #mspec
using System.Diagnostics.CodeAnalysis;
using global::Machine.Fakes;
using global::Machine.Specifications;
/// <summary>
/// Casts the subject as the supplied <typeparamref name="TInterface"/> but
/// creates it using a concrete type and fills in dependencies using the auto faking container.
/// </summary>
/// <typeparam name="TInterface">The type of the interface.</typeparam>
/// <typeparam name="TConcreteType">The type of the concrete type.</typeparam>