예제 #1
0
        protected TDependency Given <TDependency>()
            where TDependency : class
        {
            Lazy <object> dependency;

            if (!_mocksByType.TryGetValue(typeof(TDependency), out dependency))
            {
                TDependency stub = MockRepository.GenerateStub <TDependency>();

                dynamic list;

                if (_collectionsByType.TryGetValue(typeof(TDependency), out list))
                {
                    list.Add(stub);
                }
                else
                {
                    _mocksByType.Add(typeof(TDependency), new Lazy <object>(() => stub));
                }

                return(stub);
            }

            return((TDependency)dependency.Value);
        }
예제 #2
0
        /// <summary>
        /// Gets a specific dependency from the system under test.
        /// </summary>
        /// <typeparam name="TDependency"></typeparam>
        /// <returns></returns>
        protected TDependency Given <TDependency>()
            where TDependency : class
        {
            if (!_mocksByType.TryGetValue(typeof(TDependency), out Lazy <object> dependency))
            {
                TDependency stub = A.Fake <TDependency>();

                if (_collectionsByType.TryGetValue(typeof(TDependency), out dynamic list))
                {
                    list.Add(stub);
                }
                else
                {
                    _mocksByType.Add(typeof(TDependency), new Lazy <object>(() => stub));
                }

                return(stub);
            }

            return((TDependency)dependency.Value);
        }