コード例 #1
0
        //protected virtual int GetPrecision(T val)
        //{
        //    double d = Math.Abs(Convert.ToDouble(val));
        //    string asString = d.ToString("E25", System.Globalization.CultureInfo.InvariantCulture);

        //    asString = asString.Substring(0, asString.IndexOf("E"));
        //    asString = asString.Trim('0');

        //    int digits = asString.Length - 1; // ignore decimal point
        //    return digits;
        //}

        public override NodeValue CreateRandomValueForFacets(NodeFacets propertyFacets)
        {
            T f = MinValue;

            try
            {
                int r = AstoriaTestProperties.Random.Next(50);
                if (r < SpecialValues.Length)
                {
                    f = SpecialValues[r];
                }
                else
                {
                    double d = Convert.ToDouble(Range);
                    d *= AstoriaTestProperties.Random.NextDouble();
                    d += Convert.ToDouble(MinValue);

                    // 1/4 of the time, generate one that doesn't have a fractional component
                    //
                    if (AstoriaTestProperties.Random.Next(4) == 0)
                    {
                        d = (Single)Math.Floor(d);
                    }

                    string format   = String.Format("G{0}", Precision);
                    string asString = d.ToString(format, System.Globalization.CultureInfo.InvariantCulture);
                    d = double.Parse(asString);
                    f = Cast(d);
                }
            }
            catch (Exception)
            { }
            return(new NodeValue(f, this));
        }
コード例 #2
0
ファイル: Node.cs プロジェクト: zhonli/odata.net
 public Node(String name, string nodeNamespace, params Node[] facets)
     : base(name)
 {
     _namespace = nodeNamespace;
     _desc      = this.GetType().Name;
     _facets    = new NodeFacets(this, facets.OfType <NodeFacet>());
     _other     = new Nodes <Node>(this, facets.Except(_facets.OfType <Node>()));
 }
コード例 #3
0
        //Data

        //Constructor

        //Accessors
        public override NodeValue CreateRandomValueForFacets(NodeFacets propertyFacets)
        {
            bool isFixedLength = propertyFacets.FixedLength;

            if (propertyFacets.MaxSize != null)
            {
                return(CreateRandomValue((int)propertyFacets.MaxSize.Value, isFixedLength));
            }

            return(CreateRandomValue());
        }
コード例 #4
0
        public override NodeValue CreateRandomValueForFacets(NodeFacets propertyFacets)
        {
            DateTime minValue = this.MinValue;
            DateTime maxValue = this.MaxValue;

            DateTime temp;

            if (propertyFacets.TryGetMaxValue(out temp) && temp < maxValue)
            {
                maxValue = temp;
            }
            if (propertyFacets.TryGetMinValue(out temp) && temp > minValue)
            {
                minValue = temp;
            }

            return(CreateRandomValue(minValue, maxValue));
        }
コード例 #5
0
        public override NodeValue CreateRandomValueForFacets(NodeFacets propertyFacets)
        {
            long max = MaxValue;
            long min = MinValue;

            T temp;

            if (propertyFacets.TryGetMaxValue(out temp) && Wrap(temp) < max)
            {
                max = Wrap(temp);
            }
            if (propertyFacets.TryGetMinValue(out temp) && Wrap(temp) > min)
            {
                min = Wrap(temp);
            }

            long value = CreateRandomValue(min, max);

            return(new NodeValue(UnWrap(value), this));
        }
コード例 #6
0
        public override NodeValue CreateRandomValueForFacets(NodeFacets propertyFacets)
        {
            fxList <byte> bytes      = new fxList <byte>();
            int           maxSize    = propertyFacets.MaxSize != null ? propertyFacets.MaxSize.Value : 512;
            int           actualSize = maxSize;

            if (!propertyFacets.FixedLength)
            {
                //Set max size to be random
                actualSize = AstoriaTestProperties.Random.Next(maxSize);
                if (actualSize > 1000)
                {
                    actualSize = 1000;
                }
            }
            for (int i = 0; i < actualSize; i++)
            {
                bytes.Add((byte)AstoriaTestProperties.Random.Next(byte.MinValue, byte.MaxValue));
            }
            return(new NodeValue(new System.Data.Linq.Binary(bytes.ToArray()), this));
        }
