Inheritance Hierarchy
DeltaEngine.Platforms.Tests ResolverTests
Namespace: DeltaEngine.Platforms.Tests
Assembly: DeltaEngine.Platforms.Tests (in DeltaEngine.Platforms.Tests.dll) Version: 1.1.1.0 (1.1.1)
Syntax
The ResolverTests type exposes the following members.
Constructors
Name | Description | |
---|---|---|
ResolverTests | Initializes a new instance of the ResolverTests class |
Methods
Examples
[Test] public void RegisterTypeTwice() { resolver.Register(typeof(A)); resolver.Register(typeof(A)); }
[Test] public void RegisterSingletonTypeTwice() { resolver.RegisterSingleton(typeof(A)); resolver.RegisterSingleton(typeof(A)); }
[Test] public void RegisterAfterInitializationThrows() { Assert.IsFalse(resolver.IsInitialized); resolver.Register(typeof(A)); resolver.Resolve<A>(); Assert.IsTrue(resolver.IsInitialized); Assert.Throws<Resolver.UnableToRegisterMoreTypesAppAlreadyStarted>( () => resolver.Register(typeof(B))); Assert.Throws<Resolver.UnableToRegisterMoreTypesAppAlreadyStarted>( () => resolver.RegisterSingleton(typeof(C))); }
[Test] public void TryResolveWithCustomParameter() { resolver.Register(typeof(DummyClassWithString)); Assert.DoesNotThrow(() => resolver.Resolve(typeof(DummyClassWithString), "Huhu")); }
[Test] public void TryResolveWithInvalidParameter() { resolver.Register(typeof(DummyClassWithString)); Assert.Throws<DependencyResolutionException>( () => resolver.Resolve(typeof(DummyClassWithString))); }
[Test] public void TryResolveWithContentCreationData() { var creationData = new ImageCreationData(new Size(1)); Assert.IsNotNull(resolver.Resolve(typeof(MockImage), creationData)); }
[Test] public void ResolveSpecialTypes() { Assert.AreEqual(EntitiesRunner.Current, resolver.Resolve<EntitiesRunner>()); Assert.AreEqual(GlobalTime.Current, resolver.Resolve<GlobalTime>()); Assert.AreEqual(ScreenSpace.Current, resolver.Resolve<ScreenSpace>()); Assert.AreEqual(Randomizer.Current, resolver.Resolve<Randomizer>()); }
[Test] public void RegisterInstanceMultipleTimeLogsToConsole() { var previousOut = Console.Out; var text = new StringBuilder(); using (StringWriter writer = new StringWriter(text)) { Console.SetOut(writer); resolver.RegisterInstance(new A()); resolver.RegisterInstance(new A()); #if DEBUG Assert.AreEqual( "Warning: Type DeltaEngine.Platforms.Tests.ResolverTests+A " + "already exists in alreadyRegisteredTypes" + writer.NewLine, text.ToString()); #else Assert.AreEqual(string.Empty, text.ToString()); #endif } Console.SetOut(previousOut); }
See Also