Example #1
0
        static BuilderObjetoDatos()
        {
            _rnd       = new Random();
            _delegados = new Dictionary <Type, Action <IObjetoDatos, IPropiedad> >(16);

            _delegados[typeof(bool)]     = (od, propiedad) => od.EstablecerBoolean(propiedad, true);
            _delegados[typeof(byte)]     = (od, propiedad) => od.EstablecerByte(propiedad, byte.MaxValue);
            _delegados[typeof(char)]     = (od, propiedad) => od.EstablecerChar(propiedad, char.MaxValue);
            _delegados[typeof(DateTime)] = (od, propiedad) => od.EstablecerDateTime(propiedad, DateTime.Now);                            //DateTime.MaxValue);
            _delegados[typeof(decimal)]  = (od, propiedad) => od.EstablecerDecimal(propiedad, (decimal)_rnd.NextDouble() * _rnd.Next()); //decimal.MaxValue);
            _delegados[typeof(double)]   = (od, propiedad) => od.EstablecerDouble(propiedad, _rnd.NextDouble() * _rnd.Next());           //double.MaxValue);
            _delegados[typeof(float)]    = (od, propiedad) => od.EstablecerFloat(propiedad, float.MaxValue);
            _delegados[typeof(int)]      = (od, propiedad) => od.EstablecerInteger(propiedad, int.MaxValue);
            _delegados[typeof(long)]     = (od, propiedad) => od.EstablecerLong(propiedad, long.MaxValue);
            _delegados[typeof(sbyte)]    = (od, propiedad) => od.EstablecerSByte(propiedad, sbyte.MaxValue);
            _delegados[typeof(short)]    = (od, propiedad) => od.EstablecerShort(propiedad, short.MaxValue);
            _delegados[typeof(string)]   = (od, propiedad) => od.EstablecerString(propiedad, "texto");
            _delegados[typeof(uint)]     = (od, propiedad) => od.EstablecerUInteger(propiedad, uint.MaxValue);
            _delegados[typeof(ulong)]    = (od, propiedad) => od.EstablecerULong(propiedad, ulong.MaxValue);
            _delegados[typeof(ushort)]   = (od, propiedad) => od.EstablecerUShort(propiedad, ushort.MaxValue);

            _tipo = HelperTipo.ObtenerTipo(); // BuilderTipo.Construir();

            _od = Construir(_tipo, 1, 6);
            _od.EstablecerInteger("atributoId", 0);
            _od.EstablecerString("atributoString", "Objeto agregado");
        }
Example #2
0
        public void EvaluarObjetoDatosPathObtenerPorTipo()
        {
            IObjetoDatos od = Helper.Crear(_tipox);

            Helper.Construir(od, 2, 0);

            string ruta = "ReferenciaObjetoDatos";

            bool     valorBoolean  = true;
            byte     valorByte     = 125;
            char     valorChar     = 'D';
            DateTime valorDateTime = DateTime.Now;
            decimal  valorDecimal  = new decimal(15896658.100245);
            double   valorDouble   = 448995.55698;
            float    valorFloat    = (float)56625.55;
            int      valorInteger  = -102458;
            long     valorLong     = -89665522321;
            sbyte    valorSByte    = 89;
            short    valorShort    = 5444;
            string   valorString   = "cadena de texto";
            uint     valorUInteger = 89955212;
            ulong    valorULong    = 788554421056;
            ushort   valorUShort   = 9035;

            od.EstablecerBoolean($"{ruta}/atributoBoolean", valorBoolean);
            od.EstablecerByte($"{ruta}/atributoByte", valorByte);
            od.EstablecerChar($"{ruta}/atributoChar", valorChar);
            od.EstablecerDateTime($"{ruta}/atributoDateTime", valorDateTime);
            od.EstablecerDecimal($"{ruta}/atributoDecimal", valorDecimal);
            od.EstablecerDouble($"{ruta}/atributoDouble", valorDouble);
            od.EstablecerFloat($"{ruta}/atributoFloat", valorFloat);
            od.EstablecerInteger($"{ruta}/atributoInteger", valorInteger);
            od.EstablecerLong($"{ruta}/atributoLong", valorLong);
            od.EstablecerSByte($"{ruta}/atributoSByte", valorSByte);
            od.EstablecerShort($"{ruta}/atributoShort", valorShort);
            od.EstablecerString($"{ruta}/atributoString", valorString);
            od.EstablecerUInteger($"{ruta}/atributoUInteger", valorUInteger);
            od.EstablecerULong($"{ruta}/atributoULong", valorULong);
            od.EstablecerUShort($"{ruta}/atributoUShort", valorUShort);

            Assert.AreEqual(valorBoolean, od.ObtenerBoolean($"{ruta}/atributoBoolean"));
            Assert.AreEqual(valorByte, od.ObtenerByte($"{ruta}/atributoByte"));
            Assert.AreEqual(valorChar, od.ObtenerChar($"{ruta}/atributoChar"));
            Assert.AreEqual(valorDateTime, od.ObtenerDateTime($"{ruta}/atributoDateTime"));
            Assert.AreEqual(valorDecimal, od.ObtenerDecimal($"{ruta}/atributoDecimal"));
            Assert.AreEqual(valorDouble, od.ObtenerDouble($"{ruta}/atributoDouble"));
            Assert.AreEqual(valorFloat, od.ObtenerFloat($"{ruta}/atributoFloat"));
            Assert.AreEqual(valorInteger, od.ObtenerInteger($"{ruta}/atributoInteger"));
            Assert.AreEqual(valorLong, od.ObtenerLong($"{ruta}/atributoLong"));
            Assert.AreEqual(valorSByte, od.ObtenerSByte($"{ruta}/atributoSByte"));
            Assert.AreEqual(valorShort, od.ObtenerShort($"{ruta}/atributoShort"));
            Assert.AreEqual(valorString, od.ObtenerString($"{ruta}/atributoString"));
            Assert.AreEqual(valorUInteger, od.ObtenerUInteger($"{ruta}/atributoUInteger"));
            Assert.AreEqual(valorULong, od.ObtenerULong($"{ruta}/atributoULong"));
            Assert.AreEqual(valorUShort, od.ObtenerUShort($"{ruta}/atributoUShort"));
        }
