Esempio n. 1
0
        public void Init()
        {
            _mocks    = Mocks.Init();
            _resolver = Mocks.GetResolver();
            _resolver.Build();
            var updater = new ContainerBuilder();

            updater.RegisterInstance(_mocks.Input().Object).As <IInput>();
            updater.RegisterInstance(_mocks.AudioSystem().Object).As <IAudioSystem>();
            updater.RegisterInstance(new Mock <IMessagePump>().Object);
            updater.RegisterInstance(new Mock <IRuntimeSettings>().Object);
            Mock <IUIThread> uiThread = new Mock <IUIThread>();

            uiThread.Setup(u => u.RunBlocking(It.IsAny <Action>())).Callback <Action>(a => a());
            updater.RegisterInstance(uiThread.Object);
            updater.Update(_resolver.Container);
            _textures = new Dictionary <string, ITexture> ();
            _state    = _resolver.Container.Resolve <IGameState>();
            _factory  = _resolver.Container.Resolve <IGameFactory>();
            DesktopFileSystem fileSystem = new DesktopFileSystem();

            _saveLoad = new AGSSaveLoad(_resolver, _factory, _textures, _resolver.Container.Resolve <IGame>(),
                                        fileSystem);
            _state.Rooms.Add(_mocks.Room().Object);
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes the application and set the master page
        /// </summary>
        /// <typeparam name="StartViewModel">The start ViewModel (for view navigation)</typeparam>
        public void Run <StartViewModel>()
            where StartViewModel : class, IViewModel
        {
            // IOC container and ViewFactory
            var viewFactory = new ViewFactory(Resolver);

            // Views and view models
            var coreAssembly = FormsApp.GetAssembly();

            viewFactory.Register(coreAssembly);

            // Register instance dependencies
            Resolver.Register <IXamViewFactory>(viewFactory, DepedencyLifetime.PerLifetime);

            // Finish the ioc continer
            Resolver.Build();

            // Setting the BindingContext for later use
            FormsApp.BindingContext = Resolver;

            // Set the start page
            var launchPage = viewFactory.Launch <StartViewModel>();

            FormsApp.MainPage = launchPage;
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            // configure ioc
            var resolver = Resolver.Build();

            // run application
            AppBuilder.Configure <App>()
            .UsePlatformDetect()
            .Start <MainWindow>(() => resolver.Resolve <MainWindow.Context>());
        }
Esempio n. 4
0
        public void Init()
        {
            _mocks    = Mocks.Init();
            _resolver = Mocks.GetResolver();
            _resolver.Build();

            _areas       = new AGSBindingList <IArea>(1);
            _roomObjects = new AGSConcurrentHashSet <IObject>();
            _uiObjects   = new AGSConcurrentHashSet <IObject>();

            var room = _mocks.Room();

            room.Setup(m => m.Objects).Returns(_roomObjects);
            room.Setup(m => m.Areas).Returns(_areas);
            room.Setup(m => m.Background).Returns(() => null);
            _mocks.GameState().Setup(s => s.UI).Returns(_uiObjects);
        }
Esempio n. 5
0
        private async Task testAllocation <TObj>() where TObj : class
        {
            Resolver resolver = Mocks.GetResolver();

            resolver.Build();

            var myReference = resolver.Container.Resolve <TObj>();

            //https://stackoverflow.com/questions/11417283/strange-weakreference-behavior-on-mono
            var weakRef = alloc(myReference);
            await Task.Delay(5);

            // ReSharper disable once RedundantAssignment
            myReference = null;

            GC.Collect(2, GCCollectionMode.Forced, true, true);

            Assert.IsFalse(weakRef.IsAlive);
        }
Esempio n. 6
0
        public void Init()
        {
            _mocks       = Mocks.Init();
            _transitions = new Mock <IAGSRoomTransitions>();
            _resolver    = Mocks.GetResolver();
            _resolver.Build();

            _areas       = new AGSBindingList <IArea>(1);
            _roomObjects = new AGSConcurrentHashSet <IObject>();
            _uiObjects   = new AGSConcurrentHashSet <IObject>();
            _events      = _resolver.Container.Resolve <IGameEvents>(); //new AGSGameEvents(null, new AGSEvent(), null, null, null, null, _resolver);

            var room = _mocks.Room();

            room.Setup(m => m.Objects).Returns(_roomObjects);
            room.Setup(m => m.Areas).Returns(_areas);
            room.Setup(m => m.Background).Returns(() => null);
            _mocks.GameState().Setup(s => s.UI).Returns(_uiObjects);
        }
Esempio n. 7
0
        public async Task CanOnlyAddOneComponentTest()
        {
            Resolver resolver = Mocks.GetResolver();

            resolver.Builder.RegisterType <OnlyOneComponent>().As <IOnlyOneComponent>();
            resolver.Build();
            for (int i = 0; i < 100; i++)
            {
                OnlyOneComponent.LastID = 0;
                AGSEmptyEntity entity = new AGSEmptyEntity("Test" + Guid.NewGuid(), resolver);

                List <Task> tasks = new List <Task>();
                for (int j = 0; j < 10; j++)
                {
                    tasks.Add(Task.Run(() => entity.AddComponent <IOnlyOneComponent>()));
                }
                await Task.WhenAll(tasks);

                var component = entity.AddComponent <IOnlyOneComponent>();

                component.AssertOne();
            }
        }
Esempio n. 8
0
        public static IEnumerable <IObject> GetImplementors(Mocks mocks, Mock <IGameState> stateMock, IGameState state = null)
        {
            if (state == null && stateMock != null)
            {
                state = stateMock.Object;
            }
            mocks.Game().Setup(g => g.State).Returns(state);
            stateMock?.Setup(s => s.UI).Returns(new AGSConcurrentHashSet <IObject>());
            Mock <IInput> input    = new Mock <IInput>();
            Resolver      resolver = GetResolver();

            input.Setup(i => i.KeyUp).Returns(new Mock <IEvent <KeyboardEventArgs> >().Object);
            input.Setup(i => i.KeyDown).Returns(new Mock <IEvent <KeyboardEventArgs> >().Object);
            if (stateMock != null)
            {
                stateMock.Setup(s => s.Cutscene).Returns(mocks.Cutscene().Object);
            }

            Mock <IUIEvents> uiEvents = new Mock <IUIEvents>();
            Mock <IEvent <MouseButtonEventArgs> >   buttonEvent = new Mock <IEvent <MouseButtonEventArgs> >();
            Mock <IEvent <MousePositionEventArgs> > mouseEvent  = new Mock <IEvent <MousePositionEventArgs> >();

            uiEvents.Setup(u => u.MouseClicked).Returns(buttonEvent.Object);
            uiEvents.Setup(u => u.MouseDown).Returns(buttonEvent.Object);
            uiEvents.Setup(u => u.MouseUp).Returns(buttonEvent.Object);
            uiEvents.Setup(u => u.LostFocus).Returns(buttonEvent.Object);
            uiEvents.Setup(u => u.MouseEnter).Returns(mouseEvent.Object);
            uiEvents.Setup(u => u.MouseLeave).Returns(mouseEvent.Object);
            uiEvents.Setup(u => u.MouseMove).Returns(mouseEvent.Object);

            Mock <IGraphicsFactory> graphicsFactory = new Mock <IGraphicsFactory>();
            Func <ISprite>          getSprite       = () => new AGSSprite(resolver, mocks.MaskLoader().Object);

            graphicsFactory.Setup(g => g.GetSprite()).Returns(() => getSprite());
            AGSAnimationComponent animationComponent = new AGSAnimationComponent();

            Mock <IImage>           image           = new Mock <IImage>();
            Mock <IButtonComponent> buttonComponent = new Mock <IButtonComponent>();

            buttonComponent.Setup(b => b.HoverAnimation).Returns(new ButtonAnimation(new AGSSingleFrameAnimation(getSprite())));
            buttonComponent.Setup(b => b.IdleAnimation).Returns(new ButtonAnimation(new AGSSingleFrameAnimation(getSprite())));
            buttonComponent.Setup(b => b.PushedAnimation).Returns(new ButtonAnimation(new AGSSingleFrameAnimation(getSprite())));
            Mock <IAudioSystem>     audioSystem  = new Mock <IAudioSystem>();
            Mock <IRuntimeSettings> settings     = mocks.Settings();
            Mock <IRenderThread>    renderThread = new Mock <IRenderThread>();
            Mock <IUpdateThread>    updateThread = new Mock <IUpdateThread>();

            renderThread.Setup(u => u.RunBlocking(It.IsAny <Action>())).Callback <Action>(a => a());
            updateThread.Setup(u => u.RunBlocking(It.IsAny <Action>())).Callback <Action>(a => a());

            resolver.Builder.RegisterInstance(input.Object);
            resolver.Builder.RegisterInstance(state);
            resolver.Builder.RegisterInstance(uiEvents.Object);
            resolver.Builder.RegisterInstance(animationComponent).As <IAnimationComponent>();
            resolver.Builder.RegisterInstance(buttonComponent.Object);
            resolver.Builder.RegisterInstance(audioSystem.Object);
            resolver.Builder.RegisterInstance(new Mock <IRenderMessagePump>().Object);
            resolver.Builder.RegisterInstance(new Mock <IUpdateMessagePump>().Object);
            resolver.Builder.RegisterInstance(renderThread.Object);
            resolver.Builder.RegisterInstance(updateThread.Object);
            resolver.Builder.RegisterInstance(new Mock <ILabelRenderer>().Object);
            resolver.Builder.RegisterInstance(new Mock <ITexture>().Object);
            resolver.Builder.RegisterInstance(mocks.MaskLoader().Object).As <IMaskLoader>();
            resolver.Builder.RegisterInstance(settings.Object).As <IGameSettings>();
            resolver.Builder.RegisterInstance(settings.Object).As <IRuntimeSettings>();
            resolver.Builder.RegisterInstance(mocks.Game().Object);
            resolver.Build();

            Func <IObject> baseObj = () => new AGSObject("Test", resolver);

            mocks.Game().Setup(g => g.Events).Returns(resolver.Container.Resolve <IGameEvents>());
            mocks.Game().Setup(g => g.Factory).Returns(resolver.Container.Resolve <IGameFactory>());

            Mock <IOutfit> outfit = new Mock <IOutfit>();

            Func <IPanel> basePanel = () => new AGSPanel("Panel", resolver, image.Object);
            Func <ILabel> baseLabel = () => new AGSLabel("Label", resolver)
            {
                LabelRenderSize = new AGS.API.SizeF(100f, 50f)
            };
            var button = new AGSButton("Button", resolver)
            {
                LabelRenderSize = new AGS.API.SizeF(100f, 50f)
            };

            List <IObject> implmentors = new List <IObject>
            {
                baseObj().Hotspot("Object"),
                new AGSCharacter("Character", resolver, outfit.Object).Hotspot("Character"),
                basePanel().Hotspot("Panel"),
                baseLabel().Hotspot("Label"),
                button.Hotspot("Button"),
                new AGSInventoryWindow("Inventory", resolver, image.Object).Hotspot("Inventory"),
                new AGSSlider("Slider", resolver, image.Object).Hotspot("Slider"),
                new AGSCheckBox("Checkbox", resolver),
                new AGSTextbox("Textbox", resolver),
                new AGSComboBox("Combobox", resolver),
            };

            return(implmentors);
        }
Esempio n. 9
0
 public static IDependencyResolver GetHttpResolver(this Resolver resolver)
 {
     resolver.Build();
     return(new IocDependencyResolver(resolver));
 }