Exemple #1
0
        public void Create()
        {
            foreach (var init in this.Inits)
            {
                init();

                var a = (C1)this.Session.Create(MetaC1.Instance.ObjectType);
                var c = this.Session.Create(MetaC3.Instance.ObjectType);
                this.Session.Commit();

                a = (C1)this.Session.Instantiate(a);
                var b = C2.Create(this.Session);
                this.Session.Instantiate(c);

                var changes = this.Session.Checkpoint();

                Assert.Single(changes.Created);
                Assert.Contains(b.Id, changes.Created.ToArray());

                this.Session.Rollback();

                changes = this.Session.Checkpoint();

                Assert.Empty(changes.Created);

                b = C2.Create(this.Session);

                this.Session.Commit();

                changes = this.Session.Checkpoint();

                Assert.Empty(changes.Created);
            }
        }
Exemple #2
0
        public void FlushCacheOnInit()
        {
            var database = this.CreateDatabase();

            database.Init();

            using (ISession session = database.CreateSession())
            {
                var c1a = C1.Create(session);
                var c2a = C2.Create(session);
                c1a.C1C2one2one = c2a;
                session.Commit();

                // load cache
                c2a = c1a.C1C2one2one;
            }

            database.Init();

            using (ISession session = database.CreateSession())
            {
                var c1a = C1.Create(session);
                var c1b = C1.Create(session);

                session.Commit();

                c1a = C1.Instantiate(session, c1a.Id);

                Assert.IsNull(c1a.C1C2one2one);
            }
        }
        public void PrefetchCompositesRole()
        {
            var database = this.CreateDatabase();

            database.Init();

            using (var session = database.CreateSession())
            {
                var c1a = C1.Create(session);
                var c1b = C1.Create(session);
                var c2a = C2.Create(session);
                var c2b = C2.Create(session);
                var c2c = C2.Create(session);

                c1a.AddC1C2one2many(c2a);
                c1a.AddC1C2one2many(c2b);

                session.Commit();

                c1a.RemoveC1C1one2manies();
                c1a.AddC1C2one2many(c2c);

                var extent = session.Extent <C1>();
                var array  = extent.ToArray();

                var nestedPrefetchPolicyBuilder = new PrefetchPolicyBuilder();
                nestedPrefetchPolicyBuilder.WithRule(M.C2.C2C2one2manies);
                var nestedPrefetchPolicy = nestedPrefetchPolicyBuilder.Build();

                var prefetchPolicyBuilder = new PrefetchPolicyBuilder();
                prefetchPolicyBuilder.WithRule(M.C1.C1C2one2manies, nestedPrefetchPolicy);
                var prefetchPolicy = prefetchPolicyBuilder.Build();
                session.Prefetch(prefetchPolicy, new[] { c1a, c1b });

                var result = c1a.C1C2one2manies;

                session.Rollback();

                Assert.Equal(2, c1a.C1C2one2manies.Count);
                Assert.Contains(c2a, c1a.C1C2one2manies.ToArray());
                Assert.Contains(c2b, c1a.C1C2one2manies.ToArray());
            }
        }
        public void Delete()
        {
            foreach (var init in this.Inits)
            {
                init();

                var a = (C1)this.Session.Create(MetaC1.Instance.ObjectType);
                var c = this.Session.Create(MetaC3.Instance.ObjectType);
                this.Session.Commit();

                a = (C1)this.Session.Instantiate(a);
                var b = C2.Create(this.Session);
                this.Session.Instantiate(c);

                a.Strategy.Delete();
                b.Strategy.Delete();

                var changes = this.Session.Checkpoint();

                Assert.AreEqual(2, changes.Deleted.Count());
                Assert.Contains(a.Id, changes.Deleted.ToArray());
                Assert.Contains(b.Id, changes.Deleted.ToArray());

                this.Session.Rollback();

                changes = this.Session.Checkpoint();

                Assert.AreEqual(0, changes.Deleted.Count());

                a.Strategy.Delete();

                this.Session.Commit();

                changes = this.Session.Checkpoint();

                Assert.AreEqual(0, changes.Deleted.Count());
            }
        }
        public void PrefetchCompositeRole()
        {
            var database = this.CreateDatabase();

            database.Init();

            using (var session = database.CreateSession())
            {
                var c1a = C1.Create(session);
                var c1b = C1.Create(session);
                var c2a = C2.Create(session);
                var c2b = C2.Create(session);

                session.Commit();

                c1a.C1C2many2one = c2a;

                var extent = session.Extent <C1>();
                var array  = extent.ToArray();

                var nestedPrefetchPolicyBuilder = new PrefetchPolicyBuilder();
                nestedPrefetchPolicyBuilder.WithRule(M.C2.C2C2one2manies);
                var nestedPrefetchPolicy = nestedPrefetchPolicyBuilder.Build();

                var prefetchPolicyBuilder = new PrefetchPolicyBuilder();
                prefetchPolicyBuilder.WithRule(M.C1.C1C2many2one, nestedPrefetchPolicy);
                var prefetchPolicy = prefetchPolicyBuilder.Build();
                session.Prefetch(prefetchPolicy, new[] { c1a, c1b });

                var result = c1a.C1C2many2one;

                session.Rollback();

                Assert.False(c1a.ExistC1C2many2one);
            }
        }
