Пример #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);
        }
Пример #2
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);
        }