public void SetUp()
        {
            BuilderSettings builderSettings = new BuilderSettings();
            IReflectionUtil reflectionUtil  = Substitute.For <IReflectionUtil>();

            reflectionUtil.IsDefaultValue(Arg.Any <int?>()).Returns(true);

            propertyNamer = new PropertyNamerStub(reflectionUtil, builderSettings);
        }
        public RandomValuePropertyNamerTests_LoremIpsumStrings()
        {
            generator      = Substitute.For <IRandomGenerator>();
            reflectionUtil = Substitute.For <IReflectionUtil>();

            reflectionUtil.IsDefaultValue(null).Returns(true);

            theList = new List <MyClass>();

            for (int i = 0; i < listSize; i++)
            {
                theList.Add(new MyClass());
            }

            // The lorem ipsum string generator does this to get a random length of the string
            generator.Next(1, 10).Returns(5);

            new RandomValuePropertyNamer(generator, reflectionUtil, false, DateTime.MinValue, DateTime.MaxValue, true, new BuilderSettings()).SetValuesOfAllIn(theList);
        }
        public void ShouldBeAbleToTellThatReferenceTypeIsDefaultValue()
        {
            const MyClass myObj = null;

            reflectionUtil.IsDefaultValue(myObj).ShouldBeTrue();
        }
Exemple #4
0
        protected virtual void SetMemberValue <T>(MemberInfo memberInfo, T obj)
        {
            Type type = GetMemberType(memberInfo);

            if (BuilderSetup.HasDisabledAutoNameProperties && ShouldIgnore(memberInfo))
            {
                return;
            }

            object currentValue = GetCurrentValue(memberInfo, obj);

            if (!ReflectionUtil.IsDefaultValue(currentValue))
            {
                return;
            }

            object value = null;

            if (type == typeof(short))
            {
                value = GetInt16(memberInfo);
            }

            else if (type == typeof(int))
            {
                value = GetInt32(memberInfo);
            }

            else if (type == typeof(long))
            {
                value = GetInt64(memberInfo);
            }

            else if (type == typeof(decimal))
            {
                value = GetDecimal(memberInfo);
            }

            else if (type == typeof(float))
            {
                value = GetSingle(memberInfo);
            }

            else if (type == typeof(double))
            {
                value = GetDouble(memberInfo);
            }

            else if (type == typeof(ushort))
            {
                value = GetUInt16(memberInfo);
            }

            else if (type == typeof(uint))
            {
                value = GetUInt32(memberInfo);
            }

            else if (type == typeof(ulong))
            {
                value = GetUInt64(memberInfo);
            }

            else if (type == typeof(char))
            {
                value = GetChar(memberInfo);
            }

            else if (type == typeof(byte))
            {
                value = GetByte(memberInfo);
            }

            else if (type == typeof(sbyte))
            {
                value = GetSByte(memberInfo);
            }

            else if (type == typeof(DateTime))
            {
                value = GetDateTime(memberInfo);
            }

            else if (type == typeof(string))
            {
                value = GetString(memberInfo);
            }

            else if (type == typeof(bool))
            {
                value = GetBoolean(memberInfo);
            }

            else if (type.BaseType == typeof(Enum))
            {
                value = GetEnum(memberInfo);
            }

            else if (type == typeof(Guid))
            {
                value = GetGuid(memberInfo);
            }

            else if (type == typeof(TimeSpan))
            {
                value = GetTimeSpan(memberInfo);
            }

            else
            {
                HandleUnknownType(type, memberInfo, obj);
            }

            SetValue(memberInfo, obj, value);
        }