Exemplo n.º 1
0
        protected override void OnSetUp()
        {
            base.OnSetUp();

            using (ISession session = this.OpenSession())
            using (ITransaction tx = session.BeginTransaction())
            {
                List<Person> personList = new List<Person>();
                List<Employer> employerList = new List<Employer>();
                
                //Global id to avoid false positive assertion with positional parameter
                int gId = 1;

                //BEGIN: Person count: 3
                for (int i = 0; i < 3; i++)
                {
                    PersonCpId personCpId = new PersonCpId() { IdA = gId++, IdB = gId++ };
                    Person personObj = new Person() { CpId = personCpId, Name = "PERSON_" + personCpId.IdA + "_" + personCpId.IdB };
                    session.Save(personObj);
                    session.Flush();
                    personList.Add(personObj);
                }
                //END: Person count: 3

                //BEGIN: Employer count: 3
                for (int i = 0; i < 3; i++)
                {
                    EmployerCpId employerCpId = new EmployerCpId() { IdA = gId++, IdB = gId++ };
                    Employer employerObj = new Employer() { CpId = employerCpId, Name = "EMPLOYER_" + employerCpId.IdA + "_" + employerCpId.IdB };
                    session.Save(employerObj);
                    session.Flush();
                    employerList.Add(employerObj);
                }
                //END: Employer count: 3
                //BEGIN: employment count: 4
                int[] employmentIdAraay = new int[] { 
                    gId++,                    
                    gId++,
                    gId++,
                    gId++,
                };
                string[] employmentNameArray = new string[]
                {
                    //P1 + E1
                    "EMPLOYMENT_" + employmentIdAraay[0] + "_" + 
                        personList[0].CpId.IdA + "_" + personList[0].CpId.IdA + "_" + 
                        employerList[0].CpId.IdA + "_" + employerList[0].CpId.IdB,
                    //P1 + E2
                    "EMPLOYMENT_" + employmentIdAraay[1] + "_" + 
                        personList[0].CpId.IdA + "_" + personList[0].CpId.IdA + "_" + 
                        employerList[1].CpId.IdA + "_" + employerList[1].CpId.IdB,
                    //P2 + E2
                    "EMPLOYMENT_" + employmentIdAraay[2] + "_" + 
                        personList[1].CpId.IdA + "_" + personList[1].CpId.IdA + "_" + 
                        employerList[1].CpId.IdA + "_" + employerList[1].CpId.IdB,
                    //P2 + E3
                    "EMPLOYMENT_" + employmentIdAraay[2] + "_" + 
                        personList[1].CpId.IdA + "_" + personList[1].CpId.IdA + "_" + 
                        employerList[2].CpId.IdA + "_" + employerList[2].CpId.IdB
                };
                Person[] employemenPersonArray = new Person[] { 
                    personList[0],
                    personList[0],
                    personList[1],
                    personList[1]
                };
                Employer[] employemenEmployerArray = new Employer[] { 
                    employerList[0],
                    employerList[1],
                    employerList[1],
                    employerList[2]
                };
                //persinting Employment's
                for (int k = 0; k < employmentIdAraay.Length; k++)
                {
                    EmploymentCpId employmentCpId = new EmploymentCpId() { 
                        Id = employmentIdAraay [k],
                        PersonObj = employemenPersonArray[k],
                        EmployerObj = employemenEmployerArray[k]
                    };
                    Employment employmentObj = new Employment() { CpId = employmentCpId, Name = employmentNameArray[k] };
                    session.Save(employmentObj);
                    session.Flush();
                }
                //END: employment count: 4

                //BEGIN: PersonNoComponent count: 3
                for (int i = 0; i < 3; i++)
                {
                    PersonNoComponent personNoComponentObj = new PersonNoComponent() { IdA = gId++, IdB = gId++};
                    personNoComponentObj.Name = "PERSON_NO_COMPONENT_" + personNoComponentObj.IdA + "_" + personNoComponentObj.IdB;
                    session.Save(personNoComponentObj);
                    session.Flush();
                }
                //END: PersonNoComponent count: 3

                tx.Commit();
            }
        }
Exemplo n.º 2
0
        protected override void OnSetUp()
        {
            using (var s = OpenSession())
                using (var t = s.BeginTransaction())
                {
                    var personList   = new List <Person>();
                    var employerList = new List <Employer>();

                    // Global id to avoid false positive assertion with positional parameter
                    var gId = 1;

                    for (var i = 0; i < 3; i++)
                    {
                        var personCpId = new PersonCpId {
                            IdA = gId++, IdB = gId++
                        };
                        var personObj = new Person
                        {
                            CpId = personCpId, Name = "PERSON_" + personCpId.IdA + "_" + personCpId.IdB
                        };
                        s.Save(personObj);
                        personList.Add(personObj);
                    }

                    for (var i = 0; i < 3; i++)
                    {
                        var employerCpId = new EmployerCpId {
                            IdA = gId++, IdB = gId++
                        };
                        var employerObj = new Employer
                        {
                            CpId = employerCpId, Name = "EMPLOYER_" + employerCpId.IdA + "_" + employerCpId.IdB
                        };
                        s.Save(employerObj);
                        employerList.Add(employerObj);
                    }

                    var employmentIds = new[]
                    {
                        gId++,
                        gId++,
                        gId++,
                        gId++,
                    };
                    var employmentNames = new[]
                    {
                        //P1 + E1
                        "EMPLOYMENT_" + employmentIds[0] + "_" +
                        personList[0].CpId.IdA + "_" + personList[0].CpId.IdA + "_" +
                        employerList[0].CpId.IdA + "_" + employerList[0].CpId.IdB,
                        //P1 + E2
                        "EMPLOYMENT_" + employmentIds[1] + "_" +
                        personList[0].CpId.IdA + "_" + personList[0].CpId.IdA + "_" +
                        employerList[1].CpId.IdA + "_" + employerList[1].CpId.IdB,
                        //P2 + E2
                        "EMPLOYMENT_" + employmentIds[2] + "_" +
                        personList[1].CpId.IdA + "_" + personList[1].CpId.IdA + "_" +
                        employerList[1].CpId.IdA + "_" + employerList[1].CpId.IdB,
                        //P2 + E3
                        "EMPLOYMENT_" + employmentIds[2] + "_" +
                        personList[1].CpId.IdA + "_" + personList[1].CpId.IdA + "_" +
                        employerList[2].CpId.IdA + "_" + employerList[2].CpId.IdB
                    };
                    var employmentPersons = new[]
                    {
                        personList[0],
                        personList[0],
                        personList[1],
                        personList[1]
                    };
                    var employmentEmployers = new[]
                    {
                        employerList[0],
                        employerList[1],
                        employerList[1],
                        employerList[2]
                    };

                    for (var k = 0; k < employmentIds.Length; k++)
                    {
                        var employmentCpId = new EmploymentCpId
                        {
                            Id          = employmentIds[k],
                            PersonObj   = employmentPersons[k],
                            EmployerObj = employmentEmployers[k]
                        };
                        var employmentObj = new Employment {
                            CpId = employmentCpId, Name = employmentNames[k]
                        };
                        s.Save(employmentObj);
                    }

                    for (var i = 0; i < 3; i++)
                    {
                        var personNoComponentObj = new PersonNoComponent {
                            IdA = gId++, IdB = gId++
                        };
                        personNoComponentObj.Name = "PERSON_NO_COMPONENT_" + personNoComponentObj.IdA + "_" +
                                                    personNoComponentObj.IdB;
                        s.Save(personNoComponentObj);
                    }

                    t.Commit();
                }
        }