Exemple #6
0
        public TestPopulation(ISession session)
        {
            this.C1A = C1.Create(session);
            this.C1B = C1.Create(session);
            this.C1C = C1.Create(session);
            this.C1D = C1.Create(session);
            this.C2A = C2.Create(session);
            this.C2B = C2.Create(session);
            this.C2C = C2.Create(session);
            this.C2D = C2.Create(session);
            this.C3A = C3.Create(session);
            this.C3B = C3.Create(session);
            this.C3C = C3.Create(session);
            this.C3D = C3.Create(session);
            this.C4A = C4.Create(session);
            this.C4B = C4.Create(session);
            this.C4C = C4.Create(session);
            this.C4D = C4.Create(session);

            // Names
            this.C1A.Name = "c1a";
            this.C1B.Name = "c1b";
            this.C1C.Name = "c1c";
            this.C1D.Name = "c1d";
            this.C2A.Name = "c2a";
            this.C2B.Name = "c2b";
            this.C2C.Name = "c2c";
            this.C2D.Name = "c2d";
            this.C3A.Name = "c3a";
            this.C3B.Name = "c3b";
            this.C3C.Name = "c3c";
            this.C3D.Name = "c3d";
            this.C4A.Name = "c4a";
            this.C4B.Name = "c4b";
            this.C4C.Name = "c4c";
            this.C4D.Name = "c4d";

            // String
            // class
            this.C1B.C1AllorsString = "ᴀbra";
            this.C1C.C1AllorsString = "ᴀbracadabra";
            this.C1D.C1AllorsString = "ᴀbracadabra";

            this.C1A.C1StringEquals = "ᴀbra";
            this.C1B.C1StringEquals = "ᴀbra";
            this.C1C.C1StringEquals = "ᴀbra";

            this.C2B.C2AllorsString = "ᴀbra";
            this.C2C.C2AllorsString = "ᴀbracadabra";
            this.C2D.C2AllorsString = "ᴀbracadabra";

            this.C3B.C3AllorsString = "ᴀbra";
            this.C3C.C3AllorsString = "ᴀbracadabra";
            this.C3D.C3AllorsString = "ᴀbracadabra";

            this.C3A.C3StringEquals = "ᴀbra";
            this.C3B.C3StringEquals = "ᴀbra";
            this.C3C.C3StringEquals = "ᴀbra";

            // exclusive interface
            this.C1B.I1AllorsString = "ᴀbra";
            this.C1C.I1AllorsString = "ᴀbracadabra";
            this.C1D.I1AllorsString = "ᴀbracadabra";

            this.C1A.I1StringEquals = "ᴀbra";
            this.C1B.I1StringEquals = "ᴀbra";
            this.C1C.I1StringEquals = "ᴀbra";

            this.C3B.I3AllorsString = "ᴀbra";
            this.C3C.I3AllorsString = "ᴀbracadabra";
            this.C3D.I3AllorsString = "ᴀbracadabra";

            this.C3A.I3StringEquals = "ᴀbra";
            this.C3B.I3StringEquals = "ᴀbra";
            this.C3C.I3StringEquals = "ᴀbra";

            // shared interface
            this.C1B.I12AllorsString = "ᴀbra";
            this.C1C.I12AllorsString = "ᴀbracadabra";
            this.C1D.I12AllorsString = "ᴀbracadabra";
            this.C2B.I12AllorsString = "ᴀbra";
            this.C2C.I12AllorsString = "ᴀbracadabra";
            this.C2D.I12AllorsString = "ᴀbracadabra";

            this.C2B.I23AllorsString = "ᴀbra";
            this.C2C.I23AllorsString = "ᴀbracadabra";
            this.C2D.I23AllorsString = "ᴀbracadabra";
            this.C3B.I23AllorsString = "ᴀbra";
            this.C3C.I23AllorsString = "ᴀbracadabra";
            this.C3D.I23AllorsString = "ᴀbracadabra";

            this.C3B.I34AllorsString = "ᴀbra";
            this.C3C.I34AllorsString = "ᴀbracadabra";
            this.C3D.I34AllorsString = "ᴀbracadabra";
            this.C4B.I34AllorsString = "ᴀbra";
            this.C4C.I34AllorsString = "ᴀbracadabra";
            this.C4D.I34AllorsString = "ᴀbracadabra";

            this.C1B.S1AllorsString = "ᴀbra";
            this.C1C.S1AllorsString = "ᴀbracadabra";
            this.C1D.S1AllorsString = "ᴀbracadabra";

            this.C1B.S1234AllorsString = "ᴀbra";
            this.C1C.S1234AllorsString = "ᴀbracadabra";
            this.C1D.S1234AllorsString = "ᴀbracadabra";
            this.C2B.S1234AllorsString = "ᴀbra";
            this.C2C.S1234AllorsString = "ᴀbracadabra";
            this.C2D.S1234AllorsString = "ᴀbracadabra";
            this.C3B.S1234AllorsString = "ᴀbra";
            this.C3C.S1234AllorsString = "ᴀbracadabra";
            this.C3D.S1234AllorsString = "ᴀbracadabra";
            this.C4B.S1234AllorsString = "ᴀbra";
            this.C4C.S1234AllorsString = "ᴀbracadabra";
            this.C4D.S1234AllorsString = "ᴀbracadabra";

            // Integer
            this.C1B.C1AllorsInteger = 1;
            this.C1C.C1AllorsInteger = 2;
            this.C1D.C1AllorsInteger = 2;

            this.C1B.C1IntegerLessThan = 0;
            this.C1C.C1IntegerLessThan = 2;
            this.C1D.C1IntegerLessThan = 4;

            this.C1B.C1IntegerGreaterThan = 0;
            this.C1C.C1IntegerGreaterThan = 2;
            this.C1D.C1IntegerGreaterThan = 4;

            this.C1B.C1IntegerBetweenA = -10;
            this.C1B.C1IntegerBetweenB = 0;
            this.C1C.C1IntegerBetweenA = 2;
            this.C1C.C1IntegerBetweenB = 2;
            this.C1D.C1IntegerBetweenA = 0;
            this.C1D.C1IntegerBetweenB = 10;

            this.C1B.I1AllorsInteger = 1;
            this.C1C.I1AllorsInteger = 2;
            this.C1D.I1AllorsInteger = 2;

            this.C1B.S1AllorsInteger = 1;
            this.C1C.S1AllorsInteger = 2;
            this.C1D.S1AllorsInteger = 2;

            this.C1B.I12AllorsInteger = 1;
            this.C1C.I12AllorsInteger = 2;
            this.C1D.I12AllorsInteger = 2;
            this.C2B.I12AllorsInteger = 1;
            this.C2C.I12AllorsInteger = 2;
            this.C2D.I12AllorsInteger = 2;

            this.C1B.S1234AllorsInteger = 1;
            this.C1C.S1234AllorsInteger = 2;
            this.C1D.S1234AllorsInteger = 2;
            this.C2B.S1234AllorsInteger = 1;
            this.C2C.S1234AllorsInteger = 2;
            this.C2D.S1234AllorsInteger = 2;
            this.C3B.S1234AllorsInteger = 1;
            this.C3C.S1234AllorsInteger = 2;
            this.C3D.S1234AllorsInteger = 2;
            this.C4B.S1234AllorsInteger = 1;
            this.C4C.S1234AllorsInteger = 2;
            this.C4D.S1234AllorsInteger = 2;

            // DateTime
            this.C1B.C1AllorsDateTime = new DateTime(2000, 1, 1, 0, 0, 4, DateTimeKind.Utc);
            this.C1C.C1AllorsDateTime = new DateTime(2000, 1, 1, 0, 0, 5, DateTimeKind.Utc);
            this.C1D.C1AllorsDateTime = new DateTime(2000, 1, 1, 0, 0, 5, DateTimeKind.Utc);

            this.C1B.C1DateTimeLessThan = new DateTime(2000, 1, 1, 0, 0, 3, DateTimeKind.Utc);
            this.C1C.C1DateTimeLessThan = new DateTime(2000, 1, 1, 0, 0, 5, DateTimeKind.Utc);
            this.C1D.C1DateTimeLessThan = new DateTime(2000, 1, 1, 0, 0, 7, DateTimeKind.Utc);

            this.C1B.C1DateTimeGreaterThan = new DateTime(2000, 1, 1, 0, 0, 3, DateTimeKind.Utc);
            this.C1C.C1DateTimeGreaterThan = new DateTime(2000, 1, 1, 0, 0, 5, DateTimeKind.Utc);
            this.C1D.C1DateTimeGreaterThan = new DateTime(2000, 1, 1, 0, 0, 7, DateTimeKind.Utc);

            this.C1B.C1DateTimeBetweenA = new DateTime(2000, 1, 1, 0, 0, 1, DateTimeKind.Utc);
            this.C1B.C1DateTimeBetweenB = new DateTime(2000, 1, 1, 0, 0, 3, DateTimeKind.Utc);
            this.C1C.C1DateTimeBetweenA = new DateTime(2000, 1, 1, 0, 0, 5, DateTimeKind.Utc);
            this.C1C.C1DateTimeBetweenB = new DateTime(2000, 1, 1, 0, 0, 5, DateTimeKind.Utc);
            this.C1D.C1DateTimeBetweenA = new DateTime(2000, 1, 1, 0, 0, 3, DateTimeKind.Utc);
            this.C1D.C1DateTimeBetweenB = new DateTime(2000, 1, 1, 0, 0, 10, DateTimeKind.Utc);

            this.C1B.I1AllorsDateTime = new DateTime(2000, 1, 1, 0, 0, 4, DateTimeKind.Utc);
            this.C1C.I1AllorsDateTime = new DateTime(2000, 1, 1, 0, 0, 5, DateTimeKind.Utc);
            this.C1D.I1AllorsDateTime = new DateTime(2000, 1, 1, 0, 0, 5, DateTimeKind.Utc);

            this.C1B.S1AllorsDateTime = new DateTime(2000, 1, 1, 0, 0, 4, DateTimeKind.Utc);
            this.C1C.S1AllorsDateTime = new DateTime(2000, 1, 1, 0, 0, 5, DateTimeKind.Utc);
            this.C1D.S1AllorsDateTime = new DateTime(2000, 1, 1, 0, 0, 5, DateTimeKind.Utc);

            this.C1B.I12AllorsDateTime = new DateTime(2000, 1, 1, 0, 0, 4, DateTimeKind.Utc);
            this.C1C.I12AllorsDateTime = new DateTime(2000, 1, 1, 0, 0, 5, DateTimeKind.Utc);
            this.C1D.I12AllorsDateTime = new DateTime(2000, 1, 1, 0, 0, 5, DateTimeKind.Utc);
            this.C2B.I12AllorsDateTime = new DateTime(2000, 1, 1, 0, 0, 4, DateTimeKind.Utc);
            this.C2C.I12AllorsDateTime = new DateTime(2000, 1, 1, 0, 0, 5, DateTimeKind.Utc);
            this.C2D.I12AllorsDateTime = new DateTime(2000, 1, 1, 0, 0, 5, DateTimeKind.Utc);

            this.C1B.S1234AllorsDateTime = new DateTime(2000, 1, 1, 0, 0, 4, DateTimeKind.Utc);
            this.C1C.S1234AllorsDateTime = new DateTime(2000, 1, 1, 0, 0, 5, DateTimeKind.Utc);
            this.C1D.S1234AllorsDateTime = new DateTime(2000, 1, 1, 0, 0, 5, DateTimeKind.Utc);
            this.C2B.S1234AllorsDateTime = new DateTime(2000, 1, 1, 0, 0, 4, DateTimeKind.Utc);
            this.C2C.S1234AllorsDateTime = new DateTime(2000, 1, 1, 0, 0, 5, DateTimeKind.Utc);
            this.C2D.S1234AllorsDateTime = new DateTime(2000, 1, 1, 0, 0, 5, DateTimeKind.Utc);
            this.C3B.S1234AllorsDateTime = new DateTime(2000, 1, 1, 0, 0, 4, DateTimeKind.Utc);
            this.C3C.S1234AllorsDateTime = new DateTime(2000, 1, 1, 0, 0, 5, DateTimeKind.Utc);
            this.C3D.S1234AllorsDateTime = new DateTime(2000, 1, 1, 0, 0, 5, DateTimeKind.Utc);
            this.C4B.S1234AllorsDateTime = new DateTime(2000, 1, 1, 0, 0, 4, DateTimeKind.Utc);
            this.C4C.S1234AllorsDateTime = new DateTime(2000, 1, 1, 0, 0, 5, DateTimeKind.Utc);
            this.C4D.S1234AllorsDateTime = new DateTime(2000, 1, 1, 0, 0, 5, DateTimeKind.Utc);

            // Float
            this.C1B.C1AllorsDouble = 1;
            this.C1C.C1AllorsDouble = 2;
            this.C1D.C1AllorsDouble = 2;

            this.C1B.C1FloatLessThan = 0;
            this.C1C.C1FloatLessThan = 2;
            this.C1D.C1FloatLessThan = 4;

            this.C1B.C1FloatGreaterThan = 0;
            this.C1C.C1FloatGreaterThan = 2;
            this.C1D.C1FloatGreaterThan = 4;

            this.C1B.C1FloatBetweenA = -10;
            this.C1B.C1FloatBetweenB = 0;
            this.C1C.C1FloatBetweenA = 2;
            this.C1C.C1FloatBetweenB = 2;
            this.C1D.C1FloatBetweenA = 0;
            this.C1D.C1FloatBetweenB = 10;

            this.C1B.I1AllorsDouble = 1;
            this.C1C.I1AllorsDouble = 2;
            this.C1D.I1AllorsDouble = 2;

            this.C1B.S1AllorsDouble = 1;
            this.C1C.S1AllorsDouble = 2;
            this.C1D.S1AllorsDouble = 2;

            this.C1B.I12AllorsDouble = 1;
            this.C1C.I12AllorsDouble = 2;
            this.C1D.I12AllorsDouble = 2;
            this.C2B.I12AllorsDouble = 1;
            this.C2C.I12AllorsDouble = 2;
            this.C2D.I12AllorsDouble = 2;

            this.C1B.S1234AllorsDouble = 1;
            this.C1C.S1234AllorsDouble = 2;
            this.C1D.S1234AllorsDouble = 2;
            this.C2B.S1234AllorsDouble = 1;
            this.C2C.S1234AllorsDouble = 2;
            this.C2D.S1234AllorsDouble = 2;
            this.C3B.S1234AllorsDouble = 1;
            this.C3C.S1234AllorsDouble = 2;
            this.C3D.S1234AllorsDouble = 2;
            this.C4B.S1234AllorsDouble = 1;
            this.C4C.S1234AllorsDouble = 2;
            this.C4D.S1234AllorsDouble = 2;

            // Decimal
            this.C1B.C1AllorsDecimal = 1;
            this.C1C.C1AllorsDecimal = 2;
            this.C1D.C1AllorsDecimal = 2;

            this.C1B.C1DecimalLessThan = 0;
            this.C1C.C1DecimalLessThan = 2;
            this.C1D.C1DecimalLessThan = 4;

            this.C1B.C1DecimalGreaterThan = 0;
            this.C1C.C1DecimalGreaterThan = 2;
            this.C1D.C1DecimalGreaterThan = 4;

            this.C1B.C1DecimalBetweenA = -10;
            this.C1B.C1DecimalBetweenB = 0;
            this.C1C.C1DecimalBetweenA = 2;
            this.C1C.C1DecimalBetweenB = 2;
            this.C1D.C1DecimalBetweenA = 0;
            this.C1D.C1DecimalBetweenB = 10;

            this.C1B.I1AllorsDecimal = 1;
            this.C1C.I1AllorsDecimal = 2;
            this.C1D.I1AllorsDecimal = 2;

            this.C1B.S1AllorsDecimal = 1;
            this.C1C.S1AllorsDecimal = 2;
            this.C1D.S1AllorsDecimal = 2;

            this.C1B.I12AllorsDecimal = 1;
            this.C1C.I12AllorsDecimal = 2;
            this.C1D.I12AllorsDecimal = 2;
            this.C2B.I12AllorsDecimal = 1;
            this.C2C.I12AllorsDecimal = 2;
            this.C2D.I12AllorsDecimal = 2;

            this.C1B.S1234AllorsDecimal = 1;
            this.C1C.S1234AllorsDecimal = 2;
            this.C1D.S1234AllorsDecimal = 2;
            this.C2B.S1234AllorsDecimal = 1;
            this.C2C.S1234AllorsDecimal = 2;
            this.C2D.S1234AllorsDecimal = 2;
            this.C3B.S1234AllorsDecimal = 1;
            this.C3C.S1234AllorsDecimal = 2;
            this.C3D.S1234AllorsDecimal = 2;
            this.C4B.S1234AllorsDecimal = 1;
            this.C4C.S1234AllorsDecimal = 2;
            this.C4D.S1234AllorsDecimal = 2;

            // Composites
            this.C1B.C1C1one2one = this.C1B;
            this.C1C.C1C1one2one = this.C1C;
            this.C1D.C1C1one2one = this.C1D;

            this.C1B.C1C2one2one = this.C2B;
            this.C1C.C1C2one2one = this.C2C;
            this.C1D.C1C2one2one = this.C2D;

            this.C1B.C1C3one2one = this.C3B;
            this.C1C.C1C3one2one = this.C3C;
            this.C1D.C1C3one2one = this.C3D;

            this.C3B.C3C4one2one = this.C4B;
            this.C3C.C3C4one2one = this.C4C;
            this.C3D.C3C4one2one = this.C4D;

            this.C1B.I1I2one2one = this.C2B;
            this.C1C.I1I2one2one = this.C2C;
            this.C1D.I1I2one2one = this.C2D;

            this.C1B.S1S2one2one = this.C2B;
            this.C1C.S1S2one2one = this.C2C;
            this.C1D.S1S2one2one = this.C2D;

            this.C1B.I12C2one2one = this.C2B;
            this.C1C.I12C2one2one = this.C2C;
            this.C1D.I12C2one2one = this.C2D;
            this.C2A.I12C2one2one = this.C2A;

            this.C1B.I12C3one2one = this.C3B;
            this.C1C.I12C3one2one = this.C3C;
            this.C1D.I12C3one2one = this.C3D;
            this.C2A.I12C3one2one = this.C3A;

            this.C1B.S1234C2one2one = this.C2B;
            this.C1C.S1234C2one2one = this.C2C;
            this.C1D.S1234C2one2one = this.C2D;
            this.C2A.S1234C2one2one = this.C2A;

            this.C1B.C1I12one2one = this.C1B;
            this.C1C.C1I12one2one = this.C2B;
            this.C1D.C1I12one2one = this.C2C;

            this.C1B.S1234one2one = this.C1B;
            this.C1C.S1234one2one = this.C2B;
            this.C1D.S1234one2one = this.C3B;
            this.C2B.S1234one2one = this.C1C;
            this.C2C.S1234one2one = this.C2C;
            this.C2D.S1234one2one = this.C3C;
            this.C3B.S1234one2one = this.C1D;
            this.C3C.S1234one2one = this.C2D;
            this.C3D.S1234one2one = this.C3D;

            this.C1B.AddC1C1one2many(this.C1B);
            this.C1C.AddC1C1one2many(this.C1C);
            this.C1C.AddC1C1one2many(this.C1D);

            this.C1B.AddC1C2one2many(this.C2B);
            this.C1C.AddC1C2one2many(this.C2C);
            this.C1C.AddC1C2one2many(this.C2D);

            this.C3B.AddC3C4one2many(this.C4B);
            this.C3C.AddC3C4one2many(this.C4C);
            this.C3C.AddC3C4one2many(this.C4D);

            this.C1B.AddI1I2one2many(this.C2B);
            this.C1C.AddI1I2one2many(this.C2C);
            this.C1C.AddI1I2one2many(this.C2D);

            this.C1B.AddS1S2one2many(this.C2B);
            this.C1C.AddS1S2one2many(this.C2C);
            this.C1C.AddS1S2one2many(this.C2D);

            this.C1B.AddI12C2one2many(this.C2B);
            this.C2C.AddI12C2one2many(this.C2C);
            this.C2C.AddI12C2one2many(this.C2D);

            this.C1B.AddS1234C2one2many(this.C2B);
            this.C3C.AddS1234C2one2many(this.C2C);
            this.C3C.AddS1234C2one2many(this.C2D);

            this.C1B.AddC1I12one2many(this.C1B);
            this.C1C.AddC1I12one2many(this.C2C);
            this.C1C.AddC1I12one2many(this.C2D);

            this.C1B.AddS1234one2many(this.C1B);
            this.C3C.AddS1234one2many(this.C1C);
            this.C3C.AddS1234one2many(this.C1D);

            this.C1B.C1C1many2one = this.C1B;
            this.C1C.C1C1many2one = this.C1C;
            this.C1D.C1C1many2one = this.C1C;

            this.C1B.C1C2many2one = this.C2B;
            this.C1C.C1C2many2one = this.C2C;
            this.C1D.C1C2many2one = this.C2C;

            this.C3B.C3C4many2one = this.C4B;
            this.C3C.C3C4many2one = this.C4C;
            this.C3D.C3C4many2one = this.C4C;

            this.C1B.I1I2many2one = this.C2B;
            this.C1C.I1I2many2one = this.C2C;
            this.C1D.I1I2many2one = this.C2C;

            this.C1B.S1S2many2one = this.C2B;
            this.C1C.S1S2many2one = this.C2C;
            this.C1D.S1S2many2one = this.C2C;

            this.C1B.I12C2many2one = this.C2B;
            this.C2C.I12C2many2one = this.C2C;
            this.C2D.I12C2many2one = this.C2C;

            this.C1B.S1234C2many2one = this.C2B;
            this.C3C.S1234C2many2one = this.C2C;
            this.C3D.S1234C2many2one = this.C2C;

            this.C1B.C1I12many2one = this.C1B;
            this.C1C.C1I12many2one = this.C2C;
            this.C1D.C1I12many2one = this.C2C;

            this.C1B.S1234many2one = this.C1B;
            this.C3C.S1234many2one = this.C1C;
            this.C3D.S1234many2one = this.C1C;

            this.C1B.I12I34many2one = this.C3B;
            this.C2B.I12I34many2one = this.C4B;
            this.C2D.I12I34many2one = this.C4B;

            this.C1B.AddC1C1many2many(this.C1B);
            this.C1C.AddC1C1many2many(this.C1B);
            this.C1D.AddC1C1many2many(this.C1B);
            this.C1C.AddC1C1many2many(this.C1C);
            this.C1D.AddC1C1many2many(this.C1C);
            this.C1D.AddC1C1many2many(this.C1D);

            this.C1B.AddC1C2many2many(this.C2B);
            this.C1C.AddC1C2many2many(this.C2B);
            this.C1D.AddC1C2many2many(this.C2B);
            this.C1C.AddC1C2many2many(this.C2C);
            this.C1D.AddC1C2many2many(this.C2C);
            this.C1D.AddC1C2many2many(this.C2D);

            this.C1B.AddI1I2many2many(this.C2B);
            this.C1C.AddI1I2many2many(this.C2B);
            this.C1C.AddI1I2many2many(this.C2C);
            this.C1D.AddI1I2many2many(this.C2B);
            this.C1D.AddI1I2many2many(this.C2C);
            this.C1D.AddI1I2many2many(this.C2D);

            this.C1B.AddS1S2many2many(this.C2B);
            this.C1C.AddS1S2many2many(this.C2B);
            this.C1C.AddS1S2many2many(this.C2C);
            this.C1D.AddS1S2many2many(this.C2B);
            this.C1D.AddS1S2many2many(this.C2C);
            this.C1D.AddS1S2many2many(this.C2D);

            this.C1B.AddI12C2many2many(this.C2B);
            this.C1C.AddI12C2many2many(this.C2B);
            this.C1C.AddI12C2many2many(this.C2C);
            this.C1D.AddI12C2many2many(this.C2B);
            this.C1D.AddI12C2many2many(this.C2C);
            this.C1D.AddI12C2many2many(this.C2D);
            this.C2A.AddI12C2many2many(this.C2A);
            this.C2A.AddI12C2many2many(this.C2B);
            this.C2A.AddI12C2many2many(this.C2C);
            this.C2A.AddI12C2many2many(this.C2D);

            this.C1B.AddI12I34many2many(this.C3B);
            this.C1C.AddI12I34many2many(this.C3B);
            this.C1C.AddI12I34many2many(this.C3C);
            this.C1D.AddI12I34many2many(this.C3B);
            this.C1D.AddI12I34many2many(this.C3C);
            this.C1D.AddI12I34many2many(this.C3D);
            this.C2A.AddI12I34many2many(this.C4A);
            this.C2A.AddI12I34many2many(this.C4B);
            this.C2A.AddI12I34many2many(this.C4C);
            this.C2A.AddI12I34many2many(this.C4D);

            this.C1B.AddS1234C2many2many(this.C2B);
            this.C1C.AddS1234C2many2many(this.C2B);
            this.C1C.AddS1234C2many2many(this.C2C);
            this.C1D.AddS1234C2many2many(this.C2B);
            this.C1D.AddS1234C2many2many(this.C2C);
            this.C1D.AddS1234C2many2many(this.C2D);
            this.C2A.AddS1234C2many2many(this.C2A);
            this.C2A.AddS1234C2many2many(this.C2B);
            this.C2A.AddS1234C2many2many(this.C2C);
            this.C2A.AddS1234C2many2many(this.C2D);

            this.C1B.AddC1I12many2many(this.C1B);
            this.C1B.AddC1I12many2many(this.C2B);
            this.C1C.AddC1I12many2many(this.C2B);
            this.C1C.AddC1I12many2many(this.C2C);
            this.C1D.AddC1I12many2many(this.C2B);
            this.C1D.AddC1I12many2many(this.C2C);
            this.C1D.AddC1I12many2many(this.C2D);

            this.C1B.AddS1234many2many(this.C1B);
            this.C1B.AddS1234many2many(this.C1A);
            this.C1C.AddS1234many2many(this.C2B);
            this.C1C.AddS1234many2many(this.C1A);
            this.C1D.AddS1234many2many(this.C3B);
            this.C1D.AddS1234many2many(this.C1A);
            this.C2B.AddS1234many2many(this.C1C);
            this.C2B.AddS1234many2many(this.C1A);
            this.C2C.AddS1234many2many(this.C2C);
            this.C2C.AddS1234many2many(this.C1A);
            this.C2D.AddS1234many2many(this.C3C);
            this.C2D.AddS1234many2many(this.C1A);
            this.C3B.AddS1234many2many(this.C1D);
            this.C3B.AddS1234many2many(this.C1A);
            this.C3C.AddS1234many2many(this.C2D);
            this.C3C.AddS1234many2many(this.C1A);
            this.C3D.AddS1234many2many(this.C3D);
            this.C3D.AddS1234many2many(this.C1A);


            this.C1B.ClassName = "c1";
            this.C3B.ClassName = "c3";
        }
