Esempio n. 1
0
        public void LinqExploratoryTestWhichProvesNothing()
        {
            {
                var i1001 = new MyRef1 {
                    Id = 1001, I1 = null, I2 = 101
                };
                var i1101 = new MyRef1 {
                    Id = 1101, I1 = null, I2 = 111
                };
                var i1002 = new MyRef1 {
                    Id = 1002, I1 = 12, I2 = 102
                };
                var i1003 = new MyRef1 {
                    Id = 1003, I1 = 13, I2 = 103
                };

                var ref1s = new[] { i1001, i1101, i1002, i1003 };

                var someRef1s = from r in ref1s
                                orderby(r.Id == 1101 || r.Id == 1102?r.Id - 1000 : r.Id)
                                select(r.Id == 1101 || r.Id == 1102 ? r.Id + 1000 : r.Id);

                CollectionAssert.AreEqual(new[] { 2101, 1001, 1002, 1003 }, someRef1s.ToList());
            }
            {
                var j2001 = new MyRef2 {
                    Id = 2001, J1 = null, J2 = 201
                };
                var j2002 = new MyRef2 {
                    Id = 2002, J1 = 22, J2 = 202
                };

                var i1001 = new MyRef1 {
                    Id = 1001, I1 = null, I2 = 101, BO2 = j2001
                };
                var i1002 = new MyRef1 {
                    Id = 1002, I1 = 12, I2 = 102, BO2 = null
                };

                var b10 = new MyBO {
                    Id = 10, Name = "1:1001,o1:NULL,2:NULL", BO1 = i1001, OtherBO1 = null, BO2 = null
                };
                var b20 = new MyBO {
                    Id = 20, Name = "1:1002,o1:NULL,2:2002", BO1 = i1002, OtherBO1 = null, BO2 = j2002
                };

                var bos = new[] { b10 };

                //var someBos = from r in bos
                //              where r.BO1.BO2.J2 == 201
                //              select r;
                //CollectionAssert.AreEqual(new[] { b10 }, someBos.ToList());

                var someBos1 = from r in bos
                               where (r.BO1.BO2 == null ? r.BO2 : r.BO1.BO2).J2 == 201
                               select r.Id;
                Assert.That(() => someBos1.ToList(), Is.EquivalentTo(new[] { b10.Id }));
            }
        }
Esempio n. 2
0
 private async Task <MyRef1> GetOrCreateBO1Async(ISession s, CancellationToken cancellationToken = default(CancellationToken))
 {
     if (BO1 == null)
     {
         BO1 = new MyRef1();
         await(s.SaveAsync(BO1, cancellationToken));
     }
     return(BO1);
 }
Esempio n. 3
0
 private MyRef1 GetOrCreateBO1(ISession s)
 {
     if (BO1 == null)
     {
         BO1 = new MyRef1();
         s.Save(BO1);
     }
     return(BO1);
 }
