1 /**
2  * Unit tests for componentTypeProvider.d
3  *
4  */
5 module componentTypeProvider_test;
6 
7 import ashd.core.component            : Component;
8 import ashd.fsm.componentTypeProvider : ComponentTypeProvider;
9 
10 int main()
11 {
12     (new ComponentTypeProviderTests).providerReturnsAnInstanceOfType();
13     (new ComponentTypeProviderTests).providerReturnsNewInstanceEachTime();
14     (new ComponentTypeProviderTests).providersWithSameTypeHaveSameIdentifier();
15     (new ComponentTypeProviderTests).providersWithDifferentTypeHaveDifferentIdentifier();
16 
17     return 0;
18 }
19 
20 
21 public class ComponentTypeProviderTests
22 {
23     public void providerReturnsAnInstanceOfType()
24     {
25         ComponentTypeProvider provider = new ComponentTypeProvider( typeid(MockComponent) );
26         assert( provider.getComponent!MockComponent().classinfo == MockComponent.classinfo );
27     }
28 
29     public void providerReturnsNewInstanceEachTime()
30     {
31         ComponentTypeProvider provider = new ComponentTypeProvider( typeid(MockComponent) );
32         assert( provider.getComponent!MockComponent() !is provider.getComponent!MockComponent() );
33     }
34 
35     public void providersWithSameTypeHaveSameIdentifier()
36     {
37         ComponentTypeProvider provider1 = new ComponentTypeProvider( typeid(MockComponent) );
38         ComponentTypeProvider provider2 = new ComponentTypeProvider( typeid(MockComponent) );
39         assert( provider1.identifier == provider2.identifier );
40     }
41 
42     public void providersWithDifferentTypeHaveDifferentIdentifier()
43     {
44         ComponentTypeProvider provider1 = new ComponentTypeProvider( typeid(MockComponent) );
45         ComponentTypeProvider provider2 = new ComponentTypeProvider( typeid(MockComponent2) );
46         assert( provider1.identifier != provider2.identifier );
47     }
48 }
49 
50 class MockComponent
51 {
52     public int value;
53 }
54 
55 class MockComponent2
56 {
57     public string value;
58 }