Exemple #7
0
        public void UnitRole()
        {
            foreach (var init in this.Inits)
            {
                init();

                var a = (C1)this.Session.Create(MetaC1.Instance.ObjectType);
                var c = this.Session.Create(MetaC3.Instance.ObjectType);
                this.Session.Commit();

                a = (C1)this.Session.Instantiate(a);
                var b = C2.Create(this.Session);
                this.Session.Instantiate(c);

                a.C1AllorsString = "a changed";
                b.C2AllorsString = "b changed";

                var changeSet = this.Session.Checkpoint();

                var associations = changeSet.Associations;
                var roles        = changeSet.Roles;

                Assert.Equal(2, associations.Count);
                Assert.Contains(a.Id, associations.ToArray());
                Assert.Contains(b.Id, associations.ToArray());

                Assert.Equal("a changed", a.C1AllorsString);
                Assert.Equal("b changed", b.C2AllorsString);

                Assert.Single(changeSet.GetRoleTypes(a.Id));
                Assert.Equal(MetaC1.Instance.C1AllorsString, changeSet.GetRoleTypes(a.Id).First());

                Assert.Single(changeSet.GetRoleTypes(b.Id));
                Assert.Equal(MetaC2.Instance.C2AllorsString, changeSet.GetRoleTypes(b.Id).First());

                Assert.True(associations.Contains(a.Id));
                Assert.True(associations.Contains(b.Id));
                Assert.False(associations.Contains(c.Id));

                Assert.False(roles.Contains(a.Id));
                Assert.False(roles.Contains(b.Id));
                Assert.False(roles.Contains(c.Id));

                a.C1AllorsString = "a changed again";
                b.C2AllorsString = "b changed again";

                changeSet = this.Session.Checkpoint();

                associations = changeSet.Associations;
                roles        = changeSet.Roles;

                Assert.Equal(2, associations.Count);
                Assert.True(associations.Contains(a.Id));
                Assert.True(associations.Contains(a.Id));

                Assert.Single(changeSet.GetRoleTypes(a.Id));
                Assert.Equal(MetaC1.Instance.C1AllorsString, changeSet.GetRoleTypes(a.Id).First());

                Assert.Single(changeSet.GetRoleTypes(b.Id));
                Assert.Equal(MetaC2.Instance.C2AllorsString, changeSet.GetRoleTypes(b.Id).First());

                Assert.True(associations.Contains(a.Id));
                Assert.True(associations.Contains(b.Id));
                Assert.False(associations.Contains(c.Id));

                Assert.False(roles.Contains(a.Id));
                Assert.False(roles.Contains(b.Id));
                Assert.False(roles.Contains(c.Id));

                changeSet = this.Session.Checkpoint();

                associations = changeSet.Associations;
                roles        = changeSet.Roles;

                Assert.Equal(0, associations.Count);
                Assert.Empty(changeSet.GetRoleTypes(a.Id));
                Assert.Empty(changeSet.GetRoleTypes(b.Id));

                Assert.False(associations.Contains(a.Id));
                Assert.False(associations.Contains(b.Id));
                Assert.False(associations.Contains(c.Id));

                Assert.False(roles.Contains(a.Id));
                Assert.False(roles.Contains(b.Id));
                Assert.False(roles.Contains(c.Id));

                a.RemoveC1AllorsString();
                b.RemoveC2AllorsString();

                changeSet = this.Session.Checkpoint();

                associations = changeSet.Associations;
                roles        = changeSet.Roles;

                Assert.Equal(2, associations.Count);
                Assert.True(associations.Contains(a.Id));
                Assert.True(associations.Contains(a.Id));

                Assert.Single(changeSet.GetRoleTypes(a.Id));
                Assert.Equal(MetaC1.Instance.C1AllorsString, changeSet.GetRoleTypes(a.Id).First());

                Assert.Single(changeSet.GetRoleTypes(b.Id));
                Assert.Equal(MetaC2.Instance.C2AllorsString, changeSet.GetRoleTypes(b.Id).First());

                Assert.True(associations.Contains(a.Id));
                Assert.True(associations.Contains(b.Id));
                Assert.False(associations.Contains(c.Id));

                Assert.False(roles.Contains(a.Id));
                Assert.False(roles.Contains(b.Id));
                Assert.False(roles.Contains(c.Id));

                changeSet = this.Session.Checkpoint();

                associations = changeSet.Associations;
                roles        = changeSet.Roles;

                Assert.Equal(0, associations.Count);
                Assert.Empty(changeSet.GetRoleTypes(a.Id));
                Assert.Empty(changeSet.GetRoleTypes(b.Id));

                Assert.False(associations.Contains(a.Id));
                Assert.False(associations.Contains(b.Id));
                Assert.False(associations.Contains(c.Id));

                Assert.False(roles.Contains(a.Id));
                Assert.False(roles.Contains(b.Id));

                this.Session.Rollback();

                changeSet = this.Session.Checkpoint();

                associations = changeSet.Associations;
                roles        = changeSet.Roles;

                Assert.Equal(0, associations.Count);
                Assert.Empty(changeSet.GetRoleTypes(a.Id));
                Assert.Empty(changeSet.GetRoleTypes(b.Id));

                Assert.False(associations.Contains(a.Id));
                Assert.False(associations.Contains(b.Id));
                Assert.False(associations.Contains(c.Id));

                Assert.False(roles.Contains(a.Id));
                Assert.False(roles.Contains(b.Id));

                a.C1AllorsString = "a changed";

                this.Session.Commit();

                changeSet = this.Session.Checkpoint();

                associations = changeSet.Associations;
                roles        = changeSet.Roles;

                Assert.Equal(0, associations.Count);
                Assert.Empty(changeSet.GetRoleTypes(a.Id));
                Assert.Empty(changeSet.GetRoleTypes(b.Id));

                Assert.False(associations.Contains(a.Id));
                Assert.False(associations.Contains(b.Id));
                Assert.False(associations.Contains(c.Id));

                Assert.False(roles.Contains(a.Id));
                Assert.False(roles.Contains(b.Id));
            }
        }
