Created
June 6, 2013 15:26
-
-
Save akimboyko/5722397 to your computer and use it in GitHub Desktop.
Ninject.Extensions.Factory with parameters tested using FluentAssertions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Main() | |
{ | |
using(var kernel = new StandardKernel(new GameModule())) | |
{ | |
kernel.Load<FuncModule>(); | |
kernel | |
.Get<GameArtifact>() | |
.Should().NotBeNull(); | |
kernel | |
.Get<ISpinEvaluator>() | |
.Should().NotBeNull().And.BeOfType<DefaultSpinEvaluatorImpl>(); | |
kernel | |
.Get<IReelSpinner>() | |
.Should().NotBeNull().And.BeOfType<DefaultReelSpinnerImpl>(); | |
var _factory = kernel.Get<IGameOperationsFactory>(); | |
_factory.Should().NotBeNull(); | |
var gameArtifact = new GameArtifact(); | |
var spinEvaluator = _factory.GetSpinEvaluator(gameArtifact); | |
var reelSpinner = _factory.GetReelSpinner(gameArtifact); | |
spinEvaluator | |
.Should().NotBeNull() | |
.And.BeOfType<DefaultSpinEvaluatorImpl>() | |
.And.Match(se => (se as DefaultSpinEvaluatorImpl).GameArtifact.UniqueId == gameArtifact.UniqueId); | |
reelSpinner | |
.Should().NotBeNull() | |
.And.BeOfType<DefaultReelSpinnerImpl>() | |
.And.Match(se => (se as DefaultReelSpinnerImpl).GameArtifact.UniqueId == gameArtifact.UniqueId); | |
} | |
} | |
public class GameArtifact | |
{ | |
public readonly Guid UniqueId; | |
public GameArtifact() | |
{ | |
UniqueId = Guid.NewGuid(); | |
} | |
} | |
public interface ISpinEvaluator { } | |
public class DefaultSpinEvaluatorImpl : ISpinEvaluator | |
{ | |
public readonly GameArtifact GameArtifact; | |
public DefaultSpinEvaluatorImpl(GameArtifact gameArtifact) | |
{ | |
GameArtifact = gameArtifact; | |
} | |
} | |
public interface IReelSpinner { } | |
public class DefaultReelSpinnerImpl : IReelSpinner | |
{ | |
public readonly GameArtifact GameArtifact; | |
public DefaultReelSpinnerImpl(GameArtifact gameArtifact) | |
{ | |
GameArtifact = gameArtifact; | |
} | |
} | |
public interface IGameOperationsFactory | |
{ | |
ISpinEvaluator GetSpinEvaluator(GameArtifact gameArtifact); | |
IReelSpinner GetReelSpinner(GameArtifact gameArtifact); | |
} | |
public class GameModule : NinjectModule | |
{ | |
public override void Load() | |
{ | |
Bind<ISpinEvaluator>() | |
.To<DefaultSpinEvaluatorImpl>() | |
.Named("SpinEvaluator"); | |
Bind<IReelSpinner>() | |
.To<DefaultReelSpinnerImpl>() | |
.Named("ReelSpinner"); | |
Bind<IGameOperationsFactory>() | |
.ToFactory(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment