Exemple #1
0
        private static void InitializeMockedField(object target, FieldInfo mockField, MockAttribute mockAttribute)
        {
            var fieldType = mockField.FieldType;
            var mock      = NMockitoStatic.CreateMock(fieldType, mockAttribute.Tracked);

            mockField.SetValue(target, mock);

            var staticType = mockAttribute.StaticType;

            if (staticType != null)
            {
                var staticFields         = staticType.GetFields(BindingFlags.NonPublic | BindingFlags.Static);
                var staticInstanceFields = staticFields.Where(field => field.Name.EndsWith("instance") && field.FieldType == fieldType).ToArray();
                if (staticInstanceFields.Length != 1)
                {
                    throw new AmbiguousMatchException("NMockito unable to determine instance field of static " + staticType.FullName + " candidates " + string.Join(", ", staticInstanceFields.Select(f => f.Name).ToArray()));
                }
                else
                {
                    staticInstanceFields.First().SetValue(null, mock);
                }
            }
        }
Exemple #2
0
 [DebuggerHidden] public object CreateMock(Type type)
 {
     return(NMockitoStatic.CreateMock(type));
 }
Exemple #3
0
 [DebuggerHidden] public T CreateMock <T>() where T : class
 {
     return(NMockitoStatic.CreateMock <T>());
 }