Пример #1
0
        public T Dummy <T>()
        {
            var fakeInterface = _fakeChainFactory.CreateFakeOrdinaryInterfaceGenerator <T>();

            if (typeof(T).IsPrimitive)
            {
                return(_fakeChainFactory.GetUnconstrainedInstance <T>().Resolve(this));
            }
            if (typeof(T) == typeof(string))
            {
                return(_fakeChainFactory.GetUnconstrainedInstance <T>().Resolve(this));
            }
            if (TypeOf <T> .IsImplementationOfOpenGeneric(typeof(IEnumerable <>)))
            {
                return(_emptyCollectionFixture.Create <T>());
            }
            if (TypeOf <T> .IsOpenGeneric(typeof(IEnumerable <>)))
            {
                return((T)_emptyCollectionGenerator.EmptyEnumerableOf(typeof(T).GetCollectionItemType()));
            }
            if (typeof(T).IsAbstract)
            {
                return(default(T));
            }
            if (fakeInterface.Applies())
            {
                return(fakeInterface.Apply(this));
            }
            return((T)FormatterServices.GetUninitializedObject(typeof(T)));
        }
Пример #2
0
        public bool Applies()
        {
            var isCollection = TypeOf <T> .IsImplementationOfOpenGeneric(typeof(IProducerConsumerCollection <>)) ||
                               TypeOf <T> .IsImplementationOfOpenGeneric(typeof(ICollection <>));

            return(TypeOf <T> .IsConcrete() &&
                   typeof(T).IsGenericType &&
                   isCollection &&
                   TypeOf <T> .HasParameterlessConstructor());
        }
Пример #3
0
        public T Dummy <T>(GenerationTrace trace)
        {
            var fakeInterface      = _fakeChainFactory.CreateFakeOrdinaryInterfaceGenerator <T>();
            var unconstrainedChain = _fakeChainFactory.GetUnconstrainedInstance <T>();

            if (typeof(T).IsPrimitive)
            {
                return(unconstrainedChain.Resolve(SynchronizedThis, trace));
            }

            if (typeof(T) == typeof(string))
            {
                return(unconstrainedChain.Resolve(SynchronizedThis, trace));
            }

            var emptyCollectionInstantiation = new EmptyCollectionInstantiation();

            if (TypeOf <T> .IsImplementationOfOpenGeneric(typeof(IEnumerable <>)))
            {
                return(emptyCollectionInstantiation.CreateCollectionPassedAsGenericType <T>());
            }

            if (TypeOf <T> .IsOpenGeneric(typeof(IEnumerable <>)))
            {
                return((T)emptyCollectionInstantiation.EmptyEnumerableOf(typeof(T).GetCollectionItemType()));
            }

            if (typeof(T).IsAbstract)
            {
                return(default(T));
            }

            if (fakeInterface.Applies())
            {
                return(fakeInterface.Apply(SynchronizedThis, trace));
            }

            return((T)FormatterServices.GetUninitializedObject(typeof(T)));
        }