Exemplo n.º 1
0
        public void BeforeTest(TestDetails details)
        {
            Console.WriteLine("----- Beginning Duality environment setup -----");

            // Set environment directory to Duality binary directory
            this.oldEnvDir = Environment.CurrentDirectory;
            string codeBaseURI  = typeof(DualityApp).Assembly.CodeBase;
            string codeBasePath = codeBaseURI.StartsWith("file:") ? codeBaseURI.Remove(0, "file:".Length) : codeBaseURI;

            codeBasePath = codeBasePath.TrimStart('/');
            Environment.CurrentDirectory = Path.GetDirectoryName(codeBasePath);

            // Add some Console logs manually for NUnit
            if (!Log.Game.Outputs.OfType <ConsoleLogOutput>().Any())
            {
                if (this.consoleLogOutput == null)
                {
                    this.consoleLogOutput = new ConsoleLogOutput();
                }
                Log.Game.AddOutput(this.consoleLogOutput);
                Log.Core.AddOutput(this.consoleLogOutput);
                Log.Editor.AddOutput(this.consoleLogOutput);
            }

            // Initialize Duality
            DualityApp.Init(DualityApp.ExecutionEnvironment.Launcher, DualityApp.ExecutionContext.Game);

            // Manually register pseudo-plugin for the Unit Testing Assembly
            this.unitTestPlugin = DualityApp.LoadPlugin(typeof(DualityTestsPlugin).Assembly, codeBasePath);

            // Create a dummy window, to get access to all the device contexts
            if (this.dummyWindow == null)
            {
                this.dummyWindow = new GameWindow(800, 600);
                this.dummyWindow.Context.LoadAll();
                this.dummyWindow.Visible = true;
                this.dummyWindow.Context.Update(this.dummyWindow.WindowInfo);
                this.dummyWindow.MakeCurrent();
                this.dummyWindow.ProcessEvents();
                DualityApp.TargetResolution = new Vector2(this.dummyWindow.Width, this.dummyWindow.Height);
                DualityApp.TargetMode       = this.dummyWindow.Context.GraphicsMode;
                DualityApp.InitGraphics();
            }

            // Load local testing memory
            TestHelper.LocalTestMemory = Formatter.TryReadObject <TestMemory>(TestHelper.LocalTestMemoryFilePath, FormattingMethod.Xml);

            Console.WriteLine("----- Duality environment setup complete -----");
        }
Exemplo n.º 2
0
        public void BeforeTest(TestDetails details)
        {
            Console.WriteLine("----- Beginning Duality environment setup -----");

            // Set environment directory to Duality binary directory
            this.oldEnvDir = Environment.CurrentDirectory;
            string codeBaseURI  = typeof(DualityApp).Assembly.CodeBase;
            string codeBasePath = codeBaseURI.StartsWith("file:") ? codeBaseURI.Remove(0, "file:".Length) : codeBaseURI;

            codeBasePath = codeBasePath.TrimStart('/');
            Console.WriteLine("Testing Core Assembly: {0}", codeBasePath);
            Environment.CurrentDirectory = Path.GetDirectoryName(codeBasePath);

            // Add some Console logs manually for NUnit
            if (!Log.Core.Outputs.OfType <TextWriterLogOutput>().Any(o => o.Target == Console.Out))
            {
                if (this.consoleLogOutput == null)
                {
                    this.consoleLogOutput = new TextWriterLogOutput(Console.Out);
                }
                Log.AddGlobalOutput(this.consoleLogOutput);
            }

            // Initialize Duality
            DualityApp.Init(
                DualityApp.ExecutionEnvironment.Launcher,
                DualityApp.ExecutionContext.Game,
                new DefaultPluginLoader(),
                null);

            // Manually register pseudo-plugin for the Unit Testing Assembly
            this.unitTestPlugin = DualityApp.LoadPlugin(typeof(DualityTestsPlugin).Assembly, codeBasePath);

            // Create a dummy window, to get access to all the device contexts
            if (this.dummyWindow == null)
            {
                WindowOptions options = new WindowOptions
                {
                    Width  = 800,
                    Height = 600
                };
                this.dummyWindow = DualityApp.OpenWindow(options);
            }

            // Load local testing memory
            TestHelper.LocalTestMemory = Serializer.TryReadObject <TestMemory>(TestHelper.LocalTestMemoryFilePath, typeof(XmlSerializer));

            Console.WriteLine("----- Duality environment setup complete -----");
        }