Ejemplo n.º 1
0
        public void Test_Client_Can_Create_MessageHandlerService_From_DependencyModules()
        {
            //TODO: This won't work if we have multiple configurable modules.
            //arrange
            ContainerBuilder builder = TestIoC.CreateDefaultContainer();

            IContainer resolver = builder.Build();

            MessageHandlerService <GameServerPacketPayload, GameClientPacketPayload> handler = null;

            //act
            try
            {
                handler = resolver.Resolve <MessageHandlerService <GameServerPacketPayload, GameClientPacketPayload> >();
            }
            catch (DependencyResolutionException e)
            {
                //This makes it so the error is more readable. So we can see the exact dependency that is missing.
                DependencyResolutionException dependencyResolveException = e;

                while (dependencyResolveException.InnerException is DependencyResolutionException)
                {
                    dependencyResolveException = (DependencyResolutionException)dependencyResolveException.InnerException;
                }

                Assert.Fail($"Failed: {dependencyResolveException.Message}\n\n{dependencyResolveException.StackTrace}");
            }


            //assert
            Assert.NotNull(handler);
        }
Ejemplo n.º 2
0
        public void Test_Can_Resolve_RegisteredMovementBlockHandlers()
        {
            //TODO: If we change the ctor signature for the handler service we need to change this test
            //arrange
            //TODO: This won't work if we have multiple configurable modules.
            //arrange
            ContainerBuilder builder = TestIoC.CreateDefaultContainer();

            //Manually register SceneJect services
            builder.Register(context => new DefaultGameObjectFactory(context.Resolve <ILifetimeScope>(), new DefaultInjectionStrategy()))
            .As <IGameObjectFactory>()
            .SingleInstance();

            builder.Register(context => new DefaultGameObjectComponentAttachmentFactory(context.Resolve <ILifetimeScope>(), new DefaultInjectionStrategy()))
            .As <IGameObjectComponentAttachmentFactory>()
            .SingleInstance();

            builder.Register(context => new DefaultManualInjectionStrategy(context.Resolve <IComponentContext>()))
            .As <IManualInjectionStrategy>()
            .SingleInstance();

            IContainer resolver = builder.Build();

            //act
            IReadOnlyCollection <IMovementBlockHandler> handlers = resolver.Resolve <IReadOnlyCollection <IMovementBlockHandler> >();

            //assert
            Assert.NotNull(handlers);
            Console.WriteLine($"Found Handler Count: {handlers.Count}");
            Assert.IsNotEmpty(handlers);
        }
Ejemplo n.º 3
0
        public void Test_Can_Resolve_ExternalBehaviour_Type(Type t)
        {
            //arrange
            ContainerBuilder builder = TestIoC.CreateDefaultContainer();

            IContainer resolver = builder.Build();

            object eb = null;

            //act
            try
            {
                eb = resolver.Resolve(t);
            }
            catch (DependencyResolutionException e)
            {
                //This makes it so the error is more readable. So we can see the exact dependency that is missing.
                DependencyResolutionException dependencyResolveException = e;

                while (dependencyResolveException.InnerException is DependencyResolutionException)
                {
                    dependencyResolveException = (DependencyResolutionException)dependencyResolveException.InnerException;
                }

                Assert.Fail($"Failed: {dependencyResolveException.Message}\n\n{dependencyResolveException.StackTrace}");
            }

            Assert.NotNull(eb);
        }
Ejemplo n.º 4
0
        public static void Test_Can_Resolve_GameTickables()
        {
            //arrange
            //TODO: This won't work if we have multiple configurable modules.
            //arrange
            ContainerBuilder builder = TestIoC.CreateDefaultContainer();

            //Manually register SceneJect services
            builder.Register(context => new DefaultGameObjectFactory(context.Resolve <ILifetimeScope>(), new DefaultInjectionStrategy()))
            .As <IGameObjectFactory>()
            .SingleInstance();

            builder.Register(context => new DefaultGameObjectComponentAttachmentFactory(context.Resolve <ILifetimeScope>(), new DefaultInjectionStrategy()))
            .As <IGameObjectComponentAttachmentFactory>()
            .SingleInstance();

            builder.Register(context => new DefaultManualInjectionStrategy(context.Resolve <IComponentContext>()))
            .As <IManualInjectionStrategy>()
            .SingleInstance();

            IContainer resolver = builder.Build();

            //act
            IReadOnlyCollection <IGameTickable> gameTickables = null;

            try
            {
                gameTickables = resolver.Resolve <IReadOnlyCollection <IGameTickable> >();
            }
            catch (DependencyResolutionException e)
            {
                //This makes it so the error is more readable. So we can see the exact dependency that is missing.
                DependencyResolutionException dependencyResolveException = e;

                while (dependencyResolveException.InnerException is DependencyResolutionException)
                {
                    dependencyResolveException = (DependencyResolutionException)dependencyResolveException.InnerException;
                }

                Assert.Fail($"Failed: {dependencyResolveException.Message}\n\n{dependencyResolveException.StackTrace}");
            }


            //assert
            Assert.NotNull(gameTickables);
            Console.WriteLine($"Found game tickable Count: {gameTickables.Count}");
            Assert.IsNotEmpty(gameTickables);
        }