public void ConvertObjectoToEntity() { //new specie var objsSpecie = new SpecieTest() { Id = Guid.NewGuid().ToString("N"), ClientId = "2", Name = "Specie", Abbreviation = "SPC" }; // generación de hash var hashSpecie = new HashEntityMockSearch(); // action // obtiene el entitySearch var entityspecie = Mdm.Reflection.Entities.GetEntitySearch(new ImplementMock(), objsSpecie, hashSpecie); // genera el hash de las cabeceras de entitySearch // esto es un diccionario var hhSpecie = hashSpecie.HashHeader(typeof(SpecieTest)); // genera un hash del objeto de base de datos. var hmSpecie = hashSpecie.HashModel(objsSpecie); // obtiene el primer elemento de tipo barracks var specieEntityFather = entityspecie.First(s => s.index == (int)EntityRelated.SPECIE); // assert // verifica que el hash sea correcto Assert.True(specieEntityFather.hh.Equals(hhSpecie) && specieEntityFather.hm.Equals(hmSpecie)); //new variety var objsVariety = new VarietyTest() { Id = Guid.NewGuid().ToString("N"), ClientId = "3", Name = "Variety", Abbreviation = "VRTY", IdSpecie = objsSpecie.Id }; // generación de hash var hashVariety = new HashEntityMockSearch(); // action // obtiene el entitySearch var entityVariety = Mdm.Reflection.Entities.GetEntitySearch(new ImplementMock(), objsVariety, hashVariety); // genera el hash de las cabeceras de entitySearch // esto es un diccionario var hhVariety = hashVariety.HashHeader(typeof(VarietyTest)); // genera un hash del objeto de base de datos. var hmVariety = hashVariety.HashModel(objsVariety); // obtiene el primer elemento de tipo barracks var VarietyEntityFather = entityVariety.First(s => s.index == (int)EntityRelated.VARIETY); // assert // verifica que el hash sea correcto Assert.True(VarietyEntityFather.hh.Equals(hhVariety) && VarietyEntityFather.hm.Equals(hmVariety)); // new BarrackTest var objs = new BarrackTest() { ClientId = "1", GeographicalPoints = new GeoPointTs[] { new GeoPointTs { latitude = 1.3, longitude = 1.45 } }, Hectares = 3.4, Id = Guid.NewGuid().ToString("N"), IdPlotLand = Guid.NewGuid().ToString("N"), IdPollinator = Guid.NewGuid().ToString("N"), IdRootstock = Guid.NewGuid().ToString("N"), IdVariety = objsVariety.Id, Name = "Barrack1", NumberOfPlants = 1221, PlantingYear = 1982, SeasonId = Guid.NewGuid().ToString("N") }; // generación de hash var hash = new HashEntityMockSearch(); // action // obtiene el entitySearch var entities = Mdm.Reflection.Entities.GetEntitySearch(new ImplementMock(), objs, hash); // genera el hash de las cabeceras de entitySearch // esto es un diccionario var hh = hash.HashHeader(typeof(BarrackTest)); // genera un hash del objeto de base de datos. var hm = hash.HashModel(objs); // obtiene el primer elemento de tipo barracks var barrackEntityFather = entities.First(s => s.index == (int)EntityRelated.BARRACK); // assert // verifica que el hash sea correcto Assert.True(barrackEntityFather.hh.Equals(hh) && barrackEntityFather.hm.Equals(hm)); }
public void ConvertEntityToObject() { // operaciones de hash para crear las identidades. var hash = new HashEntityMockSearch(); // un id genérico. var genericId = Guid.NewGuid().ToString("N"); // objeto del modelo de base de datos. var objs = new BarrackTest() { ClientId = "1", GeographicalPoints = new GeoPointTs[] { new GeoPointTs { latitude = 1.3, longitude = 1.45 } }, Hectares = 3.4, Id = genericId, IdPlotLand = genericId, IdPollinator = genericId, IdRootstock = genericId, IdVariety = genericId, Name = "Barrack1", NumberOfPlants = 1221, PlantingYear = 1982, SeasonId = genericId }; // Creamos una entidad que coincide con el objeto de modelo de base de datos. var entity = new EntityBaseSearch <GeoPointTs> { bl = Array.Empty <BoolBaseProperty>(), created = DateTime.Now, index = (int)EntityRelated.BARRACK, dbl = new DblBaseProperty[] { new DblBaseProperty { index = (int)DoubleRelated.HECTARES, value = 3.4 } }, dt = Array.Empty <DtBaseProperty>(), enm = Array.Empty <EnumBaseProperty>(), geo = new GeographyProperty[] { new GeographyProperty { index = (int)GeoRelated.LOCATION_BARRACK, value = new GeoPointTs { latitude = 1.3, longitude = 1.45 } } }, id = genericId, num32 = new Num32BaseProperty[] { new Num32BaseProperty { index = (int)NumRelated.NUMBER_OF_PLANTS, value = 1221 }, new Num32BaseProperty { index = (int)NumRelated.PLANTING_YEAR, value = 1982 } }, num64 = Array.Empty <Num64BaseProperty>(), rel = new IRelatedId[] { new RelatedBaseId { id = genericId, index = (int)EntityRelated.PLOTLAND }, new RelatedBaseId { id = genericId, index = (int)EntityRelated.POLLINATOR }, new RelatedBaseId { id = genericId, index = (int)EntityRelated.ROOTSTOCK }, new RelatedBaseId { id = genericId, index = (int)EntityRelated.VARIETY }, new RelatedBaseId { id = genericId, index = (int)EntityRelated.SEASON }, }, str = new StrBaseProperty[] { new StrBaseProperty { index = (int)StringRelated.GENERIC_NAME, value = "Barrack1", }, new StrBaseProperty { index = (int)StringRelated.GENERIC_CORRELATIVE, value = "1" } }, sug = Array.Empty <StrBaseProperty>(), hh = hash.HashHeader(typeof(BarrackTest)), hm = hash.HashModel(objs) }; // obtenemos el entitySearch del barrack, internamente valida el hash. var barrack = (BarrackTest)Mdm.Reflection.Entities.GetEntityFromSearch(entity, typeof(BarrackTest), "trifenix.connect.test.model", s => s, new SearchElement(), hash); //assert Assert.Equal(entity.str.First().value, barrack.Name); }