コード例 #1
0
        public ClassTester(object subject, IValueCreator valueCreator)
        {
            ValidationUtils.ArgumentNotNull(valueCreator, "valueCreator");
              ValidationUtils.ArgumentNotNull(subject, "subject");

              _valueCreator = valueCreator;
              _subject = subject;
              _subjectType = _subject.GetType();

              if (subject is INotifyPropertyChanged)
              {
            _checkNotifyPropertyChanged = true;
            INotifyPropertyChanged notifyPropertyChanged = (INotifyPropertyChanged)subject;
            notifyPropertyChanged.PropertyChanged += PropertyChanged;
              }
        }
コード例 #2
0
 public MemberData(PropertyInfo propertyInfo, IValueCreator valueCreator)
 {
     _propertyInfo = propertyInfo;
     _valueCreator = valueCreator;
 }
コード例 #3
0
        internal static void TestConstructors(Type type, bool testMappedProperties, IValueCreator valueCreator)
        {
            ValidationUtils.ArgumentNotNull(valueCreator, "valueCreator");

              ConstructorInfo[] constructors = type.GetConstructors(BindingFlags.Public | BindingFlags.Instance);

              foreach (ConstructorInfo constructor in constructors)
              {
            ParameterInfo[] parameters = constructor.GetParameters();
            object[] paramValues = new object[parameters.Length];
            for (int i = 0; i < parameters.Length; i++)
            {
              paramValues[i] = valueCreator.CreateValue(parameters[i].ParameterType);
            }
            object result = constructor.Invoke(paramValues);

            if (testMappedProperties)
            {
              for (int i = 0; i < parameters.Length; i++)
              {
            PropertyInfo mappedProperty = type.GetProperty(
                parameters[i].Name, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance);

            if (mappedProperty != null && mappedProperty.CanRead)
            {
              object valueOut = mappedProperty.GetValue(result, null);

              if (!(Equals(paramValues[i], valueOut)))
              {
                throw new ClassTesterException(string.Format(
                    "The value of the '{0}' property did not equal the value set with the '{1}' constructor parameter (in: '{2}', out: '{3}')",
                    mappedProperty.Name,
                    parameters[i].Name,
                    valueOut,
                    paramValues[i]));
              }
            }
              }
            }
              }
        }