1 | using System.Collections;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using HeuristicLab.Core;
|
---|
5 | using HeuristicLab.Data;
|
---|
6 | using HeuristicLab.Parameters;
|
---|
7 | using HeuristicLab.PluginInfrastructure;
|
---|
8 | using HeuristicLab.Problems.DataAnalysis;
|
---|
9 | using HeuristicLab_33.Tests;
|
---|
10 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
---|
11 |
|
---|
12 | namespace 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 | }
|
---|