Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab/3.3/Tests/ContentViewTests.cs @ 4488

Last change on this file since 4488 was 4488, checked in by mkommend, 14 years ago

Removed unused references in Algorithms.DataAnalysis and update build configuration (ticket #1202).Removed unused references in Algorithms.DataAnalysis and update build configuration (ticket #1202).

File size: 2.1 KB
Line 
1using System;
2using System.Linq;
3using HeuristicLab.Common;
4using HeuristicLab.MainForm;
5using HeuristicLab.MainForm.WindowsForms;
6using HeuristicLab.PluginInfrastructure;
7using Microsoft.VisualStudio.TestTools.UnitTesting;
8
9namespace HeuristicLab_3._3.Tests {
10  [TestClass]
11  public class ContentViewTests {
12    public ContentViewTests() {
13    }
14
15    private TestContext testContextInstance;
16
17    /// <summary>
18    ///Gets or sets the test context which provides
19    ///information about and functionality for the current test run.
20    ///</summary>
21    public TestContext TestContext {
22      get {
23        return testContextInstance;
24      }
25      set {
26        testContextInstance = value;
27      }
28    }
29
30    // Use ClassInitialize to run code before running the first test in the class
31    [ClassInitialize]
32    public static void MyClassInitialize(TestContext testContext) {
33      PluginLoader.LoadPluginsIntoAppDomain();
34    }
35
36
37    [TestMethod]
38    public void ContentViewAttributeTest() {
39      //get all non-generic and instantiable classes which implement IContentView
40      foreach (Type viewType in ApplicationManager.Manager.GetTypes(typeof(IContentView), true).Where(t => !t.ContainsGenericParameters)) {
41        //get all ContentAttributes on the instantiable view
42        foreach (ContentAttribute attribute in viewType.GetCustomAttributes(typeof(ContentAttribute), false).Cast<ContentAttribute>()) {
43          Assert.IsTrue(attribute.ContentType == typeof(IContent) || attribute.ContentType.GetInterfaces().Contains(typeof(IContent)),
44            "The type specified in the ContentAttribute of {0} must implement IContent.", viewType);
45        }
46        //check if view can handle null as content by calling OnContentChanged
47        IContentView view = (IContentView)Activator.CreateInstance(viewType);
48        ContentView_Accessor accessor = new ContentView_Accessor(new PrivateObject(view));
49        try {
50          accessor.OnContentChanged();
51        }
52        catch (Exception ex) {
53          Assert.Fail(viewType.ToString() + Environment.NewLine + ex.Message);
54        }
55      }
56    }
57  }
58}
Note: See TracBrowser for help on using the repository browser.