コード例 #1
0
        private static void ConstruirColeccion(IObjetoDatos od, IPropiedad propiedad, int niveles, int items)
        {
            if (niveles == 0)
            {
                return;
            }

            for (int i = 1; i <= items; i++)
            {
                Construir(od.CrearObjetoDatos(propiedad), (niveles - 1), items);
            }
        }
コード例 #2
0
        private static void ConstruirReferencia(IObjetoDatos od, IPropiedad propiedad, int niveles, int items)
        {
            if (niveles == 0)
            {
                return;
            }

            if (propiedad.Asociacion == Asociacion.Composicion)
            {
                IObjetoDatos referencia = od.CrearObjetoDatos(propiedad);
                Construir(referencia, (niveles - 1), items);
            }
        }
コード例 #3
0
        private IObjetoDatos CrearObjetoDatos(IObjetoDatos od, IPropiedad propiedad, int id)
        {
            IObjetoDatos valor = null;

            if (propiedad.Asociacion == Asociacion.Composicion)
            {
                valor = od.CrearObjetoDatos(propiedad);
            }
            else if (_oid.Existe(id))
            {
                valor = _oid.Obtener(id);
            }
            else
            {
                valor = CrearObjetoDatos(propiedad.Tipo);
            }

            return(valor);
        }
