source: branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Tests/HeuristicLab-3.3/ContentViewTests.cs @ 16892

Last change on this file since 16892 was 16892, checked in by gkronber, 8 months ago

#2925 merged r16661:16890 from trunk to branch

File size: 2.7 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Linq;
24using HeuristicLab.Common;
25using HeuristicLab.MainForm;
26using HeuristicLab.PluginInfrastructure;
27using Microsoft.VisualStudio.TestTools.UnitTesting;
28
29namespace HeuristicLab.Tests {
30  [TestClass]
31  public class ContentViewTests {
32    [TestMethod]
33    [TestCategory("General")]
34    [TestCategory("Essential")]
35    [TestProperty("Time", "long")]
36    public void ContentViewAttributeTest() {
37      //get all non-generic and instantiable classes which implement IContentView
38      foreach (Type viewType in ApplicationManager.Manager.GetTypes(typeof(IContentView))) {
39        // jkarder: skip this test for the SymbolicDataAnalysisModelMathView (and for views that derive from it)
40        // reason: our new build agent cannot create an instance of this view due to the use of System.Windows.Forms.WebBrowser
41        if (typeof(HeuristicLab.Problems.DataAnalysis.Symbolic.Views.SymbolicDataAnalysisModelMathView).IsAssignableFrom(viewType))
42          continue;
43
44        //get all ContentAttributes on the instantiable view
45        foreach (ContentAttribute attribute in viewType.GetCustomAttributes(typeof(ContentAttribute), false).Cast<ContentAttribute>()) {
46          Assert.IsTrue(attribute.ContentType == typeof(IContent) || attribute.ContentType.GetInterfaces().Contains(typeof(IContent)),
47            "The type specified in the ContentAttribute of {0} must implement IContent.", viewType);
48        }
49        //check if view can handle null as content by calling OnContentChanged
50        IContentView view = (IContentView)Activator.CreateInstance(viewType);
51        var accessor = new PrivateObject(view);
52        try {
53          accessor.Invoke("OnContentChanged");
54        } catch (Exception ex) {
55          Assert.Fail(viewType.ToString() + Environment.NewLine + ex.Message);
56        }
57      }
58    }
59  }
60}
Note: See TracBrowser for help on using the repository browser.