Пример #1
0
        public void TestSaveNewPartnerWithExistingLocation()
        {
            TDataBase               db          = DBAccess.Connect("TestSaveNewPartnerWithExistingLocation");
            TDBTransaction          Transaction = db.BeginTransaction(IsolationLevel.Serializable);
            TPartnerEditUIConnector connector   = new TPartnerEditUIConnector(db);

            PartnerEditTDS MainDS = new PartnerEditTDS();

            PPartnerRow PartnerRow = TCreateTestPartnerData.CreateNewFamilyPartner(MainDS, db);

            TCreateTestPartnerData.CreateNewLocation(PartnerRow.PartnerKey, MainDS);

            DataSet ResponseDS = new PartnerEditTDS();
            TVerificationResultCollection VerificationResult;

            TSubmitChangesResult result = connector.SubmitChanges(ref MainDS, ref ResponseDS, out VerificationResult);

            Transaction.Commit();

            CommonNUnitFunctions.EnsureNullOrOnlyNonCriticalVerificationResults(VerificationResult,
                                                                                "There was a critical error when saving:");

            Assert.AreEqual(TSubmitChangesResult.scrOK, result, "saving the first partner with a location");

            Int32 LocationKey = MainDS.PLocation[0].LocationKey;

            MainDS = new PartnerEditTDS();

            Transaction = db.BeginTransaction(IsolationLevel.Serializable);

            PartnerRow = TCreateTestPartnerData.CreateNewFamilyPartner(MainDS, db);

            PPartnerLocationRow PartnerLocationRow = MainDS.PPartnerLocation.NewRowTyped();

            PartnerLocationRow.SiteKey     = DomainManager.GSiteKey;
            PartnerLocationRow.PartnerKey  = PartnerRow.PartnerKey;
            PartnerLocationRow.LocationKey = LocationKey;
            MainDS.PPartnerLocation.Rows.Add(PartnerLocationRow);

            ResponseDS = new PartnerEditTDS();

            result = connector.SubmitChanges(ref MainDS, ref ResponseDS, out VerificationResult);
            Transaction.Commit();

            CommonNUnitFunctions.EnsureNullOrOnlyNonCriticalVerificationResults(VerificationResult,
                                                                                "There was a critical error when saving:");

            TDBTransaction ReadTransaction = new TDBTransaction();

            db.ReadTransaction(
                ref ReadTransaction,
                delegate
            {
                PPartnerTable PartnerAtAddress = PPartnerAccess.LoadViaPLocation(
                    DomainManager.GSiteKey, LocationKey, ReadTransaction);
                Assert.AreEqual(2, PartnerAtAddress.Rows.Count, "there should be two partners at this location");
            });
        }