/// <summary>
        /// Core implementation to discover unit tests in a given test class.
        /// </summary>
        /// <param name="type">The test class.</param>
        /// <param name="includeSourceInformation">Set to <c>true</c> to attempt to include source information.</param>
        /// <param name="messageBus">The message sink to send discovery messages to.</param>
        /// <returns>Returns <c>true</c> if discovery should continue; <c>false</c> otherwise.</returns>
        protected virtual bool FindImpl(ITypeInfo type, bool includeSourceInformation, IMessageBus messageBus)
        {
            string currentDirectory = Directory.GetCurrentDirectory();
            var    testCollection   = TestCollectionFactory.Get(type);

            try
            {
                if (!String.IsNullOrEmpty(assemblyInfo.AssemblyPath))
                {
                    Directory.SetCurrentDirectory(Path.GetDirectoryName(assemblyInfo.AssemblyPath));
                }

                foreach (var method in type.GetMethods(includePrivateMethods: true))
                {
                    var factAttribute = method.GetCustomAttributes(typeof(FactAttribute)).FirstOrDefault();
                    if (factAttribute != null)
                    {
                        var discovererAttribute = factAttribute.GetCustomAttributes(typeof(TestCaseDiscovererAttribute)).FirstOrDefault();
                        if (discovererAttribute != null)
                        {
                            var args           = discovererAttribute.GetConstructorArguments().Cast <string>().ToList();
                            var discovererType = Reflector.GetType(args[1], args[0]);
                            if (discovererType != null)
                            {
                                var discoverer = GetDiscoverer(discovererType);

                                if (discoverer != null)
                                {
                                    foreach (var testCase in discoverer.Discover(testCollection, assemblyInfo, type, method, factAttribute))
                                    {
                                        if (!messageBus.QueueMessage(new TestCaseDiscoveryMessage(UpdateTestCaseWithSourceInfo(testCase, includeSourceInformation))))
                                        {
                                            return(false);
                                        }
                                    }
                                }
                            }
                            else
                            {
                                messageAggregator.Add(new EnvironmentalWarning {
                                    Message = String.Format("Could not create discoverer type '{0}, {1}'", args[0], args[1])
                                });
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                messageAggregator.Add(new EnvironmentalWarning {
                    Message = String.Format("Exception during discovery:{0}{1}", Environment.NewLine, ex)
                });
            }
            finally
            {
                Directory.SetCurrentDirectory(currentDirectory);
            }

            return(true);
        }
        /// <summary>
        /// Gets the test collection definitions for the given assembly.
        /// </summary>
        /// <param name="assemblyInfo">The assembly.</param>
        /// <param name="messageAggregator">The message aggregator.</param>
        /// <returns>A list of mappings from test collection name to test collection definitions (as <see cref="ITypeInfo"/></returns>
        public static Dictionary<string, ITypeInfo> GetTestCollectionDefinitions(IAssemblyInfo assemblyInfo, IMessageAggregator messageAggregator)
        {
            var attributeTypesByName =
                assemblyInfo.GetTypes(false)
                        .Select(type => new { Type = type, Attribute = type.GetCustomAttributes(typeof(CollectionDefinitionAttribute).AssemblyQualifiedName).FirstOrDefault() })
                        .Where(list => list.Attribute != null)
                        .GroupBy(list => (string)list.Attribute.GetConstructorArguments().Single(),
                                 list => list.Type,
                                 StringComparer.OrdinalIgnoreCase);

            var result = new Dictionary<string, ITypeInfo>();

            foreach (var grouping in attributeTypesByName)
            {
                var types = grouping.ToList();
                result[grouping.Key] = types[0];

                if (types.Count > 1)
                    messageAggregator.Add(new EnvironmentalWarning
                    {
                        Message = String.Format("Multiple test collections declared with name '{0}': {1}",
                                                grouping.Key,
                                                String.Join(", ", types.Select(type => type.Name)))
                    });
            }

            return result;
        }
        /// <summary>
        /// Gets the test collection definitions for the given assembly.
        /// </summary>
        /// <param name="assemblyInfo">The assembly.</param>
        /// <param name="messageAggregator">The message aggregator.</param>
        /// <returns>A list of mappings from test collection name to test collection definitions (as <see cref="ITypeInfo"/></returns>
        public static Dictionary <string, ITypeInfo> GetTestCollectionDefinitions(IAssemblyInfo assemblyInfo, IMessageAggregator messageAggregator)
        {
            var attributeTypesByName =
                assemblyInfo.GetTypes(false)
                .Select(type => new { Type = type, Attribute = type.GetCustomAttributes(typeof(CollectionDefinitionAttribute).AssemblyQualifiedName).FirstOrDefault() })
                .Where(list => list.Attribute != null)
                .GroupBy(list => (string)list.Attribute.GetConstructorArguments().Single(),
                         list => list.Type,
                         StringComparer.OrdinalIgnoreCase);

            var result = new Dictionary <string, ITypeInfo>();

            foreach (var grouping in attributeTypesByName)
            {
                var types = grouping.ToList();
                result[grouping.Key] = types[0];

                if (types.Count > 1)
                {
                    messageAggregator.Add(new EnvironmentalWarning
                    {
                        Message = String.Format("Multiple test collections declared with name '{0}': {1}",
                                                grouping.Key,
                                                String.Join(", ", types.Select(type => type.Name)))
                    });
                }
            }

            return(result);
        }
Example #4
0
        public override void Run(Size size)
        {
            _gui = _guiManager.Create(size, ViewModel);
            Glfw.Init();
            // Create GLFW window
            _window = Glfw.CreateWindow(size.Width, size.Height, "OpenCAD", GlfwMonitorPtr.Null, GlfwWindowPtr.Null);
            Glfw.SetWindowSizeCallback(_window, (wnd, newwidth, newheight) =>
            {
                GL.Viewport(0, 0, newwidth, newheight);
                _gui.Resize(new Size(newwidth, newheight));
            });

            Glfw.SetCursorPosCallback(_window, (wnd, x, y) => _gui.MouseMove(new Point((int)x, (int)y)));
            Glfw.SetWindowFocusCallback(_window, (wnd, focus) => _messageAggregator.Add(new FocusChangedMessage(this, focus)));
            Glfw.SetMouseButtonCallback(_window, OnCbfun);
            // Enable the OpenGL context for the current window
            Glfw.MakeContextCurrent(_window);

            GL.Enable(EnableCap.Texture2D);
            GL.Enable(EnableCap.VertexArray);
            GL.Enable(EnableCap.CullFace);
            GL.Enable(EnableCap.DepthTest);
            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);

            //var back = new BackgroundRenderer(new GradientBackground(Color.YellowGreen, Color.Blue, Color.Plum, Color.Aquamarine));
            var back = new BackgroundRenderer(new SolidBackground(Color.FromArgb(35, 30, 32)));
            var gui  = new GUIRenderer();

            _modelRenderer = new ModelRenderer();
            _gui.Resize(size);

            while (!Glfw.WindowShouldClose(_window))
            {
                // Poll GLFW window events
                Glfw.PollEvents();

                // If you press escape the window will close
                if (Glfw.GetKey(_window, Key.Escape))
                {
                    Glfw.SetWindowShouldClose(_window, true);
                }

                _gui.Update();
                if (_gui.IsDirty)
                {
                    //Console.WriteLine("Dirty");
                    gui.Texture.Update(_gui);
                }
                // Set OpenGL clear colour to red
                GL.ClearColor(1.0f, 0.0f, 0.0f, 1.0f);

                // Clear the screen
                GL.Clear(ClearBufferMask.ColorBufferBit);
                back.Render();

                var model = ViewModel as IHasScenes;
                if (model != null)
                {
                    _modelRenderer.Render(model.CurrentScene);
                }

                //if (CurrentScene != null)
                //{
                //    _modelRenderer.Render(CurrentScene);
                //}

                gui.Render();

                // Swap the front and back buffer, displaying the scene
                Glfw.SwapBuffers(_window);
            }

            // Finally, clean up Glfw, and close the window
            Glfw.Terminate();
        }