Example #3
0
        public void EvaluarEstablecerPorTipoPorNombre()
        {
            IObjetoDatos od  = Fabrica.Instancia.Crear(_tipo);
            Random       rnd = new Random();

            bool     valorBoolean  = true;
            byte     valorByte     = byte.MaxValue;
            char     valorChar     = char.MaxValue;
            DateTime valorDateTime = DateTime.MaxValue;
            decimal  valorDecimal  = decimal.MaxValue;
            double   valorDouble   = double.MaxValue;
            float    valorFloat    = float.MaxValue;
            int      valorInteger  = int.MaxValue;
            long     valorLong     = long.MaxValue;
            sbyte    valorSByte    = sbyte.MaxValue;
            short    valorShort    = short.MaxValue;
            string   valorString   = "abcdefghijklmnoprstuvwxyz";
            uint     valorUInteger = uint.MaxValue;
            ulong    valorULong    = ulong.MaxValue;
            ushort   valorUShort   = ushort.MaxValue;

            od.EstablecerBoolean("atributoBoolean", valorBoolean);
            od.EstablecerByte("atributoByte", valorByte);
            od.EstablecerChar("atributoChar", valorChar);
            od.EstablecerDateTime("atributoDateTime", valorDateTime);
            od.EstablecerDecimal("atributoDecimal", valorDecimal);
            od.EstablecerDouble("atributoDouble", valorDouble);
            od.EstablecerFloat("atributoFloat", valorFloat);
            od.EstablecerInteger("atributoInteger", valorInteger);
            od.EstablecerLong("atributoLong", valorLong);
            od.EstablecerSByte("atributoSByte", valorSByte);
            od.EstablecerShort("atributoShort", valorShort);
            od.EstablecerString("atributoString", valorString);
            od.EstablecerUInteger("atributoUInteger", valorUInteger);
            od.EstablecerULong("atributoULong", valorULong);
            od.EstablecerUShort("atributoUShort", valorUShort);

            Assert.AreEqual(od.ObtenerBoolean("atributoBoolean"), valorBoolean);
            Assert.AreEqual(od.ObtenerByte("atributoByte"), valorByte);
            Assert.AreEqual(od.ObtenerChar("atributoChar"), valorChar);
            Assert.AreEqual(od.ObtenerDateTime("atributoDateTime"), valorDateTime);
            Assert.AreEqual(od.ObtenerDecimal("atributoDecimal"), valorDecimal);
            Assert.AreEqual(od.ObtenerDouble("atributoDouble"), valorDouble);
            Assert.AreEqual(od.ObtenerFloat("atributoFloat"), valorFloat);
            Assert.AreEqual(od.ObtenerInteger("atributoInteger"), valorInteger);
            Assert.AreEqual(od.ObtenerLong("atributoLong"), valorLong);
            Assert.AreEqual(od.ObtenerSByte("atributoSByte"), valorSByte);
            Assert.AreEqual(od.ObtenerShort("atributoShort"), valorShort);
            Assert.AreEqual(od.ObtenerString("atributoString"), valorString);
            Assert.AreEqual(od.ObtenerUInteger("atributoUInteger"), valorUInteger);
            Assert.AreEqual(od.ObtenerULong("atributoULong"), valorULong);
            Assert.AreEqual(od.ObtenerUShort("atributoUShort"), valorUShort);
        }
