1 /** 2 * Unit tests for dynamicComponentProvider.d 3 * 4 */ 5 module dynamicComponentProvider_test; 6 7 import ashd.core.component : Component; 8 import ashd.fsm.dynamicComponentProvider : DynamicComponentProvider; 9 10 int main() 11 { 12 (new DynamicComponentProviderTests).providerReturnsTheInstance(); 13 (new DynamicComponentProviderTests).providersWithSameMethodHaveSameIdentifier(); 14 (new DynamicComponentProviderTests).providersWithDifferentMethodsHaveDifferentIdentifier(); 15 16 return 0; 17 } 18 19 20 21 22 public class DynamicComponentProviderTests 23 { 24 public void providerReturnsTheInstance() 25 { 26 MockComponent instance = new MockComponent(); 27 Object providerMethod() { return instance; } 28 auto provider = new DynamicComponentProvider!MockComponent( &providerMethod ); 29 assert( provider.getComponent!MockComponent() is instance ); 30 } 31 32 public void providersWithSameMethodHaveSameIdentifier() 33 { 34 MockComponent instance = new MockComponent(); 35 Object providerMethod() { return instance; } 36 auto provider1 = new DynamicComponentProvider!MockComponent( &providerMethod ); 37 auto provider2 = new DynamicComponentProvider!MockComponent( &providerMethod ); 38 assert( provider1.identifier == provider2.identifier ); 39 } 40 41 public void providersWithDifferentMethodsHaveDifferentIdentifier() 42 { 43 MockComponent instance = new MockComponent(); 44 Object providerMethod1() { return instance; } 45 Object providerMethod2() { return instance; } 46 auto provider1 = new DynamicComponentProvider!MockComponent( &providerMethod1 ); 47 auto provider2 = new DynamicComponentProvider!MockComponent( &providerMethod2 ); 48 assert( provider1.identifier != provider2.identifier); 49 } 50 } 51 52 class MockComponent 53 { 54 public int value; 55 }