Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Tests/HeuristicLab.PluginInfraStructure-3.3/TypeDiscoveryTest.cs @ 8571

Last change on this file since 8571 was 8571, checked in by mkommend, 12 years ago

#1923:

  • Rewrote type checks for type discovery of plugin infrastructure
  • Extracted common functionality of ApplicationManagers in another class.
  • Added unit tests for the newly implemented methods*
  • Updated test lists to include the new unit tests
File size: 3.5 KB
Line 
1using System.Collections;
2using System.Collections.Generic;
3using System.Linq;
4using HeuristicLab.Core;
5using HeuristicLab.Data;
6using HeuristicLab.Parameters;
7using HeuristicLab.PluginInfrastructure;
8using HeuristicLab.Problems.DataAnalysis;
9using HeuristicLab_33.Tests;
10using Microsoft.VisualStudio.TestTools.UnitTesting;
11
12namespace HeuristicLab.PluginInfraStructure.Tests {
13  /// <summary>
14  /// Summary description for TypeDiscoveryTest
15  /// </summary>
16  [TestClass]
17  public class TypeDiscoveryTest {
18    public TypeDiscoveryTest() { }
19
20    private TestContext testContextInstance;
21
22    /// <summary>
23    ///Gets or sets the test context which provides
24    ///information about and functionality for the current test run.
25    ///</summary>
26    public TestContext TestContext {
27      get { return testContextInstance; }
28      set { testContextInstance = value; }
29    }
30
31    public static void MyClassInitialize(TestContext testContext) {
32      PluginLoader.Assemblies.Any();
33    }
34
35    [TestMethod]
36    public void IsSubTypeOfTest() {
37      Assert.IsTrue(typeof(int).IsSubTypeOf(typeof(object)));
38      Assert.IsTrue(typeof(IntValue).IsSubTypeOf(typeof(IItem)));
39      Assert.IsTrue(typeof(List<int>).IsSubTypeOf(typeof(object)));
40
41      Assert.IsTrue(typeof(List<int>).IsSubTypeOf(typeof(IList)));
42      Assert.IsTrue(typeof(List<>).IsSubTypeOf(typeof(IList)));
43
44      Assert.IsTrue(typeof(IList<IItem>).IsSubTypeOf(typeof(IList<IItem>)));
45      Assert.IsTrue(typeof(List<IntValue>).IsSubTypeOf(typeof(IList<IItem>)));
46      Assert.IsTrue(typeof(List<IntValue>).IsSubTypeOf(typeof(List<IItem>)));
47      Assert.IsFalse(typeof(ItemList<>).IsSubTypeOf(typeof(IList<IItem>)));
48      Assert.IsFalse(typeof(ItemList<>).IsSubTypeOf(typeof(List<IItem>)));
49
50      Assert.IsFalse(typeof(List<int>).IsSubTypeOf(typeof(List<>)));
51      Assert.IsTrue(typeof(List<>).IsSubTypeOf(typeof(IList<>)));
52      Assert.IsTrue(typeof(ItemList<>).IsSubTypeOf(typeof(IList<>)));
53      Assert.IsTrue(typeof(NamedItemCollection<>).IsSubTypeOf(typeof(IItemCollection<>)));
54      Assert.IsFalse(typeof(List<IntValue>).IsSubTypeOf(typeof(IList<>)));
55    }
56
57    [TestMethod]
58    public void BuildTypeTest() {
59      Assert.AreEqual(typeof(List<>).BuildType(typeof(List<>)), typeof(List<>));
60      Assert.AreEqual(typeof(List<int>).BuildType(typeof(List<>)), typeof(List<int>));
61      Assert.AreEqual(typeof(List<>).BuildType(typeof(List<int>)), typeof(List<int>));
62
63      Assert.AreEqual(typeof(ICollection<>).BuildType(typeof(List<>)), typeof(ICollection<>));
64      Assert.AreEqual(typeof(ICollection<int>).BuildType(typeof(List<>)), typeof(ICollection<int>));
65      Assert.AreEqual(typeof(ICollection<>).BuildType(typeof(List<int>)), typeof(ICollection<int>));
66
67      Assert.AreEqual(typeof(ItemCollection<>).BuildType(typeof(ICollection<int>)), null);
68      Assert.AreEqual(typeof(ItemCollection<>).BuildType(typeof(Dictionary<IItem, IItem>)), null);
69      Assert.AreEqual(typeof(ItemCollection<>).BuildType(typeof(ICollection<IItem>)), typeof(ItemCollection<IItem>));
70
71      Assert.AreEqual(typeof(FixedValueParameter<>).BuildType(typeof(ItemCollection<DataAnalysisProblemData>)), null);
72      Assert.AreEqual(typeof(IFixedValueParameter<>).BuildType(typeof(ItemCollection<DoubleValue>)), typeof(IFixedValueParameter<DoubleValue>));
73      Assert.AreEqual(typeof(IFixedValueParameter<>).BuildType(typeof(ItemCollection<IItem>)), typeof(IFixedValueParameter<IItem>));
74    }
75  }
76}
Note: See TracBrowser for help on using the repository browser.