Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.MainForm.WindowsForms/3.3/Tests/ContentViewTests.cs @ 4483

Last change on this file since 4483 was 4483, checked in by gkronber, 14 years ago

Improved unit test for contents. #1202

File size: 4.3 KB
Line 
1using System;
2using System.Linq;
3using HeuristicLab.MainForm.WindowsForms;
4using HeuristicLab.PluginInfrastructure;
5using Microsoft.VisualStudio.TestTools.UnitTesting;
6using HeuristicLab.Common;
7
8namespace HeuristicLab.MainForm.WindowsForms_3._3.Tests {
9  [TestClass]
10  public class ContentViewTests {
11    public ContentViewTests() {
12    }
13
14    private TestContext testContextInstance;
15
16    /// <summary>
17    ///Gets or sets the test context which provides
18    ///information about and functionality for the current test run.
19    ///</summary>
20    public TestContext TestContext {
21      get {
22        return testContextInstance;
23      }
24      set {
25        testContextInstance = value;
26      }
27    }
28
29    #region Additional test attributes
30    //
31    // You can use the following additional attributes as you write your tests:
32    //
33
34    // Use ClassInitialize to run code before running the first test in the class
35    [ClassInitialize()]
36    public static void MyClassInitialize(TestContext testContext) {
37      //needed to load all assemblies in the current appdomain
38      new HeuristicLab.Analysis.Views.HeuristicLabAnalysisViewsPlugin();
39      new HeuristicLab.Core.Views.HeuristicLabCoreViewsPlugin();
40      new HeuristicLab.Data.Views.HeuristicLabDataViewsPlugin();
41      new HeuristicLab.Encodings.PermutationEncoding.Views.HeuristicLabEncodingsPermutationEncodingViewsPlugin();
42      new HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views.HeuristicLabEncodingsSymbolicExpressionTreeEncodingViewsPlugin();
43      new HeuristicLab.MainForm.HeuristicLabMainFormPlugin();
44      new HeuristicLab.MainForm.WindowsForms.HeuristicLabMainFormPlugin();
45      new HeuristicLab.Operators.Views.HeuristicLabOperatorsViewsPlugin();
46      new HeuristicLab.Operators.Views.GraphVisualization.HeuristicLabOperatorsViewsGraphVisualizationPlugin();
47      new HeuristicLab.Parameters.Views.HeuristicLabParametersViewsPlugin();
48      new HeuristicLab.Problems.ArtificialAnt.Views.HeuristicLabProblemsArtificialAntViewsPlugin();
49      new HeuristicLab.Problems.DataAnalysis.Views.HeuristicLabProblemsDataAnalysisViewsPlugin();
50      new HeuristicLab.Problems.ExternalEvaluation.Views.HeuristicLabProblemsExternalEvaluationViewsPlugin();
51      new HeuristicLab.Problems.Knapsack.Views.HeuristicLabProblemsKnapsackViewsPlugin();
52      new HeuristicLab.Problems.OneMax.Views.HeuristicLabProblemsKnapsackViewsPlugin();
53      new HeuristicLab.Problems.TestFunctions.Views.HeuristicLabProblemsTestFunctionsViewsPlugin();
54      new HeuristicLab.Problems.TravelingSalesman.Views.HeuristicLabProblemsTravelingSalesmanViewsPlugin();
55      new HeuristicLab.Problems.VehicleRouting.Views.HeuristicLabProblemsVehicleRoutingViewsPlugin();
56    }
57
58    // Use ClassCleanup to run code after all tests in a class have run
59    //[ClassCleanup()]
60    //public static void MyClassCleanup() {
61    //}
62    //
63    // Use TestInitialize to run code before running each test
64    //[TestInitialize()]
65    //public void MyTestInitialize() {      }
66    //
67    // Use TestCleanup to run code after each test has run
68    // [TestCleanup()]
69    // public void MyTestCleanup() { }
70    //
71    #endregion
72
73    [TestMethod]
74    public void ContentViewAttributeTest() {
75      //get all non-generic and instantiable classes which implement IContentView
76      foreach (Type viewType in ApplicationManager.Manager.GetTypes(typeof(IContentView), true).Where(t => !t.ContainsGenericParameters)) {
77        //get all ContentAttributes on the instantiable view
78        foreach (ContentAttribute attribute in viewType.GetCustomAttributes(typeof(ContentAttribute), false).Cast<ContentAttribute>()) {
79          Assert.IsTrue(attribute.ContentType == typeof(IContent) || attribute.ContentType.GetInterfaces().Contains(typeof(IContent)),
80            "The type specified in the ContentAttribute of {0} must implement IContent.", viewType);
81        }
82        //check if view can handle null as content by calling OnContentChanged
83        IContentView view = (IContentView)Activator.CreateInstance(viewType);
84        ContentView_Accessor accessor = new ContentView_Accessor(new PrivateObject(view));
85        try {
86          accessor.OnContentChanged();
87        }
88        catch (Exception ex) {
89          Assert.Fail(viewType.ToString() + Environment.NewLine + ex.Message);
90        }
91      }
92    }
93  }
94}
Note: See TracBrowser for help on using the repository browser.