コード例 #4
0
        public void CrearDiagramaAgregacion()
        {
            IObjetoDatos od = HelperDiagrama.CrearObjetoDatosX();

            Helper.Construir(od, 2, 5);
            HelperDiagrama.EstablecerAtributoRuta(od);

            ITipo tipoagr = od.Tipo.ObtenerPropiedad("ReferenciaObjetoDatos2").Tipo;

            IObjetoDatos odagr  = Helper.Crear(tipoagr);
            IObjetoDatos odagr2 = Helper.Crear(tipoagr);

            odagr.CrearObjetoDatos("ReferenciaObjetoDatos");
            odagr.EstablecerObjetoDatos("ReferenciaObjetoDatos2", odagr2);
            odagr2.EstablecerObjetoDatos("ReferenciaObjetoDatos2", odagr); // establecer referencia agregacion apuntando al contenedor (odgr)

            od.EstablecerObjetoDatos("ReferenciaObjetoDatos2", odagr);

            BuilderDiagrama helper = new BuilderDiagrama();
            Diagrama        diag   = helper.Crear(od);

            NodoReferencia nodoprop1 = (NodoReferencia)diag.Root.Nodos[0];
            NodoReferencia nodoprop3 = (NodoReferencia)diag.Root.Nodos[2];
            NodoObjeto     nodoobj1  = (NodoObjeto)nodoprop1.Nodos[0];
            NodoObjeto     nodoobj3  = (NodoObjeto)nodoprop3.Nodos[0];

            IPropiedad   prop1 = od.Tipo.ObtenerPropiedad("ReferenciaObjetoDatos");
            IPropiedad   prop3 = od.Tipo.ObtenerPropiedad("ReferenciaObjetoDatos2");
            IObjetoDatos obj1  = od.ObtenerObjetoDatos(prop1);
            IObjetoDatos obj3  = od.ObtenerObjetoDatos(prop3);

            Assert.IsNotNull(nodoprop1);
            Assert.IsNotNull(nodoprop3);
            Assert.IsNotNull(prop1);
            Assert.IsNotNull(prop3);
            Assert.IsNotNull(obj1);
            Assert.IsNotNull(obj3);

            Assert.AreEqual(prop1, nodoprop1.Propiedad);
            Assert.AreEqual(prop3, nodoprop3.Propiedad);
            Assert.AreEqual(obj1, nodoobj1.Objeto.ObjetoDatos);
            Assert.AreEqual(obj3, nodoobj3.Objeto.ObjetoDatos);

            Assert.AreEqual("/ReferenciaObjetoDatos", nodoobj1.Objeto.Propietario);
            Assert.AreEqual("/ReferenciaObjetoDatos2", nodoobj3.Objeto.Propietario);


            nodoprop1 = (NodoReferencia)nodoobj3.Nodos[0];
            nodoprop3 = (NodoReferencia)nodoobj3.Nodos[1];
            nodoobj1  = (NodoObjeto)nodoprop1.Nodos[0];
            nodoobj3  = (NodoObjeto)nodoprop3.Nodos[0];

            prop1 = odagr.Tipo.ObtenerPropiedad("ReferenciaObjetoDatos");
            prop3 = odagr.Tipo.ObtenerPropiedad("ReferenciaObjetoDatos2");
            obj1  = odagr.ObtenerObjetoDatos(prop1);
            obj3  = odagr.ObtenerObjetoDatos(prop3);

            Assert.IsNotNull(nodoprop1);
            Assert.IsNotNull(nodoprop3);
            Assert.IsNotNull(prop1);
            Assert.IsNotNull(prop3);
            Assert.IsNotNull(obj1);
            Assert.IsNotNull(obj3);

            Assert.AreEqual(prop1, nodoprop1.Propiedad);
            Assert.AreEqual(prop3, nodoprop3.Propiedad);
            Assert.AreEqual(obj1, nodoobj1.Objeto.ObjetoDatos);
            Assert.AreEqual(odagr2, nodoobj3.Objeto.ObjetoDatos);

            Assert.AreEqual("/ReferenciaObjetoDatos2/ReferenciaObjetoDatos", nodoobj1.Objeto.Propietario);
            Assert.AreEqual("/ReferenciaObjetoDatos2/ReferenciaObjetoDatos2", nodoobj3.Objeto.Propietario);

            // verificar la referencia odgr2.ReferenciaObjetoDatos2 => odagr
            nodoprop1 = (NodoReferencia)nodoobj3.Nodos[0];
            nodoobj1  = (NodoObjeto)nodoprop1.Nodos[0];
            obj1      = odagr2.ObtenerObjetoDatos("ReferenciaObjetoDatos2");

            Assert.AreEqual(odagr, obj1);

            Assert.AreEqual("/ReferenciaObjetoDatos2", nodoobj1.Objeto.Propietario);
        }
        public void RecuperarInstantaneaEnObjetoDatosX()
        {
            // arrange
            Log          log     = new Log();
            IFabrica     fabrica = new FabricaHistorial(log);
            IObjetoDatos od      = fabrica.Crear(HelperTipo.ObtenerTipo2());

            // act
            var instantanea1 = log.CrearInstantanea();

            od.CrearObjetoDatos("ReferenciaObjetoDatos");

            var instantanea2 = log.CrearInstantanea();

            od.CrearObjetoDatos("ReferenciaObjetoDatosItem");

            var instantanea3 = log.CrearInstantanea();

            od.CrearObjetoDatos("ReferenciaObjetoDatosItem");

            var instantanea4 = log.CrearInstantanea();

            od.CrearObjetoDatos("ReferenciaObjetoDatosItem[0]/ReferenciaObjetoDatos");

            var instantanea5 = log.CrearInstantanea();

            od.CrearObjetoDatos("ReferenciaObjetoDatosItem[1]/ReferenciaObjetoDatos");

            var valorBoolean = od.Obtener("atributoBoolean");
            var valorByte    = od.Obtener("atributoByte");

            var instantanea6 = log.CrearInstantanea();

            od.EstablecerBoolean("ReferenciaObjetoDatosItem[1]/ReferenciaObjetoDatos/atributoBoolean", true);
            od.EstablecerByte("ReferenciaObjetoDatosItem[1]/ReferenciaObjetoDatos/atributoByte", byte.MaxValue);

            Assert.AreEqual(od.ObtenerBoolean("ReferenciaObjetoDatosItem[1]/ReferenciaObjetoDatos/atributoBoolean"), true);
            Assert.AreEqual(od.ObtenerByte("ReferenciaObjetoDatosItem[1]/ReferenciaObjetoDatos/atributoByte"), byte.MaxValue);

            // recuperar
            log.Recuperar(instantanea6);

            Assert.AreEqual(od.ObtenerBoolean("ReferenciaObjetoDatosItem[1]/ReferenciaObjetoDatos/atributoBoolean"), valorBoolean);
            Assert.AreEqual(od.ObtenerByte("ReferenciaObjetoDatosItem[1]/ReferenciaObjetoDatos/atributoByte"), valorByte);


            // recuperar
            log.Recuperar(instantanea5);

            Assert.IsNull(od.Obtener("ReferenciaObjetoDatosItem[1]/ReferenciaObjetoDatos"));

            // recuperar
            log.Recuperar(instantanea4);

            Assert.IsNull(od.Obtener("ReferenciaObjetoDatosItem[0]/ReferenciaObjetoDatos"));

            // recuperar
            log.Recuperar(instantanea3);

            Assert.AreEqual(od.ObtenerColeccion("ReferenciaObjetoDatosItem").Longitud, 1);

            // recuperar
            log.Recuperar(instantanea2);

            Assert.AreEqual(od.ObtenerColeccion("ReferenciaObjetoDatosItem").Longitud, 0);

            // recuperar
            log.Recuperar(instantanea1);

            Assert.IsNull(od.Obtener("ReferenciaObjetoDatos"));
        }