コード例 #7
0
ファイル: UpdateTree.cs プロジェクト: zhonli/odata.net
 public ResourceInstanceSimpleProperty(NodeFacets facets, string propertyName, object propertyValue)
     : this(propertyName, propertyValue, false)
 {
     base.Facets.Add(facets);
 }
コード例 #8
0
 public override NodeValue CreateRandomValueForFacets(NodeFacets propertyFacets)
 {
     // TODO: Add some random goo
     return(new NodeValue(new System.Xml.Linq.XElement("Root"), this));
 }
コード例 #9
0
        //Data

        //Constructor

        //Accessors
        public override NodeValue CreateRandomValueForFacets(NodeFacets propertyFacets)
        {
            int maxSize = propertyFacets.MaxSize != null ? propertyFacets.MaxSize.Value : 512;

            return(CreateRandomValue(maxSize, propertyFacets.FixedLength));
        }
コード例 #10
0
        //Data

        //Constructor

        //Accessors
        public override NodeValue CreateRandomValueForFacets(NodeFacets propertyFacets)
        {
            if (propertyFacets.Precision != null && propertyFacets.Scale != null)
            {
                //ISSUE: Small money has a range - 214,748.3648 through +214,748.3647
                // In order to always make this work, reducing the Pre by 1 does this

                decimal?max = null;
                decimal?min = null;
                decimal temp;
                if (propertyFacets.TryGetMaxValue(out temp))
                {
                    max = temp;
                }
                if (propertyFacets.TryGetMinValue(out temp))
                {
                    min = temp;
                }

                int scale     = propertyFacets.Scale.Value;
                int precision = propertyFacets.Precision.Value;
                if (precision > 28)
                {
                    precision = 28; //can't exceed CLR limit
                }
                Decimal[] specialValues = new Decimal[] { Decimal.MinValue, Decimal.MinusOne, Decimal.Zero, Decimal.One, Decimal.MaxValue };
                Decimal?  value         = null;
                int       random        = AstoriaTestProperties.Random.Next(50 + specialValues.Length);
                if (random < specialValues.Length)
                {
                    value = specialValues[random];
                    string asString = Math.Abs(value.Value).ToString();

                    // is there enough precision?
                    if (asString.Length >= precision)
                    {
                        value = null;
                    }

                    // is there enough scale?
                    if (asString.Length - asString.IndexOf('.') >= scale)
                    {
                        value = null;
                    }

                    // is it too big?
                    if (max.HasValue && value > max)
                    {
                        value = null;
                    }

                    // is it too small?
                    if (min.HasValue && value < min)
                    {
                        value = null;
                    }
                }

                if (value == null)
                {
                    bool negative = (random % 2 == 0);
                    if (min.HasValue && min >= decimal.Zero)
                    {
                        negative = false;
                    }

                    int fractionLength = AstoriaTestProperties.Random.Next(scale);
                    int integerLength  = AstoriaTestProperties.Random.Next(precision - scale); //assume that it will be padded to the maximum scale

                    if (max.HasValue && max <= decimal.One && !negative)
                    {
                        integerLength = 0;
                    }

                    StringBuilder builder = new StringBuilder();
                    if (negative)
                    {
                        builder.Append('-');
                    }

                    if (integerLength == 0)
                    {
                        builder.Append('0');
                    }
                    else
                    {
                        for (int i = 0; i < integerLength; i++)
                        {
                            builder.Append(AstoriaTestProperties.Random.Next(10));
                        }
                    }

                    if (fractionLength > 0)
                    {
                        builder.Append('.');
                        for (int i = 0; i < fractionLength; i++)
                        {
                            builder.Append(AstoriaTestProperties.Random.Next(10));
                        }
                    }

                    string asString = builder.ToString();

                    SqlDecimal sqlValue = SqlDecimal.Parse(builder.ToString());
                    value = sqlValue.Value;

                    try
                    {
                        SqlDecimal.ConvertToPrecScale(sqlValue, precision, scale); //in case the DB wants it to use the whole scale
                    }
                    catch (Exception e)
                    {
                        throw new TestFailedException(String.Format("Generated decimal value '{0}' exceeds precision/scale specified", asString), null, null, e);
                    }
                }

                return(new NodeValue(value.Value, this));
            }
            else
            {
                return(this.CreateRandomValue());
            }
        }
コード例 #11
0
 public virtual NodeValue CreateValueForFacets(NodeFacets propertyFacets)
 {
     return(this.CreateValue());
 }