public void CreatesFactoryForDomainObjectWithDefaultConstructor()
        {
            FactoryClassEmitter emitter;
            ICreateDomainObjectWithDefaultConstructor factory;
            IDivineInjector injector;
            IDomainObject obj;

            Scenario()
                .Given(injector = AMock<IDivineInjector>().Instance)
                .Given(emitter = new FactoryClassEmitter(
                    injector,
                    typeof(ICreateDomainObjectWithDefaultConstructor),
                    typeof(DomainObjectWithDefaultConstructor)))

                .When(factory = (ICreateDomainObjectWithDefaultConstructor)emitter.CreateNewObject())
                .When(obj = factory.Create())

                .Then(obj, Is(AnInstance.NotNull()));
        }
        public void CreatesFactoryForDomainObjectWithConstructorWithTwoArgsOfSameType()
        {
            FactoryClassEmitter emitter;
            ICreateDomainObjectWithConstructorWithTwoArgsOfSameType factory;
            IDivineInjector injector;
            DomainObjectWithConstructorWithTwoArgsOfSameType obj;

            Scenario()
                .Given(injector = AMock<IDivineInjector>()
                    .WhereMethod(i => i.IsBound(typeof(string))).Returns(false)
                    .Instance)
                .Given(emitter = new FactoryClassEmitter(
                    injector,
                    typeof(ICreateDomainObjectWithConstructorWithTwoArgsOfSameType),
                    typeof(DomainObjectWithConstructorWithTwoArgsOfSameType)))

                .When(factory = (ICreateDomainObjectWithConstructorWithTwoArgsOfSameType)emitter.CreateNewObject())
                .When(obj = factory.Create("developer", "sarah"))

                .Then(obj, Is(AnInstance.NotNull()))
                .Then(obj.Name, Is(AString.EqualTo("sarah")))
                .Then(obj.Role, Is(AString.EqualTo("developer")));
        }
        public void CreatesFactoryForDomainObjectTwoConstructors()
        {
            FactoryClassEmitter emitter;
            ICreateDomainObjectWithTwoConstructors factory;
            IDivineInjector injector;
            IDomainObjectWithName objWithDefaultName, objWithSpecificName;

            Scenario()
                .Given(injector = AMock<IDivineInjector>()
                    .WhereMethod(i => i.IsBound(typeof(string))).Returns(false)
                    .Instance)
                .Given(emitter = new FactoryClassEmitter(
                    injector,
                    typeof(ICreateDomainObjectWithTwoConstructors),
                    typeof(DomainObjectWithTwoConstructors)))

                .When(factory = (ICreateDomainObjectWithTwoConstructors)emitter.CreateNewObject())
                .When(objWithDefaultName = factory.CreateWithDefaultName())
                .When(objWithSpecificName = factory.CreateWithName("Bob"))

                .Then(objWithSpecificName.Name, Is(AString.EqualTo("Bob")))
                .Then(objWithDefaultName.Name, Is(AString.EqualTo("Fred")));
        }
        public void CreatesFactoryForDomainObjectWithInjectedDependency()
        {
            FactoryClassEmitter emitter;
            ICreateDomainObjectWithOneDependency factory;
            IDivineInjector injector;
            IDatabase database;
            IDomainObject obj;

            Scenario()
                .Given(database = AMock<IDatabase>().Instance)
                .Given(injector = AMock<IDivineInjector>()
                    .WhereMethod(i => i.IsBound(typeof(IDatabase))).Returns(true)
                    .WhereMethod(i => i.Get(typeof(IDatabase))).Returns(database)
                    .Instance)
                .Given(emitter = new FactoryClassEmitter(
                    injector,
                    typeof(ICreateDomainObjectWithOneDependency),
                    typeof(DomainObjectWithOneDependency)))

                .When(factory = (ICreateDomainObjectWithOneDependency)emitter.CreateNewObject())
                .When(obj = factory.Create())

                .Then(obj, Is(AnInstance.NotNull()))
                .Then(((DomainObjectWithOneDependency)obj).Database, Is(AnInstance.SameAs(database)));
        }
        public void CreatesFactoryForDomainObjectWithPassedArgument()
        {
            FactoryClassEmitter emitter;
            ICreateDomainObjectWithSingleArgConstructor factory;
            IDivineInjector injector;
            IDomainObjectWithName obj;

            Scenario()
                .Given(injector = AMock<IDivineInjector>()
                    .WhereMethod(i => i.IsBound(typeof(string))).Returns(false)
                    .Instance)
                .Given(emitter = new FactoryClassEmitter(
                    injector,
                    typeof(ICreateDomainObjectWithSingleArgConstructor),
                    typeof(DomainObjectWithSingleArgConstructor)))

                .When(factory = (ICreateDomainObjectWithSingleArgConstructor)emitter.CreateNewObject())
                .When(obj = factory.Create("bob"))

                .Then(obj, Is(AnInstance.NotNull()))
                .Then(obj.Name, Is(AString.EqualTo("bob")));
        }
        public void CreatesFactoryForDomainObjectWithInjectedDependencyAndArgument()
        {
            FactoryClassEmitter emitter;
            ICreateDomainObjectWithDependencyAndArg factory;
            IDivineInjector injector;
            IDatabase database;
            IDomainObjectWithName obj;

            Scenario()
                .Given(database = AMock<IDatabase>().Instance)
                .Given(injector = AMock<IDivineInjector>()
                    .WhereMethod(i => i.IsBound(typeof(IDatabase))).Returns(true)
                    .WhereMethod(i => i.IsBound(typeof(string))).Returns(false)
                    .WhereMethod(i => i.Get(typeof(IDatabase))).Returns(database)
                    .Instance)
                .Given(emitter = new FactoryClassEmitter(
                    injector,
                    typeof(ICreateDomainObjectWithDependencyAndArg),
                    typeof(DomainObjectWithDependencyAndArg)))

                .When(factory = (ICreateDomainObjectWithDependencyAndArg)emitter.CreateNewObject())
                .When(obj = factory.Create("Fred"))

                .Then(obj, Is(AnInstance.NotNull()))
                .Then(((DomainObjectWithDependencyAndArg)obj).Database, Is(AnInstance.SameAs(database)))
                .Then(obj.Name, Is(AString.EqualTo("Fred")));
        }