public FactoryClassEmitter(IDivineInjector injector, Type interfaceType, Type domainObjectType) { m_interfaceType = interfaceType; m_injector = injector; m_domainObjectType = domainObjectType; m_tb = GetTypeBuilder(interfaceType); m_factoryClassFactory = new FactoryClassFactory(new FactoryMethodFactory()); }
public void CreatesFactoryClass() { IFactoryMethodFactory methodFactory; FactoryClassFactory classFactory; IDivineInjector injector; FactoryClass createdClass; IFactoryMethod method1; IFactoryMethod method2; Scenario() .Given(method1 = AMock<IFactoryMethod>() .WhereGet(m => m.ConstructorArgs).Returns(new List<IConstructorArgDefinition>()) .Instance) .Given(method2 = AMock<IFactoryMethod>() .WhereGet(m => m.ConstructorArgs).Returns(new List<IConstructorArgDefinition>()) .Instance) .Given(injector = AMock<IDivineInjector>().Instance) .Given(methodFactory = AMock<IFactoryMethodFactory>() .WhereMethod(f => f.Create( ArgIs(AMethodInfo.With().Name("MethodWithDependencyOnly")), injector, typeof(DomainObjectWithDependencyAndArg))) .Returns(method1) .WhereMethod(f => f.Create( ArgIs(AMethodInfo.With().Name("MethodWithDependencyAndArg")), injector, typeof(DomainObjectWithDependencyAndArg))) .Returns(method2) .Instance) .Given(classFactory = new FactoryClassFactory(methodFactory)) .When(createdClass = classFactory.Create(typeof(IFactoryInterfaceWithTwoMethods), injector, typeof(DomainObjectWithDependencyAndArg), new ConstructorArgList(null))) .Then(createdClass.Methods, Is(AList.InOrder().WithOnly( AnInstance.SameAs(method1), AnInstance.SameAs(method2)))); }