Exemple #8
0
        public void CompositeRoles()
        {
            foreach (var init in this.Inits)
            {
                init();

                var c1a = (C1)this.Session.Create(MetaC1.Instance.ObjectType);
                var c1b = (C1)this.Session.Create(MetaC1.Instance.ObjectType);
                var c2a = (C2)this.Session.Create(MetaC2.Instance.ObjectType);

                this.Session.Commit();

                c1a = (C1)this.Session.Instantiate(c1a);
                var c2b = C2.Create(this.Session);
                this.Session.Instantiate(c2a);

                c1a.AddC1C2one2many(c2b);

                var changes = this.Session.Checkpoint();

                var associations = changes.Associations.ToArray();
                var roles        = changes.Roles.ToArray();

                Assert.Single(associations);
                Assert.Contains(c1a.Id, associations);

                Assert.Single(roles);
                Assert.Contains(c2b.Id, roles);

                Assert.Single(changes.GetRoleTypes(c1a.Id));
                Assert.Equal(MetaC1.Instance.C1C2one2manies, changes.GetRoleTypes(c1a.Id).First());

                Assert.Contains(c1a.Id, associations);
                Assert.DoesNotContain(c2b.Id, associations);
                Assert.DoesNotContain(c2a.Id, associations);

                Assert.DoesNotContain(c1a.Id, roles);
                Assert.Contains(c2b.Id, roles);
                Assert.DoesNotContain(c2a.Id, roles);

                changes = this.Session.Checkpoint();

                associations = changes.Associations.ToArray();
                roles        = changes.Roles.ToArray();

                Assert.Empty(associations);
                Assert.Empty(roles);
                Assert.Empty(changes.GetRoleTypes(c1a.Id));
                Assert.Empty(changes.GetRoleTypes(c2b.Id));
                Assert.Empty(changes.GetRoleTypes(c2a.Id));

                c1a.AddC1C2one2many(c2a);

                changes = this.Session.Checkpoint();

                associations = changes.Associations.ToArray();
                roles        = changes.Roles.ToArray();

                Assert.Single(associations);
                Assert.Contains(c1a.Id, associations);

                Assert.Single(roles);
                Assert.Contains(c2a.Id, roles);

                Assert.Single(changes.GetRoleTypes(c1a.Id));
                Assert.Equal(MetaC1.Instance.C1C2one2manies, changes.GetRoleTypes(c1a.Id).First());

                Assert.Contains(c1a.Id, associations);
                Assert.DoesNotContain(c2b.Id, associations);
                Assert.DoesNotContain(c2a.Id, associations);

                Assert.DoesNotContain(c1a.Id, roles);
                Assert.DoesNotContain(c2b.Id, roles);
                Assert.Contains(c2a.Id, roles);

                changes = this.Session.Checkpoint();

                associations = changes.Associations.ToArray();
                roles        = changes.Roles.ToArray();

                Assert.Empty(associations);
                Assert.Empty(roles);
                Assert.Empty(changes.GetRoleTypes(c1a.Id));
                Assert.Empty(changes.GetRoleTypes(c2b.Id));
                Assert.Empty(changes.GetRoleTypes(c2a.Id));

                c1a.RemoveC1C2one2many(c2a);

                changes = this.Session.Checkpoint();

                associations = changes.Associations.ToArray();
                roles        = changes.Roles.ToArray();

                Assert.Single(associations);
                Assert.Contains(c1a.Id, associations);

                Assert.Single(roles);
                Assert.Contains(c2a.Id, roles);

                Assert.Single(changes.GetRoleTypes(c1a.Id));
                Assert.Equal(MetaC1.Instance.C1C2one2manies, changes.GetRoleTypes(c1a.Id).First());

                Assert.Contains(c1a.Id, associations);
                Assert.DoesNotContain(c2b.Id, associations);
                Assert.DoesNotContain(c2a.Id, associations);

                Assert.DoesNotContain(c1a.Id, roles);
                Assert.DoesNotContain(c2b.Id, roles);
                Assert.Contains(c2a.Id, roles);

                changes = this.Session.Checkpoint();

                associations = changes.Associations.ToArray();
                roles        = changes.Roles.ToArray();

                Assert.Empty(associations);
                Assert.Empty(roles);
                Assert.Empty(changes.GetRoleTypes(c1a.Id));
                Assert.Empty(changes.GetRoleTypes(c2b.Id));
                Assert.Empty(changes.GetRoleTypes(c2a.Id));

                c1a.RemoveC1C2one2many(c2b);

                changes = this.Session.Checkpoint();

                associations = changes.Associations.ToArray();
                roles        = changes.Roles.ToArray();

                Assert.Single(associations);
                Assert.Contains(c1a.Id, associations);

                Assert.Single(roles);
                Assert.Contains(c2b.Id, roles);

                Assert.Single(changes.GetRoleTypes(c1a.Id));
                Assert.Equal(MetaC1.Instance.C1C2one2manies, changes.GetRoleTypes(c1a.Id).First());

                Assert.Contains(c1a.Id, associations);
                Assert.DoesNotContain(c2b.Id, associations);
                Assert.DoesNotContain(c2a.Id, associations);

                Assert.DoesNotContain(c1a.Id, roles);
                Assert.Contains(c2b.Id, roles);
                Assert.DoesNotContain(c2a.Id, roles);

                changes = this.Session.Checkpoint();

                associations = changes.Associations.ToArray();
                roles        = changes.Roles.ToArray();

                Assert.Empty(associations);
                Assert.Empty(roles);
                Assert.Empty(changes.GetRoleTypes(c1a.Id));
                Assert.Empty(changes.GetRoleTypes(c2b.Id));
                Assert.Empty(changes.GetRoleTypes(c2a.Id));

                c1a.AddC1C2one2many(c2a);

                this.Session.Rollback();

                changes = this.Session.Checkpoint();

                associations = changes.Associations.ToArray();
                roles        = changes.Roles.ToArray();

                Assert.Empty(associations);
                Assert.Empty(roles);

                Assert.Empty(changes.GetRoleTypes(c1a.Id));
                Assert.Empty(changes.GetRoleTypes(c2b.Id));
                Assert.Empty(changes.GetRoleTypes(c2a.Id));

                c1a.AddC1C2one2many(c2a);

                this.Session.Commit();

                changes = this.Session.Checkpoint();

                associations = changes.Associations.ToArray();
                roles        = changes.Roles.ToArray();

                Assert.Empty(associations);
                Assert.Empty(roles);

                Assert.Empty(changes.GetRoleTypes(c1a.Id));
                Assert.Empty(changes.GetRoleTypes(c2b.Id));
                Assert.Empty(changes.GetRoleTypes(c2a.Id));

                c1b.AddC1C2one2many(c2a);

                changes = this.Session.Checkpoint();

                associations = changes.Associations.ToArray();
                roles        = changes.Roles.ToArray();

                Assert.Equal(2, associations.Length);
                Assert.Single(roles);
                Assert.Single(changes.GetRoleTypes(c1a.Id));
                Assert.Single(changes.GetRoleTypes(c1b.Id));
                Assert.Empty(changes.GetRoleTypes(c2b.Id));
                Assert.Empty(changes.GetRoleTypes(c2a.Id));
            }
        }
        public void CompositeRoles()
        {
            foreach (var init in this.Inits)
            {
                init();

                var a = (C1)this.Session.Create(MetaC1.Instance.ObjectType);
                var c = (C2)this.Session.Create(MetaC2.Instance.ObjectType);

                this.Session.Commit();

                a = (C1)this.Session.Instantiate(a);
                var b = C2.Create(this.Session);
                this.Session.Instantiate(c);

                a.AddC1C2one2many(b);

                var changes = this.Session.Checkpoint();

                var associations = changes.Associations.ToArray();
                var roles        = changes.Roles.ToArray();

                Assert.AreEqual(1, associations.Length);
                Assert.Contains(a.Id, associations);

                Assert.AreEqual(1, roles.Length);
                Assert.Contains(b.Id, roles);

                Assert.AreEqual(1, changes.GetRoleTypes(a.Id).Count());
                Assert.AreEqual(MetaC1.Instance.C1C2one2manies, changes.GetRoleTypes(a.Id).First());

                Assert.IsTrue(associations.Contains(a.Id));
                Assert.IsFalse(associations.Contains(b.Id));
                Assert.IsFalse(associations.Contains(c.Id));

                Assert.IsFalse(roles.Contains(a.Id));
                Assert.IsTrue(roles.Contains(b.Id));
                Assert.IsFalse(roles.Contains(c.Id));

                changes = this.Session.Checkpoint();

                associations = changes.Associations.ToArray();
                roles        = changes.Roles.ToArray();

                Assert.AreEqual(0, associations.Length);
                Assert.AreEqual(0, roles.Length);
                Assert.AreEqual(0, changes.GetRoleTypes(a.Id).Count());
                Assert.AreEqual(0, changes.GetRoleTypes(b.Id).Count());
                Assert.AreEqual(0, changes.GetRoleTypes(c.Id).Count());

                a.AddC1C2one2many(c);

                changes = this.Session.Checkpoint();

                associations = changes.Associations.ToArray();
                roles        = changes.Roles.ToArray();

                Assert.AreEqual(1, associations.Length);
                Assert.Contains(a.Id, associations);

                Assert.AreEqual(1, roles.Length);
                Assert.Contains(c.Id, roles);

                Assert.AreEqual(1, changes.GetRoleTypes(a.Id).Count());
                Assert.AreEqual(MetaC1.Instance.C1C2one2manies, changes.GetRoleTypes(a.Id).First());

                Assert.IsTrue(associations.Contains(a.Id));
                Assert.IsFalse(associations.Contains(b.Id));
                Assert.IsFalse(associations.Contains(c.Id));

                Assert.IsFalse(roles.Contains(a.Id));
                Assert.IsFalse(roles.Contains(b.Id));
                Assert.IsTrue(roles.Contains(c.Id));

                changes = this.Session.Checkpoint();

                associations = changes.Associations.ToArray();
                roles        = changes.Roles.ToArray();

                Assert.AreEqual(0, associations.Length);
                Assert.AreEqual(0, roles.Length);
                Assert.AreEqual(0, changes.GetRoleTypes(a.Id).Count());
                Assert.AreEqual(0, changes.GetRoleTypes(b.Id).Count());
                Assert.AreEqual(0, changes.GetRoleTypes(c.Id).Count());

                a.RemoveC1C2one2many(c);

                changes = this.Session.Checkpoint();

                associations = changes.Associations.ToArray();
                roles        = changes.Roles.ToArray();

                Assert.AreEqual(1, associations.Length);
                Assert.Contains(a.Id, associations);

                Assert.AreEqual(1, roles.Length);
                Assert.Contains(c.Id, roles);

                Assert.AreEqual(1, changes.GetRoleTypes(a.Id).Count());
                Assert.AreEqual(MetaC1.Instance.C1C2one2manies, changes.GetRoleTypes(a.Id).First());

                Assert.IsTrue(associations.Contains(a.Id));
                Assert.IsFalse(associations.Contains(b.Id));
                Assert.IsFalse(associations.Contains(c.Id));

                Assert.IsFalse(roles.Contains(a.Id));
                Assert.IsFalse(roles.Contains(b.Id));
                Assert.IsTrue(roles.Contains(c.Id));

                changes = this.Session.Checkpoint();

                associations = changes.Associations.ToArray();
                roles        = changes.Roles.ToArray();

                Assert.AreEqual(0, associations.Length);
                Assert.AreEqual(0, roles.Length);
                Assert.AreEqual(0, changes.GetRoleTypes(a.Id).Count());
                Assert.AreEqual(0, changes.GetRoleTypes(b.Id).Count());
                Assert.AreEqual(0, changes.GetRoleTypes(c.Id).Count());

                a.RemoveC1C2one2many(b);

                changes = this.Session.Checkpoint();

                associations = changes.Associations.ToArray();
                roles        = changes.Roles.ToArray();

                Assert.AreEqual(1, associations.Length);
                Assert.Contains(a.Id, associations);

                Assert.AreEqual(1, roles.Length);
                Assert.Contains(b.Id, roles);

                Assert.AreEqual(1, changes.GetRoleTypes(a.Id).Count());
                Assert.AreEqual(MetaC1.Instance.C1C2one2manies, changes.GetRoleTypes(a.Id).First());

                Assert.IsTrue(associations.Contains(a.Id));
                Assert.IsFalse(associations.Contains(b.Id));
                Assert.IsFalse(associations.Contains(c.Id));

                Assert.IsFalse(roles.Contains(a.Id));
                Assert.IsTrue(roles.Contains(b.Id));
                Assert.IsFalse(roles.Contains(c.Id));

                changes = this.Session.Checkpoint();

                associations = changes.Associations.ToArray();
                roles        = changes.Roles.ToArray();

                Assert.AreEqual(0, associations.Length);
                Assert.AreEqual(0, roles.Length);
                Assert.AreEqual(0, changes.GetRoleTypes(a.Id).Count());
                Assert.AreEqual(0, changes.GetRoleTypes(b.Id).Count());
                Assert.AreEqual(0, changes.GetRoleTypes(c.Id).Count());

                a.AddC1C2one2many(c);

                this.Session.Rollback();

                changes = this.Session.Checkpoint();

                associations = changes.Associations.ToArray();
                roles        = changes.Roles.ToArray();

                Assert.AreEqual(0, associations.Length);
                Assert.AreEqual(0, roles.Length);

                Assert.AreEqual(0, changes.GetRoleTypes(a.Id).Count());
                Assert.AreEqual(0, changes.GetRoleTypes(b.Id).Count());
                Assert.AreEqual(0, changes.GetRoleTypes(c.Id).Count());

                a.AddC1C2one2many(c);

                this.Session.Commit();

                changes = this.Session.Checkpoint();

                associations = changes.Associations.ToArray();
                roles        = changes.Roles.ToArray();

                Assert.AreEqual(0, associations.Length);
                Assert.AreEqual(0, roles.Length);

                Assert.AreEqual(0, changes.GetRoleTypes(a.Id).Count());
                Assert.AreEqual(0, changes.GetRoleTypes(b.Id).Count());
                Assert.AreEqual(0, changes.GetRoleTypes(c.Id).Count());
            }
        }
