protected virtual void FillDatabase(Session ssn) { department1 = Prepare_hrmDepartment(ssn, "1"); department2 = Prepare_hrmDepartment(ssn, "2"); country1 = Prepare_csCountry(ssn, "1"); address1 = Prepare_csAddress(ssn, "1", country1); address2 = Prepare_csAddress(ssn, "1", country1); contractCategory1 = Prepare_crmContractCategory(ssn, "1"); documentCategory1 = Prepare_crmDocumentCategory(ssn, "1"); legalPersonRussianRu1 = Prepare_crmCLegalPerson(ssn, "1", address1); legalPersonRussianRu2 = Prepare_crmCLegalPerson(ssn, "2", address2); partyRu1 = legalPersonRussianRu1.Party; // Prepare_crmPartyRu(ssn, "1", address1, legalPersonRussianRu1); partyRu2 = legalPersonRussianRu2.Party; // Prepare_crmPartyRu(ssn, "2", address2, legalPersonRussianRu2); unit1 = Prepare_csUnit(ssn, "1"); nomenclatureType1 = Prepare_csNomenclatureType(ssn, "1"); costItem1 = Prepare_fmCostItem(ssn, "1"); valuta1 = Prepare_csValuta(ssn, "1", nomenclatureType1, unit1, costItem1); physicalPersonRu1 = Prepare_crmPhysicalPerson(ssn, "1", address1); physicalPersonRu2 = Prepare_crmPhysicalPerson(ssn, "1", address2); staff1 = Prepare_hrmStaff(ssn, "1", physicalPersonRu1, department1); staff2 = Prepare_hrmStaff(ssn, "2", physicalPersonRu2, department2); }
protected virtual csAddress Prepare_csAddress(Session ssn, string modificator, csCountry country) { csAddress address1 = new csAddress(ssn); address1.Country = country; address1.ZipPostal = "100000"; address1.Region = "Московский"; address1.StateProvince = "Московская провинция"; address1.City = "Москва"; address1.Street = "Профсоюзная, " + modificator; address1.AddressHandmake = "стр. " + modificator; return(address1); }
public void CreateAllReferencesOnlyTest() { UnitOfWork uow = new UnitOfWork(Common.dataLayer); csCountry country = Prepare_csCountry(uow, ""); csAddress address = Prepare_csAddress(uow, "", country); csCountry country1 = Prepare_csCountry(uow, "1"); csAddress address1 = Prepare_csAddress(uow, "1", country1); csCountry country2 = Prepare_csCountry(uow, "2"); csAddress address2 = Prepare_csAddress(uow, "2", country2); csCountry country3 = Prepare_csCountry(uow, "3"); csAddress address3 = Prepare_csAddress(uow, "3", country3); csCountry country4 = Prepare_csCountry(uow, "4"); csAddress address4 = Prepare_csAddress(uow, "4", country4); uow.CommitChanges(); // Изменение какого-либо поля. Если вложенный uow читал бы снова из БД, то это изменение было бы проигнорировано address.Region = "ХРЕНОВЫЙ РЕГИОН"; // Организуем коллецию XPCollection <csAddress> addressCoollection = new XPCollection <csAddress>(uow); NestedUnitOfWork nuow = uow.BeginNestedUnitOfWork(); XPCollection <csAddress> nestedAddressCoollectionBEFORECHANGE = new XPCollection <csAddress>(nuow); csAddress nestedAddress = nuow.GetObjectByKey <csAddress>(address.Oid); nestedAddress.City = "Абракадабра"; XPCollection <csAddress> nestedAddressCoollectionAFTERCHANGE = new XPCollection <csAddress>(nuow); XPClassInfo addressClassInfo = uow.GetClassInfo(typeof(csAddress)); //var AddrKeyCollection = from addr in addressCoollection select addr.Oid; List <System.Guid> AddrKeyCollection = new List <System.Guid>(); foreach (csAddress addr in addressCoollection) { ((IList)AddrKeyCollection).Add(addr.Oid); } //ICollection nestedAddressCoollectionFromDB = nuow.GetObjectsByKey(addressClassInfo, AddrKeyCollection as IList, true); // И/ИЛИ : ICollection nestedAddressCoollectionFromDS = nuow.GetObjectsByKey(addressClassInfo, AddrKeyCollection as IList, false); string xxx = nuow.ToString(); nuow.CommitChanges(); uow.CommitChanges(); // ********************************************************************************************************************** /* * * 1. После создания вложенного uow в нём ничего нет. Если же csAddress nestedAddress = nuow.GetObjectByKey<csAddress>(address.Oid); * то во вложенном uow окажется не только объект адрес, но и объект страна, которая является свойством объекта адреса * * 2. При измеениее объекта во вложенном uow он в родительском не меняется, пока изменения не утверждены. * * 3. При получении объекта, находящегося в корневм uow, во вложенном, объект оказывается во вложенном uow со всеми своими изменениями, * сделанными в корневом uow, даже если они не утверждены. * * Чтение и передача коллекций. * * 4. Коллекция во вложенном uow может быть прочитана в двух режимах: из БД и из datastore. В любом случае изменение сделанное * с объектом в корневом uow будет присутствовать в объекте из коллекции во вложенном uow (из-за кэширования, т.е. реальное чтение * БД не происходит в данном контрольном примере). Изменениеже сделанное в объекте в рамках вложенного uow будет учтено только в * режиме чтения datastore (т.е. опять же чтение будет прроисходить из кэша, где уже произведено изменение данных). * * 5. Вложенный uow после создания не содержит объектов. Объекты могут попасть во вложенный uow путём передачи из корневого со всеми * изменениями, сделанными в корневом uow. */ // ********************************************************************************************************************** }
protected virtual crmCLegalPerson Prepare_crmCLegalPerson(Session ssn, string modificator, csAddress address) { crmCLegalPerson legalPersonRussianRu1 = new crmCLegalPerson(ssn); legalPersonRussianRu1.Name = "ИнтекоАГ" + modificator; legalPersonRussianRu1.NameFull = "ИнтекоАГ" + modificator; // legalPersonRussianRu1.RegNumber = "Рег Ном " + modificator; legalPersonRussianRu1.INN = "ИНН 1111111111"; legalPersonRussianRu1.Code = "LP" + modificator; legalPersonRussianRu1.Description = "LegalPerson Description" + modificator; legalPersonRussianRu1.KPP = "КПП 222222222"; legalPersonRussianRu1.RegCode = "RC"; legalPersonRussianRu1.Person.Address = address; legalPersonRussianRu1.Party.AddressFact = address; legalPersonRussianRu1.Party.AddressPost = address; // legalPersonRussianRu1.Address = address; return(legalPersonRussianRu1); }
protected virtual crmCBusinessman Prepare_crmBusinessmanRu(Session ssn, string modificator, crmPhysicalPerson physicalPersonRu, csAddress address) { crmCBusinessman businessman1 = new crmCBusinessman(ssn); businessman1.Person = physicalPersonRu; businessman1.Name = "Иван" + modificator; // businessman1.NameFull = "Иванов & Ко" + modificator; businessman1.RegCode = "Рег Код " + modificator; businessman1.INN = "123456789"; //businessman1.Address = address; return(businessman1); }
protected virtual crmPhysicalPerson Prepare_crmPhysicalPerson(Session ssn, string modificator, csAddress address) { crmPhysicalPerson physicalPerson1 = new crmPhysicalPerson(ssn); physicalPerson1.LastName = "Иванов" + modificator; physicalPerson1.FirstName = "Иван" + modificator; physicalPerson1.MiddleName = "Иванович" + modificator; physicalPerson1.INN = "123456789"; //physicalPerson1.Address = address; return(physicalPerson1); }
public void CreateAllReferencesOnlyTest([Values("", "0", "1", "2", "3", "4")] string modificator) { //Session ssn = session1; UnitOfWork ssn = new UnitOfWork(Common.dataLayer); crmContractCategory contractCategory = Prepare_crmContractCategory(ssn, modificator); if (Common.CheckValidationRule) { ruleResult = ruleSet.ValidateTarget(contractCategory, DefaultContexts.Save); Assert.AreEqual(ValidationState.Valid, ruleResult.State); } crmCostModel costModel = Prepare_crmCostModel(ssn, modificator); if (Common.CheckValidationRule) { ruleResult = ruleSet.ValidateTarget(costModel, DefaultContexts.Save); Assert.AreEqual(ValidationState.Valid, ruleResult.State); } csCountry country = Prepare_csCountry(ssn, modificator); if (Common.CheckValidationRule) { ruleResult = ruleSet.ValidateTarget(country, DefaultContexts.Save); Assert.AreEqual(ValidationState.Valid, ruleResult.State); } csUnit unit = Prepare_csUnit(ssn, modificator); if (Common.CheckValidationRule) { ruleResult = ruleSet.ValidateTarget(unit, DefaultContexts.Save); Assert.AreEqual(ValidationState.Valid, ruleResult.State); } csNomenclatureType nomenclatureType = Prepare_csNomenclatureType(ssn, modificator); if (Common.CheckValidationRule) { ruleResult = ruleSet.ValidateTarget(nomenclatureType, DefaultContexts.Save); Assert.AreEqual(ValidationState.Valid, ruleResult.State); } fmCostItem costItem = Prepare_fmCostItem(ssn, modificator); if (Common.CheckValidationRule) { ruleResult = ruleSet.ValidateTarget(costItem, DefaultContexts.Save); Assert.AreEqual(ValidationState.Valid, ruleResult.State); } csMaterial material = Prepare_csMaterial(ssn, modificator, nomenclatureType, unit, costItem); if (Common.CheckValidationRule) { ruleResult = ruleSet.ValidateTarget(material, DefaultContexts.Save); Assert.AreEqual(ValidationState.Valid, ruleResult.State); } csService service = Prepare_csService(ssn, modificator, nomenclatureType, unit, costItem); if (Common.CheckValidationRule) { ruleResult = ruleSet.ValidateTarget(service, DefaultContexts.Save); Assert.AreEqual(ValidationState.Valid, ruleResult.State); } csValuta valuta = Prepare_csValuta(ssn, modificator, nomenclatureType, unit, costItem); if (Common.CheckValidationRule) { ruleResult = ruleSet.ValidateTarget(valuta, DefaultContexts.Save); Assert.AreEqual(ValidationState.Valid, ruleResult.State); } csAddress address = Prepare_csAddress(ssn, modificator, country); if (Common.CheckValidationRule) { ruleResult = ruleSet.ValidateTarget(address, DefaultContexts.Save); Assert.AreEqual(ValidationState.Valid, ruleResult.State); } crmPhysicalPerson physicalPersonRu = Prepare_crmPhysicalPerson(ssn, modificator, address); if (Common.CheckValidationRule) { ruleResult = ruleSet.ValidateTarget(physicalPersonRu, DefaultContexts.Save); Assert.AreEqual(ValidationState.Valid, ruleResult.State); } crmCBusinessman businessmanRu = Prepare_crmBusinessmanRu(ssn, modificator, physicalPersonRu, address); if (Common.CheckValidationRule) { ruleResult = ruleSet.ValidateTarget(businessmanRu, DefaultContexts.Save); Assert.AreEqual(ValidationState.Valid, ruleResult.State); } crmCLegalPerson legalPersonRussianRu = Prepare_crmCLegalPerson(ssn, modificator, address); if (Common.CheckValidationRule) { ruleResult = ruleSet.ValidateTarget(legalPersonRussianRu, DefaultContexts.Save); Assert.AreEqual(ValidationState.Valid, ruleResult.State); } //crmPartyRu partyRu = Prepare_crmPartyRu(ssn, modificator, address, legalPersonRussianRu); //if (Common.CheckValidationRule) { // ruleResult = ruleSet.ValidateTarget(partyRu, DefaultContexts.Save); // Assert.AreEqual(ValidationState.Valid, ruleResult.State); //} fmCSubject subject = Prepare_fmSubject(ssn, modificator); if (Common.CheckValidationRule) { ruleResult = ruleSet.ValidateTarget(subject, DefaultContexts.Save); Assert.AreEqual(ValidationState.Valid, ruleResult.State); } hrmDepartment department = Prepare_hrmDepartment(ssn, modificator); if (Common.CheckValidationRule) { ruleResult = ruleSet.ValidateTarget(department, DefaultContexts.Save); Assert.AreEqual(ValidationState.Valid, ruleResult.State); } hrmStaff staff = Prepare_hrmStaff(ssn, modificator, physicalPersonRu, department); if (Common.CheckValidationRule) { ruleResult = ruleSet.ValidateTarget(staff, DefaultContexts.Save); Assert.AreEqual(ValidationState.Valid, ruleResult.State); } crmUserParty userParty = Prepare_crmUserParty(ssn, modificator, legalPersonRussianRu.Party); if (Common.CheckValidationRule) { ruleResult = ruleSet.ValidateTarget(userParty, DefaultContexts.Save); Assert.AreEqual(ValidationState.Valid, ruleResult.State); } ssn.CommitChanges(); }