public void Create() { try { rt.srz.model.srz.AutoComplete entity = CreateNew(); object result = manager.Save(entity); Assert.IsNotNull(result); } catch (Exception ex) { Assert.Fail(ex.ToString()); } }
public void Read() { try { rt.srz.model.srz.AutoComplete entityA = CreateNew(); manager.Save(entityA); rt.srz.model.srz.AutoComplete entityB = manager.GetById(entityA.Id); Assert.AreEqual(entityA, entityB); } catch (Exception ex) { Assert.Fail(ex.ToString()); } }
public void Delete() { try { rt.srz.model.srz.AutoComplete entityC = CreateNew(); manager.Save(entityC); manager.Session.GetISession().Flush(); manager.Session.GetISession().Clear(); rt.srz.model.srz.AutoComplete entity = GetFirstAutoComplete(); manager.Delete(entity); entity = manager.GetById(entity.Id); Assert.IsNull(entity); } catch (Exception ex) { Assert.Fail(ex.ToString()); } }
public static AutoComplete CreateNew(int depth = 0) { rt.srz.model.srz.AutoComplete entity = new rt.srz.model.srz.AutoComplete(); // You may need to maually enter this key if there is a constraint violation. entity.Id = System.Guid.NewGuid(); entity.Name = "Test Test "; entity.Relevance = 44; using (rt.srz.business.manager.IConceptManager concept1Manager = ObjectFactory.GetInstance <IConceptManager>()) { entity.Gender = null; } using (rt.srz.business.manager.IConceptManager concept2Manager = ObjectFactory.GetInstance <IConceptManager>()) { var all = concept2Manager.GetAll(1); Concept entityRef = null; if (all.Count > 0) { entityRef = all[0]; } if (entityRef == null && depth < 3) { depth++; entityRef = ConceptTests.CreateNew(depth); ObjectFactory.GetInstance <ISessionFactory>().GetCurrentSession().Save(entityRef); } entity.Type = entityRef; } return(entity); }
public void Update() { try { rt.srz.model.srz.AutoComplete entityC = CreateNew(); manager.Save(entityC); manager.Session.GetISession().Flush(); manager.Session.GetISession().Clear(); rt.srz.model.srz.AutoComplete entityA = GetFirstAutoComplete(); entityA.Name = "Test Test "; manager.Update(entityA); rt.srz.model.srz.AutoComplete entityB = manager.GetById(entityA.Id); Assert.AreEqual(entityA.Name, entityB.Name); } catch (Exception ex) { Assert.Fail(ex.ToString()); } }
/// <summary> /// The sinhronize names. /// </summary> private void SinhronizeNames() { using ( var sessionSrz = ObjectFactory.GetInstance <IManagerSessionFactorys>().GetFactoryByName("NHibernateCfgAtl.xml").OpenSession()) { var sessionPvp = ObjectFactory.GetInstance <ISessionFactory>().GetCurrentSession(); var conceptManager = ObjectFactory.GetInstance <IConceptCacheManager>(); var srzImList = sessionSrz.QueryOver <Im>().List(); var srzOtList = sessionSrz.QueryOver <Ot>().List(); var pvpImOtList = sessionPvp.QueryOver <AutoComplete>().List(); var pvpImList = pvpImOtList.Where(x => x.Type.Id == srz.model.srz.concepts.AutoComplete.FirstName && x.Gender != null) .ToList(); var pvpOtList = pvpImOtList.Where(x => x.Type.Id == srz.model.srz.concepts.AutoComplete.MiddleName && x.Gender != null) .ToList(); // Перенос имен из СРЗ в ПВП var srz2PvpImList = srzImList.Where( x => !pvpImList.Any( y => x.Caption.ToLower() == y.Name.ToLower() && (x.W == y.Gender.Id - Sex.Sex1 + 1))) .ToList(); foreach (var im in srz2PvpImList) { var ac = new AutoComplete(); ac.Name = im.Caption.ToUpperFirstChar(); ac.Gender = conceptManager.GetBy(x => x.Code == im.W.ToString() && x.Oid.Id == Oid.Пол).FirstOrDefault() ?? conceptManager.GetById(Sex.Sex1); ac.Type = conceptManager.GetById(srz.model.srz.concepts.AutoComplete.FirstName); pvpImList.Add(ac); sessionPvp.Save(ac); } // Перенос отчеств из СРЗ в ПВП var srz2PvpOtList = srzOtList.Where( x => !pvpOtList.Any( y => x.Caption.ToLower() == y.Name.ToLower() && (x.W == y.Gender.Id - Sex.Sex1 + 1))) .ToList(); foreach (var ot in srz2PvpOtList) { var ac = new AutoComplete(); ac.Name = ot.Caption.ToUpperFirstChar(); ac.Gender = conceptManager.GetBy(x => x.Code == ot.W.ToString() && x.Oid.Id == Oid.Пол).FirstOrDefault() ?? conceptManager.GetById(Sex.Sex1); ac.Type = conceptManager.GetById(srz.model.srz.concepts.AutoComplete.MiddleName); pvpOtList.Add(ac); sessionPvp.Save(ac); } sessionPvp.Flush(); // Перенос имен из ПВП в СРЗ var pvp2SrzImList = pvpImList.Where( y => !srzImList.Any( x => x.Caption.ToLower() == y.Name.ToLower() && (x.W == y.Gender.Id - Sex.Sex1 + 1))) .ToList(); foreach (var im in pvp2SrzImList) { var ac = new Im(); ac.Caption = im.Name.ToUpperFirstChar(); int gender; if (im.Gender != null && int.TryParse(im.Gender.Code, out gender)) { ac.W = gender; } sessionSrz.Save(ac); } // Перенос отчеств из ПВП в СРЗ var pvp2SrzOtList = pvpOtList.Where( y => !srzOtList.Any( x => x.Caption.ToLower() == y.Name.ToLower() && (x.W == y.Gender.Id - Sex.Sex1 + 1))) .ToList(); foreach (var ot in pvp2SrzOtList) { var ac = new Ot(); ac.Caption = ot.Name.ToUpperFirstChar(); int gender; if (int.TryParse(ot.Gender.Code, out gender)) { ac.W = gender; } sessionSrz.Save(ac); } sessionSrz.Flush(); // закрываем сессию СРЗ sessionSrz.Close(); } }