Exemple #10
0
        private void Populate(ISession session)
        {
            this.c1A = C1.Create(session);
            this.c1B = C1.Create(session);
            this.c1C = C1.Create(session);
            this.c1D = C1.Create(session);
            this.c2A = C2.Create(session);
            this.c2B = C2.Create(session);
            this.c2C = C2.Create(session);
            this.c2D = C2.Create(session);
            this.c3A = C3.Create(session);
            this.c3B = C3.Create(session);
            this.c3C = C3.Create(session);
            this.c3D = C3.Create(session);
            this.c4A = C4.Create(session);
            this.c4B = C4.Create(session);
            this.c4C = C4.Create(session);
            this.c4D = C4.Create(session);

            IObject[] allObjects =
            {
                this.c1A, this.c1B, this.c1C, this.c1D, this.c2A, this.c2B, this.c2C, this.c2D,
                this.c3A, this.c3B, this.c3C, this.c3D, this.c4A, this.c4B, this.c4C, this.c4D
            };

            this.c1A.C1AllorsString   = string.Empty; // emtpy string
            this.c1A.C1AllorsInteger  = -1;
            this.c1A.C1AllorsDecimal  = 1.1m;
            this.c1A.C1AllorsDouble   = 1.1d;
            this.c1A.C1AllorsBoolean  = true;
            this.c1A.C1AllorsDateTime = new DateTime(1973, 3, 27, 12, 1, 2, 3, DateTimeKind.Utc);
            this.c1A.C1AllorsUnique   = new Guid(GuidString);
            this.c1A.C1AllorsBinary   = new byte[0];

            this.c1B.C1AllorsString = "a1";
            this.c1B.C1AllorsBinary = new byte[] { 0, 1, 2, 3 };
            this.c1B.C1C2one2one    = this.c2A;
            this.c1B.C1C2many2one   = this.c2A;
            this.c1C.C1C2many2one   = this.c2A;
            this.c1B.AddC1C2one2many(this.c2A);
            this.c1B.AddC1C2one2many(this.c2B);
            this.c1B.AddC1C2one2many(this.c2C);
            this.c1B.AddC1C2one2many(this.c2D);
            this.c1B.AddC1C2many2many(this.c2A);
            this.c1B.AddC1C2many2many(this.c2B);
            this.c1B.AddC1C2many2many(this.c2C);
            this.c1B.AddC1C2many2many(this.c2D);

            this.c1C.C1AllorsString = "a2";
            this.c1C.C1AllorsBinary = null;

            this.c3A.I34AllorsString = "c3a";
            this.c4A.I34AllorsString = "c4a";

            foreach (S1234 allorsObject in allObjects)
            {
                foreach (S1234 addObject in allObjects)
                {
                    allorsObject.AddS1234many2many(addObject);
                }
            }

            session.Commit();
        }
