Skip to content

Instantly share code, notes, and snippets.

@jameshulse
Last active January 8, 2016 16:07
Show Gist options
  • Save jameshulse/81771d6b10c9a96927f0 to your computer and use it in GitHub Desktop.
Save jameshulse/81771d6b10c9a96927f0 to your computer and use it in GitHub Desktop.

Revisions

  1. jameshulse renamed this gist Jan 8, 2016. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions MyTests.cs → TestingWithDependencies.cs
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    public class MyTests : TestKit
    public class TestingWithDependencies : TestKit
    {
    public MyTests()
    public TestingWithDependencies()
    {
    var dependencyResolver = new TestDependencyResolver();

  2. jameshulse created this gist Jan 8, 2016.
    11 changes: 11 additions & 0 deletions MyTests.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    public class MyTests : TestKit
    {
    public MyTests()
    {
    var dependencyResolver = new TestDependencyResolver();

    dependencyResolver.Register<MyActor>(Props.Create<MyActor>());

    Sys.AddDependencyResolver(dependencyResolver);
    }
    }
    33 changes: 33 additions & 0 deletions TestDependencyResolver.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    public class TestDependencyResolver : IDependencyResolver
    {
    private readonly Dictionary<Type, Props> _registrations = new Dictionary<Type, Props>();

    public void Register<T>(Props instance)
    {
    _registrations.Add(typeof(T), instance);
    }

    public Type GetType(string actorName)
    {
    throw new NotImplementedException();
    }

    public Func<ActorBase> CreateActorFactory(Type actorType)
    {
    return () => Create(actorType).NewActor();
    }

    public Props Create<TActor>() where TActor : ActorBase
    {
    return _registrations[typeof (TActor)];
    }

    public Props Create(Type actorType)
    {
    return _registrations[actorType];
    }

    public void Release(ActorBase actor)
    {
    }
    }