Esempio n. 4
0
        /// <summary>
        /// This setup is used in most tests in here - but not all; and we might want to
        /// twist it for special tests. Therefore, the OnSetUp mechanism is not used.
        /// </summary>
        /// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
        private async Task StandardSetUpAsync(CancellationToken cancellationToken = default(CancellationToken))
        {
            using (var session = OpenSession())
            {
                using (var tx = session.BeginTransaction())
                {
                    var i1001 = new MyRef1 {
                        Id = 1001, I1 = null, I2 = 101
                    };
                    var i1101 = new MyRef1 {
                        Id = 1101, I1 = null, I2 = 111
                    };
                    var i1002 = new MyRef1 {
                        Id = 1002, I1 = 12, I2 = 102
                    };
                    var i1003 = new MyRef1 {
                        Id = 1003, I1 = 13, I2 = 103
                    };
                    await(session.SaveAsync(i1001, cancellationToken));
                    await(session.SaveAsync(i1101, cancellationToken));
                    await(session.SaveAsync(i1002, cancellationToken));
                    await(session.SaveAsync(i1003, cancellationToken));

                    var j2001 = new MyRef2 {
                        Id = 2001, J1 = null, J2 = 201
                    };
                    var j2002 = new MyRef2 {
                        Id = 2002, J1 = 22, J2 = 202
                    };
                    var j2003 = new MyRef2 {
                        Id = 2003, J1 = null, J2 = 203
                    };
                    await(session.SaveAsync(j2001, cancellationToken));
                    await(session.SaveAsync(j2002, cancellationToken));
                    await(session.SaveAsync(j2003, cancellationToken));

                    var b10 = new MyBO {
                        Id = 10, Name = "1:1001,o1:NULL,2:NULL", BO1 = i1001, OtherBO1 = null, BO2 = null
                    };
                    var b11 = new MyBO {
                        Id = 11, Name = "1:1001,o1:1101,2:NULL", BO1 = i1001, OtherBO1 = i1101, BO2 = null
                    };
                    var b20 = new MyBO {
                        Id = 20, Name = "1:1002,o1:NULL,2:2002", BO1 = i1002, OtherBO1 = null, BO2 = j2002
                    };
                    var b30 = new MyBO {
                        Id = 30, Name = "1:NULL,o1:NULL,2:2003", BO1 = null, OtherBO1 = null, BO2 = j2003
                    };
                    await(session.SaveAsync(b10, cancellationToken));
                    await(session.SaveAsync(b11, cancellationToken));
                    await(session.SaveAsync(b20, cancellationToken));
                    await(session.SaveAsync(b30, cancellationToken));
                    await(tx.CommitAsync(cancellationToken));
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// This setup is used in most tests in here - but not all; and we might want to
        /// twist it for special tests. Therefore, the OnSetUp mechanism is not used.
        /// </summary>
        private void StandardSetUp()
        {
            using (var session = OpenSession())
            {
                using (var tx = session.BeginTransaction())
                {
                    var i1001 = new MyRef1 {
                        Id = 1001, I1 = null, I2 = 101
                    };
                    var i1101 = new MyRef1 {
                        Id = 1101, I1 = null, I2 = 111
                    };
                    var i1002 = new MyRef1 {
                        Id = 1002, I1 = 12, I2 = 102
                    };
                    var i1003 = new MyRef1 {
                        Id = 1003, I1 = 13, I2 = 103
                    };
                    session.Save(i1001);
                    session.Save(i1101);
                    session.Save(i1002);
                    session.Save(i1003);

                    var j2001 = new MyRef2 {
                        Id = 2001, J1 = null, J2 = 201
                    };
                    var j2002 = new MyRef2 {
                        Id = 2002, J1 = 22, J2 = 202
                    };
                    var j2003 = new MyRef2 {
                        Id = 2003, J1 = null, J2 = 203
                    };
                    session.Save(j2001);
                    session.Save(j2002);
                    session.Save(j2003);

                    var b10 = new MyBO {
                        Id = 10, Name = "1:1001,o1:NULL,2:NULL", BO1 = i1001, OtherBO1 = null, BO2 = null
                    };
                    var b11 = new MyBO {
                        Id = 11, Name = "1:1001,o1:1101,2:NULL", BO1 = i1001, OtherBO1 = i1101, BO2 = null
                    };
                    var b20 = new MyBO {
                        Id = 20, Name = "1:1002,o1:NULL,2:2002", BO1 = i1002, OtherBO1 = null, BO2 = j2002
                    };
                    var b30 = new MyBO {
                        Id = 30, Name = "1:NULL,o1:NULL,2:2003", BO1 = null, OtherBO1 = null, BO2 = j2003
                    };
                    session.Save(b10);
                    session.Save(b11);
                    session.Save(b20);
                    session.Save(b30);
                    tx.Commit();
                }
            }
        }
Esempio n. 6
0
        public async Task ProjectionDoesNotChangeResultAsync()
        {
            // This tests against the "projection anomaly" of (||-4) semantics.
            using (var session = OpenSession())
            {
                using (var tx = session.BeginTransaction())
                {
                    var i1001 = new MyRef1 {
                        Id = 1001, I1 = null, I2 = 101
                    };
                    var i1101 = new MyRef1 {
                        Id = 1101, I1 = null, I2 = 111
                    };
                    await(session.SaveAsync(i1001));
                    await(session.SaveAsync(i1101));

                    var b1 = new MyBO {
                        Id = 1, Name = "1:1001", BO1 = i1001
                    };
                    var b2 = new MyBO {
                        Id = 2, Name = "2:1101", BO1 = i1101
                    };
                    var b3 = new MyBO {
                        Id = 3, Name = "3:1101", BO1 = i1101
                    };
                    var b4 = new MyBO {
                        Id = 4, Name = "4:NULL", BO1 = null
                    };
                    await(session.SaveAsync(b1));
                    await(session.SaveAsync(b2));
                    await(session.SaveAsync(b3));
                    await(session.SaveAsync(b4));
                    await(tx.CommitAsync());
                }
            }

            using (var session = OpenSession())
            {
                var directResult = (await(session.Query <MyRef1>()
                                          .Where(bo => bo.I1 == null).ToListAsync())).Select(bo => bo.Id);
                var resultViaProjection = (await((from bo in session.Query <MyBO>()
                                                  where bo.BO1.I1 == null || bo.BO2.J2 == 999
                                                  select bo.BO1).Distinct().ToListAsync())).Select(bo => bo.Id);
                // With "projection anomaly", the previous Select will fail, as one "bo" is null,
                // and hence bo.Id throws a NRE.
                Assert.That(() => resultViaProjection.ToList(), Is.EquivalentTo(directResult.ToList()));
            }
        }
Esempio n. 7
0
 private MyRef1 GetOrCreateBO1(ISession s)
 {
     if (BO1 == null)
     {
         BO1 = new MyRef1();
         s.Save(BO1);
     }
     return BO1;
 }