Skip to content

Instantly share code, notes, and snippets.

@derekgreer
Created July 22, 2011 22:49
Show Gist options
  • Save derekgreer/1100617 to your computer and use it in GitHub Desktop.
Save derekgreer/1100617 to your computer and use it in GitHub Desktop.
Monarchy Refactored Specs
using Machine.Specifications;
namespace Monarchy.Specs
{
[Subject(typeof(ObjectFactory))]
public class when_retrieving_a_type_with_registered_dependency_factory
{
static TestService _instance;
static ObjectFactory _factory;
Establish context = () =>
{
_factory = new ObjectFactory();
_factory.Register<IDependencyService>(() => new DependencyServiceImpl());
};
Because of = () => _instance = _factory.Get(typeof(TestService)) as TestService;
It should_return_the_instance = () => _instance.ShouldNotBeNull();
It should_inject_dependency = () => _instance.DependencyService.ShouldNotBeNull();
}
[Subject(typeof (ObjectFactory))]
public class when_retrieving_a_type_with_registered_dependency_factory_with_generic_overload
{
static TestService _instance;
static ObjectFactory _factory;
Establish context = () =>
{
_factory = new ObjectFactory();
_factory.Register<IDependencyService>(() => new DependencyServiceImpl());
};
Because of = () => _instance = _factory.Get<TestService>();
It should_return_the_instance = () => _instance.ShouldNotBeNull();
It should_inject_dependency = () => _instance.DependencyService.ShouldNotBeNull();
}
[Subject(typeof (ObjectFactory))]
public class when_retrieving_a_type_with_a_registered_dependency_type
{
static TestService _instance;
static ObjectFactory _factory;
Establish context = () =>
{
_factory = new ObjectFactory();
_factory.Register<IDependencyService, DependencyServiceImpl>();
};
Because of = () => _instance = _factory.Get<TestService>();
It should_return_the_instance = () => _instance.ShouldNotBeNull();
It should_inject_dependency = () => _instance.DependencyService.ShouldNotBeNull();
}
public class TestService
{
public readonly IDependencyService DependencyService;
public TestService()
{
}
public TestService(IDependencyService dependencyService)
{
DependencyService = dependencyService;
}
}
public interface IDependencyService
{
}
public class DependencyServiceImpl : IDependencyService
{
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment