Exemplo n.º 1
0
        public TClassUnderTest Build()
        {
            var constructorParams = new List <object>();
            var constructors      = (typeof(TClassUnderTest)).GetConstructors();

            if (constructors.Length > 1)
            {
                throw new InvalidOperationException("Cannot Test Types with multiple constructors - Code Smell");
            }

            var constructor = constructors[0];
            var parameters  = constructor.GetParameters();

            foreach (var parameter in parameters)
            {
                var parametType = parameter.ParameterType;
                if (!parametType.GetTypeInfo().IsAbstract&& !parametType.GetTypeInfo().IsInterface)
                {
                    throw new InvalidOperationException("Use more appropriate types (interface or abstract) for your dependencies");
                }

                constructorParams.Add(MockRegistry.Get(parameter.ParameterType));
            }

            var instance = constructor.Invoke(constructorParams.ToArray());

            return((TClassUnderTest)instance);
        }
Exemplo n.º 2
0
 public Mock <TMockType> Mock <TMockType>() where TMockType : class
 {
     return(MockRegistry.Get <TMockType>());
 }
Exemplo n.º 3
0
 public MockRegistryTests()
 {
     this.ClassUnderTest = new MockRegistry();
 }