1 | using System;
|
---|
2 | using System.Linq;
|
---|
3 | using HeuristicLab.Common;
|
---|
4 | using HeuristicLab.MainForm;
|
---|
5 | using HeuristicLab.MainForm.WindowsForms;
|
---|
6 | using HeuristicLab.PluginInfrastructure;
|
---|
7 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
---|
8 |
|
---|
9 | namespace 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 | }
|
---|