Example #1
0
        /// <summary>
        /// Freeze a specific type
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="fixture"></param>
        /// <param name="parameter"></param>
        /// <param name="freezeAttribute"></param>
        /// <returns></returns>
        private static T Freeze <T>(Fixture fixture, ParameterInfo parameter, FreezeAttribute freezeAttribute)
        {
            T value;

            if (freezeAttribute.Value is T)
            {
                value = (T)freezeAttribute.Value;
            }
            else
            {
                object min            = null;
                object max            = null;
                string constraintName = null;

                if (freezeAttribute != null)
                {
                    min            = freezeAttribute.Min;
                    max            = freezeAttribute.Max;
                    constraintName = freezeAttribute.ConstraintName;
                }

                if (string.IsNullOrEmpty(constraintName))
                {
                    constraintName = parameter.Name;
                }

                value = fixture.Generate <T>(parameter.Name);
            }

            if (freezeAttribute.For != null)
            {
                fixture.Return(value).For(freezeAttribute.For);
            }
            else
            {
                fixture.Return(value);
            }

            return(value);
        }
Example #2
0
        /// <summary>
        /// Freeze value in fixture
        /// </summary>
        /// <param name="fixture"></param>
        /// <param name="parameter"></param>
        /// <param name="freezeAttribute"></param>
        /// <returns></returns>
        private static object FreezeValue(Fixture fixture, ParameterInfo parameter, FreezeAttribute freezeAttribute)
        {
            var closedMethod = FreezeMethod.MakeGenericMethod(parameter.ParameterType);

            return(closedMethod.Invoke(null, new object[] { fixture, parameter, freezeAttribute }));
        }