Exemplo n.º 1
0
 private Mock GetOrMakeMockFor(Type type)
 {
     if (!typeMap.ContainsKey(type) || !typeMap[type].IsMock)
     {
         typeMap[type] = new MockInstance(type, mockBehavior);
     }
     return(((MockInstance)typeMap[type]).Mock);
 }
Exemplo n.º 2
0
        /// <summary>
        /// Combines all given types so that they are mocked by the same
        /// mock. Some IoC containers call this "Forwarding" one type to
        /// other interfaces. In the end, this just means that all given
        /// types will be implemnted by the same instance.
        /// </summary>
        public void Combine(Type type, params Type[] forwardTo)
        {
            var mockObject = new MockInstance(type, mockBehavior);

            forwardTo.Aggregate(mockObject.Mock, As);

            foreach (var serviceType in forwardTo.Concat(new[] { type }))
            {
                typeMap[serviceType] = mockObject;
            }
        }
Exemplo n.º 3
0
        private IInstance CreateMockObjectAndStore(Type type)
        {
            if (type.IsArray)
            {
                Type elmType = type.GetElementType();

                MockArrayInstance instance = new MockArrayInstance(elmType);
                if (typeMap.ContainsKey(elmType))
                {
                    instance.Add(typeMap[elmType]);
                }
                return(typeMap[type] = instance);
            }
            return(typeMap[type] = new MockInstance(type, mockBehavior));
        }
Exemplo n.º 4
0
 /// <summary>
 /// Adds an intance to the container.
 /// </summary>
 /// <typeparam name="TService">The type that the instance will be registered as</typeparam>
 /// <param name="mockedService"></param>
 public void Use <TService>(Mock <TService> mockedService)
     where TService : class
 {
     typeMap[typeof(TService)] = new MockInstance(mockedService);
 }