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