Exemple #11
0
        public void FailedCommit()
        {
            var database = this.CreateDatabase();

            database.Init();

            long c1Id = 0;
            long c2Id = 0;

            using (var session = database.CreateSession())
            {
                var c1 = C1.Create(session);
                var c2 = C2.Create(session);

                c1Id = c1.Id;
                c2Id = c2.Id;

                c1.C1C2one2one = c2;

                session.Commit();

                c1.C1AllorsString = "Session 1";

                using (var session2 = database.CreateSession())
                {
                    var session2C1 = (C1)session2.Instantiate(c1);
                    session2C1.C1AllorsString = "Session 2";

                    session2C1.C1C2one2one = null;

                    session2.Commit();

                    var session2C2 = (C2)session2.Instantiate(c2);
                    session2C2.Strategy.Delete();

                    session2.Commit();
                }

                var triggerCache = c1.C1C2one2one;

                var exceptionThrown = false;
                try
                {
                    session.Commit();
                }
                catch
                {
                    exceptionThrown = true;
                }

                Assert.True(exceptionThrown);
            }

            using (var session = database.CreateSession())
            {
                var c1 = (C1)session.Instantiate(c1Id);
                var c2 = session.Instantiate(c2Id);

                Assert.Null(c1.C1C2one2one);
            }
        }