Example #1
0
        public void Add_nuint()
        {
            IStack <nuint> stack = new BoundedArray <nuint>(1, 2);

            stack.Add();
            Assert.That(stack.Pop()).Equals(3);
        }
Example #2
0
        public void Add_Decimal()
        {
            IStack <Decimal> stack = new BoundedArray <Decimal>(1.0m, 2.0m);

            stack.Add();
            Assert.That(stack.Pop()).Equals(3.0m);
        }
Example #3
0
        public void Add_Double()
        {
            IStack <Double> stack = new BoundedArray <Double>(1.0, 2.0);

            stack.Add();
            Assert.That(stack.Pop()).Equals(3.0);
        }
Example #4
0
        public void Add_Single()
        {
            IStack <Single> stack = new BoundedArray <Single>(1.0f, 2.0f);

            stack.Add();
            Assert.That(stack.Pop()).Equals(3.0f);
        }
Example #5
0
        public void Add_UInt64()
        {
            IStack <UInt64> stack = new BoundedArray <UInt64>(1, 2);

            stack.Add();
            Assert.That(stack.Pop()).Equals(3);
        }
Example #6
0
        public void Add_Int32()
        {
            IStack <Int32> stack = new BoundedArray <Int32>(1, 2);

            stack.Add();
            Assert.That(stack.Pop()).Equals(3);
        }
Example #7
0
        /// <summary>
        /// Converts a string value to a binary array based on the column definition
        /// </summary>
        /// <param name="value">The value to convert</param>
        /// <param name="columnDefinition">The column definition (Example: "VARCHAR(10)")</param>
        /// <returns>A byte array of the value</returns>
        /// <exception cref="System.InvalidOperationException">Thrown if the column definition size is greater than the actual value</exception>
        public static byte[] StringToBinary(string value, string columnDefinition)
        {
            byte[] result = null;
            // to do: need to parse the column definition to make sure that the size of the string field is not
            // longer than the actual value

            // VARCHAR(20)
            value = value.Replace("'", string.Empty);

            string[] lengthDefinition = columnDefinition.Split('(', ')');
            int      length           = Convert.ToInt32(lengthDefinition[1]);
            int      indexLengthStart = columnDefinition.IndexOf('(');
            string   definition       = columnDefinition.Substring(0, indexLengthStart);

            if (definition.Equals("VARCHAR"))
            {
                var item  = new BoundedArray <char>(length);
                var items = value.ToCharArray();
                foreach (var x in items)
                {
                    item.Add(x);
                }

                if (item.Length < length)
                {
                    int spacesRemaining = length - item.Length;
                    for (int x = item.Length + 1; x < length; x++)
                    {
                        item[x] = Char.MinValue; // will I regret this? probably.
                    }
                }

                char[] temp = new char[length];
                int    k    = 0;
                foreach (var y in item)
                {
                    temp[k] = y;
                    k++;
                }

                result = Encoding.UTF8.GetBytes(temp);
            }

            if (definition.Equals("NVARCHAR"))
            {
                throw new NotImplementedException();
            }

            if (definition.Equals("CHAR"))
            {
                throw new NotImplementedException();
            }


            // this method should handle the following SQL types: NVARCHAR, VARCHAR, CHAR
            return(result);
        }