public void DoGetAllInstances_Gets_Expected_IEmumerable() { var ioc = new MatchBox(); ioc.RegisterCollection( new List <Func <ISimpleClass> > { () => new SimpleClass { Index = 1 }, () => new SimpleClass { Index = 2 }, () => new SimpleClass { Index = 3 } }); var simpleClasses = ioc.DoGetAllInstances(typeof(ISimpleClass)).Cast <ISimpleClass>().ToList(); Assert.IsTrue(simpleClasses.Count == 3 && simpleClasses[0].Index == 1 && simpleClasses[1].Index == 2 && simpleClasses[2].Index == 3); }
public void Register_singleton_DoesNot_Call_constructor() { var ioc = new MatchBox(); var dependency = Substitute.For <IDependency>(); ioc.RegisterSingleton(() => new ClassWithDependency(dependency)); dependency.DidNotReceive().Write(); }
public void Register_View_RegistersBothPublicAndImplementationType() { var ioc = new MatchBox(); ioc.RegisterView <ISimpleClass, SimpleClass>(() => new SimpleClass()); var simpleClassA = ioc.Get <ISimpleClass>(); var simpleClassB = ioc.Get <SimpleClass>(); }
public void Relocate(MatchBox matchBox) { IEnumerable <Room> possibleRooms = rooms.Values.Where(r => r != currentRoom && r.FreeMatchSpawnPoint); Room nextLocation = possibleRooms.ElementAt(UnityEngine.Random.Range(0, possibleRooms.Count())); nextLocation.Place(matchBox); }
static void Main(string[] args) { var Ioc = new MatchBox(); ConfigureServices(Ioc); var game = Ioc.Get <IGame>(); game.StartGame(); }
private static void ConfigureServices(MatchBox Ioc) { Ioc.RegisterSingleton <IBoard, OXBoard>(); Ioc.Register <ILineService, LineService>(); Ioc.Register <IOutputInputService, ConsoleService>(); Ioc.Register <IGameScorer, GameScorer>(); Ioc.Register <IMoveHandler, MoveHandler>(); Ioc.Register <IGame, Game>(); }
public void Get_T_Returns_T() { var ioc = new MatchBox(); ioc.Register(() => new SimpleClass()); var simpleClass = ioc.Get <SimpleClass>(); Assert.IsInstanceOfType(simpleClass, typeof(SimpleClass)); }
public void RegisterSingleton_Gets_A_singleton() { var ioc = new MatchBox(); ioc.RegisterSingleton <ISimpleClass>(() => new SimpleClass()); var singletonA = ioc.Get <ISimpleClass>(); var singletonB = ioc.Get <ISimpleClass>(); Assert.AreEqual(singletonA, singletonB); }
public void Register_View_As_Singleton_Gets_A_Singleton() { var ioc = new MatchBox(); ioc.RegisterViewAsSingleton <ISimpleClass, SimpleClass>(() => new SimpleClass()); var simpleClassA = ioc.Get <ISimpleClass>(); var simpleClassB = ioc.Get <ISimpleClass>(); Assert.IsTrue(simpleClassA == simpleClassB); }
public void Register_As_Transient_Gets_A_Transient() { var ioc = new MatchBox(); ioc.Register <ISimpleClass>(() => new SimpleClass()); var transientA = ioc.Get <ISimpleClass>(); var transientB = ioc.Get <ISimpleClass>(); Assert.AreNotEqual(transientA, transientB); }
public void singleton_Calls_constructor_only_when_first_used() { var ioc = new MatchBox(); var dependency = Substitute.For <IDependency>(); ioc.RegisterSingleton(() => new ClassWithDependency(dependency)); ioc.Get <ClassWithDependency>(); ioc.Get <ClassWithDependency>(); dependency.Received(1).Write(); }
public void Register_Dependent_Type_As_Transient_Gets_A_Transient() { var ioc = new MatchBox(); ioc.RegisterSingleton <IDependency>(() => new Dependency()); ioc.Register <ClassWithDependency>(); var classWithDepedencyA = ioc.Get <ClassWithDependency>(); var classWithDepedencyB = ioc.Get <ClassWithDependency>(); Assert.AreNotEqual(classWithDepedencyA, classWithDepedencyB); }
public void GetInstanceFromStringReturnsInstanceWithSameTypeName() { var ioc = new MatchBox(); ioc.Register(() => new SimpleClass()); const string className = "SimpleClass"; object simpleClass = ioc.GetInstanceFromString(className); Type classType = simpleClass.GetType(); Assert.IsTrue(className == classType.Name); }
public void RegisterDependentTypeAsSingletonInjectsDependency() { var ioc = new MatchBox(); IDependency dependency = new Dependency(); ioc.Register(() => dependency); ioc.RegisterSingleton <ClassWithDependency>(); var classWithDependency = ioc.Get <ClassWithDependency>(); Assert.AreEqual(classWithDependency.Dependency, dependency); }
public void RegisterClassWithDependencyAsParameterInConstructorInitialisesCorrectly() { var ioc = new MatchBox(); IDependency dependency = new Dependency(); ioc.Register(() => dependency); ioc.RegisterSingleton(() => new ClassWithDependency(ioc.Get <IDependency>())); var classWithDependency = ioc.Get <ClassWithDependency>(); Assert.AreEqual(classWithDependency.Dependency, dependency); }
public void Place(MatchBox matchBox) { matchBox.transform.parent = roomGameObject.transform; IEnumerable <MatchSpawnPoint> possibleSpawnPoints = matchSpawnPoints.Where(m => m.MatchBox == null); MatchSpawnPoint location = possibleSpawnPoints.ElementAt(UnityEngine.Random.Range(0, possibleSpawnPoints.Count())); location.MatchBox = matchBox; matchBox.Location = location; matchBox.transform.position = location.transform.position; }
public void RegisterWithObjectInitialiserInjectsObjectCorrectly() { var ioc = new MatchBox(); IDependency dependency = new Dependency(); ioc.Register(() => dependency); ioc.RegisterSingleton(() => new SimpleClass { Dependency = ioc.Get <IDependency>() }); var classWithObjectInjection = ioc.Get <SimpleClass>(); Assert.AreEqual(classWithObjectInjection.Dependency, dependency); }
public void RegisterCollectionT_Gets_Expected_ListT() { var ioc = new MatchBox(); ioc.RegisterCollection <ISimpleClass>(new List <Func <ISimpleClass> > { () => new SimpleClass { Index = 1 }, () => new SimpleClass { Index = 2 }, () => new SimpleClass { Index = 3 } }); List <ISimpleClass> simpleClasses = ioc.GetCollection <ISimpleClass>(); Assert.IsTrue(simpleClasses.Count == 3 && simpleClasses[0].Index == 1 && simpleClasses[1].Index == 2 && simpleClasses[2].Index == 3); }
private void LightUp(GameObject other) { MatchBox matchBox = other.GetComponent <MatchBox>(); if (matchBox) { LightUp(); return; } if (!isLighted) { return; } Match match = other.GetComponent <Match>(); if (match) { match.LightUp(); return; } }
public void Get_Throws_InvalidOperationException_When_Instance_Is_not_Registered() { var ioc = new MatchBox(); ioc.Get <ISimpleClass>(); }
public void DoGetInstance_Throws_InvalidOperationException_When_Instance_Is_not_Registered() { var ioc = new MatchBox(); ioc.DoGetInstance(typeof(ISimpleClass)); }
public void GetInstanceFromStringThrowsInvalidOperationExceptionWhenStringIsNotFound() { var ioc = new MatchBox(); ioc.GetInstanceFromString("SimpleClass"); }