public void RegisterFactoryFunction_ShouldThrowWhenFactoryFunctionAlreadyExistsForType()
        {
            var col = new EntityFactoryFunctionCollection();
            col.RegisterFactoryFunction(() => new SimpleTestEntity());

            Assert.Throws<ArgumentException>(() =>
                col.RegisterFactoryFunction(() => new SimpleTestEntity()));
        }
        public void RegisterFactoryFunction_ShouldAddMethodThatTakesNoParameters()
        {
            var expected = new SimpleTestEntity();
            var col = new EntityFactoryFunctionCollection();
            col.RegisterFactoryFunction(() => expected);

            var factoryFunction = col.GetFactoryFunction<SimpleTestEntity>();

            Assert.Same(expected, factoryFunction(null));
        }
        public void RegisterFactories_ShouldRegisterMethodsOfObjectThatTakeNoParam()
        {
            var collection = new EntityFactoryFunctionCollection();

            var factoryClass = new FactoryClassWithNoParam();
            collection.RegisterFactories(factoryClass);

            var factoryFunction = collection.GetFactoryFunction<SimpleTestEntity>();

            Assert.Equal(factoryClass.SimpleTestEntity, factoryFunction(new Factory()));
        }
        public void RegisterFactories_ShouldRegisterMethodsOfObjectThatTakeFactoryParam()
        {
            var collection = new EntityFactoryFunctionCollection();

            var factoryClass = new FactoryClassWithParam();
            collection.RegisterFactories(factoryClass);

            var factoryFunction = collection.GetFactoryFunction<EntityWithMoneyProperty>();

            var expectedFactory = new Factory();
            Assert.Equal(factoryClass.EntityWithMoneyProperty, factoryFunction(expectedFactory));
            Assert.Equal(factoryClass.PassedFactory, expectedFactory);
        }
        public void RegisterFactoryFunction_ShouldAddMethodThatTakesFactory()
        {
            var expectedFactory = new Factory();
            var col = new EntityFactoryFunctionCollection();
            Factory passed = null;
            col.RegisterFactoryFunction(f =>
                                            {
                                                passed = f;
                                                return new SimpleTestEntity();
                                            });

            var factoryFunction = col.GetFactoryFunction<SimpleTestEntity>();
            factoryFunction(expectedFactory);

            Assert.Same(expectedFactory, passed);
        }