public void ReturnsNullWhenKeyNotFound() { var store = new ComponentStore(); var registrationsForService = store.GetRegistrationsForService<IService>(); Assert.Equal(0, registrationsForService.Count); }
public void CannotInsertOneNameTwice() { var store = new ComponentStore(); var name = "test"; store.Add<IService, ClassWithNoDependencies>(name); Assert.Throws<NameAlreadyRegisteredException>(() => store.Add<IService, ClassWithNoDependencies>(name)); }
public void CanInsertServiceTwice() { var store = new ComponentStore(); store.Add<IService, ClassWithNoDependencies>(); Assert.DoesNotThrow(() => store.Add<IService, ClassWithNoDependencies>()); }
public void CanSplitGraph() { /* * Dotty Graph: * * digraph G { * a [label="IService :: A"] ; * a -> b [label="service1"] ; * a -> c [label="service2"] ; * b [label="IService :: B"] ; * b -> d ; * d [label="IService :: C"] ; * c [label="IService :: B"] ; * c -> f ; * f [label="IService :: C"] ; * } */ var store = new ComponentStore(); store.Add <IService, ClassWithTwoDependenciesOnItsOwnService>(); store.Add <IService, ClassWithDependencyOnItsOwnService>(); store.Add <IService, ClassWithNoDependencies>(); var container = new PandoraContainer(store); var service = container.Resolve <IService>(); Assert.IsType(typeof(ClassWithTwoDependenciesOnItsOwnService), service); }
public void ReturnsNullWhenKeyNotFound() { var store = new ComponentStore(); var registrationsForService = store.GetRegistrationsForService <IService>(); Assert.Equal(0, registrationsForService.Count); }
public void CanResolveConcreteType() { var store = new ComponentStore(); store.Add<ClassWithNoDependencies, ClassWithNoDependencies>(); var container = new PandoraContainer(store); Assert.DoesNotThrow(() => container.Resolve<ClassWithNoDependencies>()); }
public void CanInsertServiceTwice() { var store = new ComponentStore(); store.Add <IService, ClassWithNoDependencies>(); Assert.DoesNotThrow(() => store.Add <IService, ClassWithNoDependencies>()); }
public void CannotInsertOneNameTwice() { var store = new ComponentStore(); var name = "test"; store.Add <IService, ClassWithNoDependencies>(name); Assert.Throws <NameAlreadyRegisteredException>(() => store.Add <IService, ClassWithNoDependencies>(name)); }
public void CanInsertServiceTwice() { var store = new ComponentStore(); store.Add <IService, ClassWithNoDependencies>(); store.Add <IService, ClassWithNoDependencies>(); }
public void CanResolveConcreteType() { var store = new ComponentStore(); store.Add <ClassWithNoDependencies, ClassWithNoDependencies>(); var container = new PandoraContainer(store); container.Resolve <ClassWithNoDependencies>(); }
public void ThrowsExceptionIfDependencyCouldNotBeSatisfied() { var store = new ComponentStore(); store.Add <ClassWithOneDependency, ClassWithOneDependency>(); var container = new PandoraContainer(store); Assert.Throws <DependencyMissingException>(() => container.Resolve <ClassWithOneDependency>()); }
private SubscriptionStore(string deployPath, string tempPath, ComponentStoreType storeType) { this._deployPath = deployPath; this._tempPath = tempPath; Directory.CreateDirectory(this._deployPath); Directory.CreateDirectory(this._tempPath); using (this.AcquireStoreWriterLock()) this._compStore = ComponentStore.GetStore(storeType, this); }
public void CanInsertRegistration() { var store = new ComponentStore(); store.Add <IService, ClassWithNoDependencies>(); var registration = store.GetRegistrationsForService <IService>()[0]; Assert.Equal(registration.Implementor, typeof(ClassWithNoDependencies)); }
public void ContainerSetup() { var store = new ComponentStore(); //Add components to the store. store.Register(p => p.Service <IService>() .Implementor <ClassWithNoDependencies>()); //Create the container var container = new PandoraContainer(store); }
public void CanResolveWhenGivenTwoConstructorsWhereOneCantBeSatisfied() { var store = new ComponentStore(); store.Add <IService4, ClassWithMultipleConstructors>(); var container = new PandoraContainer(store); container.Resolve <IService4>(); }
public void ThrowsExceptionIfTypeNotRegistered() { var store = new ComponentStore(); var container = new PandoraContainer(store); Assert.Throws <ServiceNotFoundException>(() => { var result = container.Resolve <IService>(); }); }
public void CanResolveClassWithoutDependencies() { var componentStore = new ComponentStore(); componentStore.Add<IService, ClassWithNoDependencies>(); var container = new PandoraContainer(componentStore); var result = container.Resolve<IService>(); Assert.IsType<ClassWithNoDependencies>(result); }
public void ExcludesServicesThatCantBeCreated() { var store = new ComponentStore(); store.Add<IService, ClassWithDependencyOnItsOwnService>(); var container = new PandoraContainer(store); var enumerable = container.ResolveAll<IService>(); Assert.Equal(0, enumerable.Count()); }
public void ThrowsDependencyMissingExceptionIfDependencyChainCannotBeSatisfied() { var store = new ComponentStore(); store.Add <IService, ClassWithDependencyOnItsOwnService>(); var container = new PandoraContainer(store); Assert.Throws <DependencyMissingException>(() => container.Resolve <IService>()); }
public void CanResolveClassWithOneDependency() { IComponentStore componentStore = new ComponentStore(); componentStore.Add<IService, ClassWithNoDependencies>(); componentStore.Add<IService2, ClassWithOneDependency>(); PandoraContainer locator = new PandoraContainer(componentStore); var result = locator.Resolve<IService2>(); Assert.IsType<ClassWithOneDependency>(result); }
public void ExcludesServicesThatCantBeCreated() { var store = new ComponentStore(); store.Add <IService, ClassWithDependencyOnItsOwnService>(); var container = new PandoraContainer(store); var enumerable = container.ResolveAll <IService>(); Assert.Equal(0, enumerable.Count()); }
public void DependencyMissingExceptionPropagatesThroughMultipleLevels() { var store = new ComponentStore(); store.Add <IService3, ClassDependingOnClassWithOneDependency>(); store.Add <IService2, ClassWithOneDependency>(); var container = new PandoraContainer(store); Assert.Throws <DependencyMissingException>(() => container.Resolve <IService3>()); }
public void CanRetrieveServiceByName() { var store = new ComponentStore(); //This registration is to give the container something to choose from, in case named lookup won't work store.Add<IService, ClassWithDependencyOnItsOwnService>("memory.repository"); store.Add<IService, ClassWithNoDependencies>("db.repository"); var container = new PandoraContainer(store); var service = container.Resolve<IService>("db.repository"); Assert.IsType<ClassWithNoDependencies>(service); }
public void CanInsertInstanceWithoutName() { var store = new ComponentStore(); var instance = new ClassWithNoDependencies(); store.AddInstance<IService>(instance); var container = new PandoraContainer(store); var service = container.Resolve<IService>(); Assert.Same(instance, service); }
public void RetrievalByNameThrowsExceptionWhenNameNotRegistered() { var store = new ComponentStore(); var container = new PandoraContainer(store); //To make it lookup something container.Register(p => p.Service<ClassWithNoDependencies>() .Implementor<ClassWithNoDependencies>()); Assert.Throws<ServiceNotFoundException>(() => container.Resolve<ClassWithNoDependencies>("test")); }
public void CanResolveClassWithTwoDependenciesOnItsOwnServiceWithOnlyOneSubdependencyRegistration() { var store = new ComponentStore(); store.Add<IService, ClassWithTwoDependenciesOnItsOwnService>(); store.Add<IService, ClassWithNoDependencies>(); var container = new PandoraContainer(store); var service = container.Resolve<IService>(); Assert.IsType(typeof (ClassWithTwoDependenciesOnItsOwnService), service); }
public void RegisterSimpleTypeFluently() { var store = new ComponentStore(); /* * Register ClassWithNoDependencies implementing * IService with default Lifestyle and no Parameters */ store.Register(p => p.Service <IService>() .Implementor <ClassWithNoDependencies>()); }
public void CanResolveClassWithoutDependencies() { var componentStore = new ComponentStore(); componentStore.Add <IService, ClassWithNoDependencies>(); var container = new PandoraContainer(componentStore); var result = container.Resolve <IService>(); Assert.IsType <ClassWithNoDependencies>(result); }
public void CanInsertRegistration() { var store = new ComponentStore(); Assert.DoesNotThrow(() => store.Add<IService, ClassWithNoDependencies>() ); var registration = store.GetRegistrationsForService<IService>()[0]; Assert.Equal(registration.Implementor, typeof(ClassWithNoDependencies)); }
public void CanResolveClassWithMultipleDependencies() { var store = new ComponentStore(); store.Add<IService, ClassWithNoDependencies>(); store.Add<IService2, ClassWithOneDependency>(); store.Add<IService3, ClassDependingOnClassWithOneDependency>(); var container = new PandoraContainer(store); var result = container.Resolve<IService3>(); Assert.IsType<ClassDependingOnClassWithOneDependency>(result); }
public void ReturnsAllServicesForGivenType() { var store = new ComponentStore(); store.Add<IService, ClassWithNoDependencies>("test1"); store.Add<IService, ClassWithDependencyOnItsOwnService>(); store.Add<IService2, ClassWithOneDependency>(); var container = new PandoraContainer(store); var enumerable = container.ResolveAll<IService>(); Assert.Equal(2, enumerable.Count()); }
public void CanInsertInstanceWithoutName() { var store = new ComponentStore(); var instance = new ClassWithNoDependencies(); store.AddInstance <IService>(instance); var container = new PandoraContainer(store); var service = container.Resolve <IService>(); Assert.Same(instance, service); }
public void CanResolveClassWithOneDependency() { IComponentStore componentStore = new ComponentStore(); componentStore.Add <IService, ClassWithNoDependencies>(); componentStore.Add <IService2, ClassWithOneDependency>(); PandoraContainer locator = new PandoraContainer(componentStore); var result = locator.Resolve <IService2>(); Assert.IsType <ClassWithOneDependency>(result); }
public void ActivationHappensEveryTime() { var store = new ComponentStore(); var registration = store.Add<IService, ClassWithNoDependencies>(); registration.Lifestyle = ComponentLifestyles.Transient; var container = new PandoraContainer(store); var service = container.Resolve<IService>(); var service2 = container.Resolve<IService>(); Assert.NotSame(service, service2); }
public BaseGame() : base() { _graphics = new GraphicsDeviceManager(this); _graphics.IsFullScreen = true; Resolution.Init(ref _graphics); Components = new ComponentStore(); GameScreenService = new GameScreenService(); }
public void RegisterNamedType() { var store = new ComponentStore(); /* * Every registration can be assigned a unique name to * be able to retrieve it in case there is more than one IService * See PandoraContainer.Resolve<T>(string) */ store.Register(p => p.Service <IService>("componentName") .Implementor <ClassWithNoDependencies>()); }
public void RetrievalByNameThrowsExceptionWhenNameNotRegistered() { var store = new ComponentStore(); var container = new PandoraContainer(store); //To make it lookup something container.Register(p => p.Service <ClassWithNoDependencies>() .Implementor <ClassWithNoDependencies>()); Assert.Throws <ServiceNotFoundException>(() => container.Resolve <ClassWithNoDependencies>("test")); }
public void CustomLifestyle() { /* * Any instance implementing ILifestyle can be passed to the container. */ var store = new ComponentStore(); var myLifestyle = new CustomLifestyle(); store.Register(p => p.Service <IService>() .Implementor <ClassWithNoDependencies>() .Lifestyle.Custom(myLifestyle)); }
public void RegisterMultipleServicesInOneClosure() { var store = new ComponentStore(); store.Register(p => { p.Service <IService>() .Implementor <ClassWithDependencyOnItsOwnService>(); p.Service <IService>() .Implementor <ClassWithNoDependencies>(); }); }
public void ReturnsAllServicesForGivenType() { var store = new ComponentStore(); store.Add <IService, ClassWithNoDependencies>("test1"); store.Add <IService, ClassWithDependencyOnItsOwnService>(); store.Add <IService2, ClassWithOneDependency>(); var container = new PandoraContainer(store); var enumerable = container.ResolveAll <IService>(); Assert.Equal(2, enumerable.Count()); }
public void CanResolveClassWithMultipleDependencies() { var store = new ComponentStore(); store.Add <IService, ClassWithNoDependencies>(); store.Add <IService2, ClassWithOneDependency>(); store.Add <IService3, ClassDependingOnClassWithOneDependency>(); var container = new PandoraContainer(store); var result = container.Resolve <IService3>(); Assert.IsType <ClassDependingOnClassWithOneDependency>(result); }
public ShipService(ComponentStore components, BaseGameScreen gameScreen) { _components = components; _gameScreen = gameScreen; var keyboardService = _components.GetSingle<KeyboardService>(); keyboardService.RegisterKeyListener(new KeyboardService.KeyCombination(Keys.Up, KeyboardService.KeyEventType.Down, Keys.Down, KeyboardService.KeyEventType.Up), Accelerate); keyboardService.RegisterKeyListener(new KeyboardService.KeyCombination(Keys.Up, KeyboardService.KeyEventType.Up, Keys.Down, KeyboardService.KeyEventType.Down), Decelerate); keyboardService.RegisterKeyListener(new KeyboardService.KeyCombination(Keys.Left, KeyboardService.KeyEventType.Down), Left); keyboardService.RegisterKeyListener(new KeyboardService.KeyCombination(Keys.Right, KeyboardService.KeyEventType.Down), Right); keyboardService.RegisterKeyListener(new KeyboardService.KeyCombination(Keys.LeftControl, KeyboardService.KeyEventType.Pressed), Fire); }
public void CanRetrieveServiceByName() { var store = new ComponentStore(); //This registration is to give the container something to choose from, in case named lookup won't work store.Add <IService, ClassWithDependencyOnItsOwnService>("memory.repository"); store.Add <IService, ClassWithNoDependencies>("db.repository"); var container = new PandoraContainer(store); var service = container.Resolve <IService>("db.repository"); Assert.IsType <ClassWithNoDependencies>(service); }
public void CanResolveClassWithTwoDependenciesOnItsOwnServiceWithOnlyOneSubdependencyRegistration() { var store = new ComponentStore(); store.Add <IService, ClassWithTwoDependenciesOnItsOwnService>(); store.Add <IService, ClassWithNoDependencies>(); var container = new PandoraContainer(store); var service = container.Resolve <IService>(); Assert.IsType(typeof(ClassWithTwoDependenciesOnItsOwnService), service); }
public ShipService(ComponentStore components, BaseGameScreen gameScreen) { _components = components; _gameScreen = gameScreen; var keyboardService = _components.GetSingle <KeyboardService>(); keyboardService.RegisterKeyListener(new KeyboardService.KeyCombination(Keys.Up, KeyboardService.KeyEventType.Down, Keys.Down, KeyboardService.KeyEventType.Up), Accelerate); keyboardService.RegisterKeyListener(new KeyboardService.KeyCombination(Keys.Up, KeyboardService.KeyEventType.Up, Keys.Down, KeyboardService.KeyEventType.Down), Decelerate); keyboardService.RegisterKeyListener(new KeyboardService.KeyCombination(Keys.Left, KeyboardService.KeyEventType.Down), Left); keyboardService.RegisterKeyListener(new KeyboardService.KeyCombination(Keys.Right, KeyboardService.KeyEventType.Down), Right); keyboardService.RegisterKeyListener(new KeyboardService.KeyCombination(Keys.LeftControl, KeyboardService.KeyEventType.Pressed), Fire); }
public void CanSpecifyDependencyByName() { var store = new ComponentStore(); store.Add<IService, ClassWithNoDependencies>("service1"); store.Add<IService, ClassWithNoDependencies2>("service2"); store.Add<ClassWithOneDependency, ClassWithOneDependency>() .Parameters["dependency"] = "service2"; var container = new PandoraContainer(store); var service2 = container.Resolve<ClassWithOneDependency>(); Assert.IsType<ClassWithNoDependencies2>(service2.Dependency); }
public void ActivationHappensOnlyOnceForSingletonComponents() { var store = new ComponentStore(); var registration = store.Add <IService, ClassWithNoDependencies>("test"); registration.Lifestyle = ComponentLifestyles.Singleton; var container = new PandoraContainer(store); var service = container.Resolve <IService>("test"); var service2 = container.Resolve <IService>("test"); Assert.Same(service, service2); }
public void CanInstantiateClassThatDependsOnAString() { var store = new ComponentStore(); store.Register( p => { p.Service<ClassDependingOnAString>() .Implementor<ClassDependingOnAString>() .Parameters("string1"); p.Service<string>("string1") .Instance("Hello World"); }); var container = new PandoraContainer(store); var resolve = container.Resolve<ClassDependingOnAString>(); Assert.Equal("Hello World", resolve.Dependency); }
public BaseGameScreen(string name, BaseGame game, List<IComponent> components = null) { Game = game; Name = name; if (components == null) { Components = new ComponentStore(); } else { Components = new ComponentStore(components); } Textures = new Dictionary<string, Texture2D>(); SoundEffects = new Dictionary<string, SoundEffect>(); }
public MovementService(ComponentStore components) { _components = components; }
public void ThrowsDependencyMissingExceptionIfDependencyChainCannotBeSatisfied() { var store = new ComponentStore(); store.Add<IService, ClassWithDependencyOnItsOwnService>(); var container = new PandoraContainer(store); Assert.Throws<DependencyMissingException>(() => container.Resolve<IService>()); }
public void CanResolveDependencyChainOfSameService() { var store = new ComponentStore(); store.Add<IService, ClassWithDependencyOnItsOwnService>(); store.Add<IService, ClassWithNoDependencies>(); var container = new PandoraContainer(store); var service = container.Resolve<IService>(); Assert.IsType(typeof (ClassWithDependencyOnItsOwnService), service); var ownService = (ClassWithDependencyOnItsOwnService)service; Assert.IsType(typeof (ClassWithNoDependencies), ownService.SubService); }
public void CanRegisterMultipleParametersInARow() { store = new ComponentStore(); store.Register(p => p.Service<IService>() .Implementor<ClassWithNoDependencies>() .Parameters("test").Set("test") .Parameters("repository").Set("something")); var registrations = store.GetRegistrationsForService<IService>().First(); Assert.NotNull(registrations.Parameters["test"]); Assert.NotNull(registrations.Parameters["repository"]); }
public void ThrowsExceptionIfDependencyCouldNotBeSatisfied() { var store = new ComponentStore(); store.Add<ClassWithOneDependency, ClassWithOneDependency>(); var container = new PandoraContainer(store); Assert.Throws<DependencyMissingException>(() => container.Resolve<ClassWithOneDependency>()); }
public FluentInterface() { store = new ComponentStore(); container = new PandoraContainer(store); }
public void ThrowsExceptionIfTypeNotRegistered() { var store = new ComponentStore(); var container = new PandoraContainer(store); Assert.Throws<ServiceNotFoundException>(() => { var result = container.Resolve<IService>(); }); }
public CollisionService(ComponentStore components) { _components = components; }
public PandoraSurfaceInterface() { var store = new ComponentStore(); container = new PandoraContainer(store); }
public AsteroidService(ComponentStore components) { _components = components; }