forked from pythonnet/pythonnet
-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathTestInterfaceClasses.cs
More file actions
76 lines (64 loc) · 1.74 KB
/
TestInterfaceClasses.cs
File metadata and controls
76 lines (64 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using NUnit.Framework;
using Python.Runtime;
namespace Python.EmbeddingTest
{
public class TestInterfaceClasses
{
public string testCode = @"
from clr import AddReference
AddReference(""System"")
AddReference(""Python.EmbeddingTest"")
from Python.EmbeddingTest import *
testModule = TestInterfaceClasses.GetInstance()
print(testModule.Child.ChildBool)
";
[OneTimeSetUp]
public void SetUp()
{
PythonEngine.Initialize();
}
[OneTimeTearDown]
public void Dispose()
{
PythonEngine.Shutdown();
}
[Test]
public void TestInterfaceDerivedClassMembers()
{
// This test gets an instance of the CSharpTestModule in Python
// and then attempts to access it's member "Child"'s bool that is
// not defined in the interface.
PythonEngine.Exec(testCode);
}
public interface IInterface
{
bool InterfaceBool { get; set; }
}
public class Parent : IInterface
{
public bool InterfaceBool { get; set; }
public bool ParentBool { get; set; }
}
public class Child : Parent
{
public bool ChildBool { get; set; }
}
public class CSharpTestModule
{
public IInterface Child;
public CSharpTestModule()
{
Child = new Child
{
ChildBool = true,
ParentBool = true,
InterfaceBool = true
};
}
}
public static CSharpTestModule GetInstance()
{
return new CSharpTestModule();
}
}
}