Example #4
0
        public void EvaluarEstablecerPorTipoPorIndice()
        {
            IObjetoDatos od  = Fabrica.Instancia.Crear(_tipo);
            Random       rnd = new Random();

            bool     valorBoolean  = true;
            byte     valorByte     = byte.MaxValue;
            char     valorChar     = char.MaxValue;
            DateTime valorDateTime = DateTime.MaxValue;
            decimal  valorDecimal  = decimal.MaxValue;
            double   valorDouble   = double.MaxValue;
            float    valorFloat    = float.MaxValue;
            int      valorInteger  = int.MaxValue;
            long     valorLong     = long.MaxValue;
            sbyte    valorSByte    = sbyte.MaxValue;
            short    valorShort    = short.MaxValue;
            string   valorString   = "abcdefghijklmnoprstuvwxyz";
            uint     valorUInteger = uint.MaxValue;
            ulong    valorULong    = ulong.MaxValue;
            ushort   valorUShort   = ushort.MaxValue;

            od.EstablecerBoolean(0, valorBoolean);
            od.EstablecerByte(1, valorByte);
            od.EstablecerChar(2, valorChar);
            od.EstablecerDateTime(3, valorDateTime);
            od.EstablecerDecimal(4, valorDecimal);
            od.EstablecerDouble(5, valorDouble);
            od.EstablecerFloat(6, valorFloat);
            od.EstablecerInteger(7, valorInteger);
            od.EstablecerLong(8, valorLong);
            od.EstablecerSByte(9, valorSByte);
            od.EstablecerShort(10, valorShort);
            od.EstablecerString(11, valorString);
            od.EstablecerUInteger(12, valorUInteger);
            od.EstablecerULong(13, valorULong);
            od.EstablecerUShort(14, valorUShort);

            Assert.AreEqual(od.ObtenerBoolean(0), valorBoolean);
            Assert.AreEqual(od.ObtenerByte(1), valorByte);
            Assert.AreEqual(od.ObtenerChar(2), valorChar);
            Assert.AreEqual(od.ObtenerDateTime(3), valorDateTime);
            Assert.AreEqual(od.ObtenerDecimal(4), valorDecimal);
            Assert.AreEqual(od.ObtenerDouble(5), valorDouble);
            Assert.AreEqual(od.ObtenerFloat(6), valorFloat);
            Assert.AreEqual(od.ObtenerInteger(7), valorInteger);
            Assert.AreEqual(od.ObtenerLong(8), valorLong);
            Assert.AreEqual(od.ObtenerSByte(9), valorSByte);
            Assert.AreEqual(od.ObtenerShort(10), valorShort);
            Assert.AreEqual(od.ObtenerString(11), valorString);
            Assert.AreEqual(od.ObtenerUInteger(12), valorUInteger);
            Assert.AreEqual(od.ObtenerULong(13), valorULong);
            Assert.AreEqual(od.ObtenerUShort(14), valorUShort);
        }
Example #5
0
        public static void Construir(IObjetoDatos od, int niveles, int items)
        {
            if (od.Tipo.ContienePropiedad("atributoId"))
            {
                od.EstablecerInteger("atributoId", ++_id);
            }

            Construir(od, od.Tipo.Propiedades, niveles, items);

            if (od.Tipo["ReferenciaObjetoDatos2"] != null)
            {
                od.EstablecerObjetoDatos("ReferenciaObjetoDatos2", _od);
            }

            if (od.Tipo["ReferenciaObjetoDatosItem2"] != null && od.ObtenerColeccion("ReferenciaObjetoDatosItem").Longitud > 0)
            {
                od.EstablecerObjetoDatos("ReferenciaObjetoDatosItem2", od.ObtenerColeccion("ReferenciaObjetoDatosItem")[0]);
            }
        }
        void LeerAtributo(IObjetoDatos od, IPropiedad atributo)
        {
            switch (atributo.Tipo.Nombre)
            {
            case "Boolean":
                od.EstablecerBoolean(atributo, LeerBoolean());
                break;

            case "Byte":
                od.EstablecerByte(atributo, LeerByte());
                break;

            case "Char":
                od.EstablecerChar(atributo, LeerChar());
                break;

            case "DateTime":
                od.EstablecerDateTime(atributo, LeerDateTime());
                break;

            case "Decimal":
                od.EstablecerDecimal(atributo, LeerDecimal());
                break;

            case "Double":
                od.EstablecerDouble(atributo, LeerDouble());
                break;

            case "Single":
                od.EstablecerFloat(atributo, LeerFloat());
                break;

            case "Int32":
                od.EstablecerInteger(atributo, LeerInteger());
                break;

            case "Int64":
                od.EstablecerLong(atributo, LeerLong());
                break;

            case "SByte":
                od.EstablecerSByte(atributo, LeerSByte());
                break;

            case "Int16":
                od.EstablecerShort(atributo, LeerShort());
                break;

            case "String":
                od.EstablecerString(atributo, LeerString());
                break;

            case "UInt32":
                od.EstablecerUInteger(atributo, LeerUInteger());
                break;

            case "UInt64":
                od.EstablecerULong(atributo, LeerULong());
                break;

            case "UInt16":
                od.EstablecerUShort(atributo, LeerUShort());
                break;
            }
        }