Example #1
0
 private BuildDetails GetSimpleClassDetails()
 {
     return(new BuildDetails
     {
         ConstructorToUse = UtilityExtensions.GetConstructors(typeof(SimpleClass)).First(),
         TypeToCreate = typeof(SimpleClass)
     });
 }
Example #2
0
 private BuildDetails GetComplexClassDetails()
 {
     return(new BuildDetails()
     {
         ConstructorToUse = UtilityExtensions
                            .GetConstructors(typeof(ComplexClass))
                            .FirstOrDefault(t => t.GetParameters().Count() == 1),
         TypeToCreate = typeof(ComplexClass),
         Dependencies = new List <BuildDetails> {
             GetSimpleClassDetails()
         }
     });
 }
Example #3
0
        public void BuildParameterlessClass()
        {
            RegistrationDetails details = new RegistrationDetails
            {
                ResolvedType = typeof(SimpleClass),
                Instructions = new BuildDetails
                {
                    ConstructorToUse = UtilityExtensions.GetConstructors(typeof(SimpleClass)).First(),
                    TypeToCreate     = typeof(SimpleClass)
                }
            };

            var ctor = new ObjectConstructor();
            var obj  = ctor.Build(details.Instructions);

            Assert.NotNull(obj as SimpleClass);
        }
Example #4
0
        public void BuildClassWithMultipleParameterConstructor()
        {
            var complexDetails = GetComplexClassDetails();
            var simpleDetails  = GetSimpleClassDetails();
            var rootDetails    = new BuildDetails
            {
                ConstructorToUse = UtilityExtensions.GetConstructors(typeof(MultipleConstructorParamsClass)).First(),
                TypeToCreate     = typeof(MultipleConstructorParamsClass),
                Dependencies     = new List <BuildDetails>
                {
                    simpleDetails,
                    complexDetails
                }
            };

            ObjectConstructor ctor = new ObjectConstructor();
            var builtObject        = ctor.Build(rootDetails) as MultipleConstructorParamsClass;

            Assert.NotNull(builtObject);
            Assert.NotNull(builtObject.Simple);
            Assert.NotNull(builtObject.Complex);
        }
        public void GetPublicNonStaticConstructors()
        {
            var results = UtilityExtensions.GetConstructors(typeof(ComplexClass));

            Assert.Equal(1, results.Count());
        }