Esempio n. 1
0
        private void getData(ITestDataContext db, IEnumerable <int?> d, IEnumerable <int?> compareWith)
        {
            var r1 = db.GrandChild
                     .Where(x => d.Contains(x.ParentID))
                     .GroupBy(x => x.ChildID, x => x.GrandChildID)
                     .ToList();

            foreach (var group in r1)
            {
                Assert.That(compareWith.Any(x => group.Contains(x)), Is.True);
            }
        }
Esempio n. 2
0
        IQueryable <MyObject> GetData(ITestDataContext db, int id)
        {
            var q =
                from p in db.Parent
                join c in db.Child on p.ParentID equals c.ChildID
                where p.ParentID == id && c.ChildID > 0
                select new MyObject {
                Parent = p, Child = c
            };

            return(q);
        }
Esempio n. 3
0
        static DateTime DateTimeParams(ITestDataContext db, DateTime?dateTime)
        {
            var q =
                from t in db.Types2
                where t.DateTimeValue > dateTime
                select new
            {
                t.DateTimeValue,
                dateTime.Value
            };

            return(q.First().Value);
        }
Esempio n. 4
0
        private void InsertData(ITestDataContext db)
        {
            var eye = new Eye
            {
                Id = 1,
                Xy = "Hallo"
            };

            var dog = new Dog
            {
                Id            = 1,
                Discriminator = "Dog",
                EyeId         = 1,
                Name          = "FirstDog",
                DogName       = new Name {
                    First = "a", Second = "b"
                },
                AnimalType  = AnimalType.Big,
                AnimalType2 = AnimalType2.Big
            };

            var wildAnimal = new WildAnimal
            {
                Id            = 2,
                Discriminator = "WildAnimal",
                Name          = "WildAnimal",
                AnimalType    = AnimalType.Big,
                AnimalType2   = AnimalType2.Big
            };

            var test = new Test
            {
                Id           = 1,
                TestAnimalId = null
            };

            var test2 = new Test
            {
                Id           = 2,
                TestAnimalId = 1
            };

            using (new DisableLogging())
            {
                db.Insert(eye);
                db.Insert(dog);
                db.Insert(wildAnimal);
                db.Insert(test);
                db.Insert(test2);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Value is not used and shouldn't produce memory leaks.
        /// This one used to detect situations when testing approach in broken in general due to runtime/GC behavior
        /// changes.
        /// </summary>
        private static void Unused(ITestDataContext db, byte[] value, int calls)
        {
            var query = db.Types.Where(_ => _.ID == 256);

            while (calls > 0)
            {
                var result = query.ToList();

                Assert.AreEqual(1, result.Count);
                Assert.AreEqual(256, result[0].ID);

                calls--;
            }
        }
Esempio n. 6
0
        private static void SelectOrderBy(ITestDataContext db, byte[] value, int calls)
        {
            var query = db.Types.Where(_ => _.ID == 256).OrderBy(_ => _.BinaryValue == value);

            while (calls > 0)
            {
                var result = query.ToList();

                Assert.AreEqual(1, result.Count);
                Assert.AreEqual(256, result[0].ID);

                calls--;
            }
        }
Esempio n. 7
0
        private static void NonLinqInsert(ITestDataContext db, byte[] value, int calls)
        {
            db.Insert(new LinqDataTypesWithPK()
            {
                ID = 10256, BinaryValue = value, DateTimeValue = Date
            });
            var result = db.Types.Where(_ => _.ID == 10256).ToList();

            db.Types.Where(_ => _.ID == 10256).Delete();

            Assert.AreEqual(1, result.Count);
            Assert.AreEqual(10256, result[0].ID);
            Assert.True(value.SequenceEqual(result[0].BinaryValue.ToArray()));
        }
Esempio n. 8
0
        public TestDataRepository(ITestDataContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            _context  = context;
            _testData = context.GetDbSet <TestData>();
            if (_testData == null)
            {
                throw new ArgumentException("Null DbSet retrieved from context");
            }
        }
Esempio n. 9
0
        static IQueryable <B> GenerateQuery(ITestDataContext db, DateTime?asOfDate = null)
        {
            var q =
                from identifier in db.GetTable <A>()
                where identifier.DateTime <= asOfDate
                select identifier;

            return
                (from a in db.GetTable <A>()
                 select new B
            {
                ID = a.ID,
                Name = q.Select(identifier => identifier.Value).FirstOrDefault()
            });
        }
Esempio n. 10
0
        protected IEnumerable <LinqDataTypes2> AdjustExpectedData(ITestDataContext db, IEnumerable <LinqDataTypes2> data)
        {
            if (db.ContextID == "MySql" || db.ContextID == "MySql.LinqService")
            {
                // MySql versions prior to 5.6.4 do not store fractional seconds so we need to trim
                // them from expected data too
                var version = db.Types.Select(_ => MySqlVersion()).First();
                var match   = new Regex(@"^\d+\.\d+.\d+").Match(version);
                if (match.Success)
                {
                    var versionParts = match.Value.Split('.').Select(_ => int.Parse(_)).ToArray();

                    if (versionParts[0] * 10000 + versionParts[1] * 100 + versionParts[2] < 50604)
                    {
                        var adjusted = new List <LinqDataTypes2>();
                        foreach (var record in data)
                        {
                            var copy = new LinqDataTypes2()
                            {
                                ID             = record.ID,
                                MoneyValue     = record.MoneyValue,
                                DateTimeValue  = record.DateTimeValue,
                                DateTimeValue2 = record.DateTimeValue2,
                                BoolValue      = record.BoolValue,
                                GuidValue      = record.GuidValue,
                                SmallIntValue  = record.SmallIntValue,
                                IntValue       = record.IntValue,
                                BigIntValue    = record.BigIntValue,
                                StringValue    = record.StringValue
                            };

                            if (copy.DateTimeValue != null)
                            {
                                copy.DateTimeValue = copy.DateTimeValue.Value.AddMilliseconds(-copy.DateTimeValue.Value.Millisecond);
                            }

                            adjusted.Add(copy);
                        }

                        return(adjusted);
                    }
                }
            }

            return(data);
        }
Esempio n. 11
0
        private void InsertData(ITestDataContext db)
        {
            var eye = new Eye
            {
                Id = 1,
                Xy = "Hallo"
            };

            var dog = new Dog
            {
                Id            = 1,
                Discriminator = "Dog",
                EyeId         = 1,
                Name          = "FirstDog",
                DogName       = new Name {
                    First = "a", Second = "b"
                },
                AnimalType  = AnimalType.Big,
                AnimalType2 = AnimalType2.Big
            };

            var test = new Test
            {
                Id           = 1,
                TestAnimalId = null
            };

            var test2 = new Test
            {
                Id           = 2,
                TestAnimalId = 1
            };

            db.DropTable <Animal>(throwExceptionIfNotExists: false);
            db.DropTable <Eye>(throwExceptionIfNotExists: false);
            db.DropTable <Test>(throwExceptionIfNotExists: false);
            db.CreateTable <Animal>();
            db.CreateTable <Eye>();
            db.CreateTable <Test>();

            db.Insert(eye);
            db.Insert(dog);
            db.Insert(test);
            db.Insert(test2);
        }
Esempio n. 12
0
        void ProcessItem(ITestDataContext db, int id)
        {
            var hashQuery1 = Parent.Where(t => t.ParentID == id);

            var groups1 = Child
                          .Where(p => hashQuery1.Any(e => e.ParentID == p.ParentID))
                          .GroupBy(e => e.ParentID)
                          .Select(g => g.Key);

            var hashQuery2 = db.Parent.Where(t => t.ParentID == id);

            var groups2 = db.Child
                          .Where(p => hashQuery2.Any(e => e.ParentID == p.ParentID))
                          .GroupBy(e => e.ParentID)
                          .Select(g => g.Key);

            AreEqual(groups1, groups2);
        }
Esempio n. 13
0
        private static void DeleteWhere(ITestDataContext db, byte[] value, int calls)
        {
            var query = db.Types.Where(_ => _.BinaryValue == value);

            while (calls > 0)
            {
                query.Delete();
                var result = db.Types.Where(_ => _.ID == 256).ToList();

                Assert.AreEqual(0, result.Count);

                calls--;
                db.Types.Insert(() => new LinqDataTypes()
                {
                    ID = 256, BinaryValue = value
                });
            }
        }
Esempio n. 14
0
        private static void UpdateWhere(ITestDataContext db, byte[] value, int calls)
        {
            var query = db.Types.Where(_ => _.BinaryValue == value);

            var expected = true;

            while (calls > 0)
            {
                query.Set(_ => _.BoolValue, _ => !_.BoolValue).Update();
                var result = db.Types.Where(_ => _.ID == 256).ToList();

                Assert.AreEqual(1, result.Count);
                Assert.AreEqual(256, result[0].ID);
                Assert.AreEqual(expected, result[0].BoolValue);

                calls--;
                expected = !expected;
            }
        }
Esempio n. 15
0
        private static void NonLinqDelete(ITestDataContext db, byte[] value, int calls)
        {
            while (calls > 0)
            {
                db.Delete(new LinqDataTypesWithPK()
                {
                    ID = 256, BinaryValue = value, DateTimeValue = Date
                });
                var result = db.Types.Where(_ => _.ID == 256).ToList();

                Assert.AreEqual(0, result.Count);

                calls--;
                db.Types.Insert(() => new LinqDataTypes()
                {
                    ID = 256, BinaryValue = value
                });
            }
        }
Esempio n. 16
0
        public void SubQuery2(ITestDataContext db)
        {
            var q1 = from p in db.Person where p.ID == 1 || p.ID == 2 select p;
            var q2 = from p in db.Person where !(p.ID == 2) select p;

            var q =
                from p1 in q1
                from p2 in q2
                where p1.ID == p2.ID
                select new Person {
                ID = p1.ID, FirstName = p2.FirstName
            };

            foreach (var person in q)
            {
                Assert.AreEqual(1, person.ID);
                Assert.AreEqual("John", person.FirstName);
            }
        }
Esempio n. 17
0
        private static void InsertInsert(ITestDataContext db, byte[] value, int calls)
        {
            var query = db.Types.Where(_ => _.ID == 256);

            while (calls > 0)
            {
                Assert.AreEqual(1, query.Delete());
                db.Types.Insert(() => new LinqDataTypes()
                {
                    ID = 256, BinaryValue = value
                });
                var result = query.ToList();

                Assert.AreEqual(1, result.Count);
                Assert.AreEqual(256, result[0].ID);
                Assert.True(value.SequenceEqual(result[0].BinaryValue.ToArray()));

                calls--;
            }
        }
Esempio n. 18
0
        private static string GetSchemaName(string context, ITestDataContext db)
        {
            switch (context)
            {
            case ProviderName.SapHana:
            case ProviderName.Informix:
            case ProviderName.Oracle:
            case ProviderName.OracleNative:
            case ProviderName.OracleManaged:
            case ProviderName.PostgreSQL:
            case ProviderName.DB2:
            case ProviderName.Sybase:
            case ProviderName.SqlServer2000:
            case ProviderName.SqlServer2005:
            case ProviderName.SqlServer2008:
            case ProviderName.SqlServer2012:
            case ProviderName.SqlServer2014:
            case TestProvName.SqlAzure:
                return(db.Types.Select(_ => SchemaName()).First());
            }

            return("UNUSED_SCHEMA");
        }
Esempio n. 19
0
        private static void UpdateSet(ITestDataContext db, byte[] value, int calls)
        {
            var query = db.Types.Where(_ => _.ID == 256);

            while (calls > 0)
            {
                query.Set(_ => _.BinaryValue, _ => null).Update();
                var result = query.ToList();

                Assert.AreEqual(1, result.Count);
                Assert.AreEqual(256, result[0].ID);
                Assert.IsNull(result[0].BinaryValue);

                query.Set(_ => _.BinaryValue, _ => value).Update();
                result = query.ToList();

                Assert.AreEqual(1, result.Count);
                Assert.AreEqual(256, result[0].ID);
                Assert.True(value.SequenceEqual(result[0].BinaryValue.ToArray()));

                calls--;
            }
        }
Esempio n. 20
0
		IQueryable<Person> GetPersonQuery(ITestDataContext db, int id)
		{
			return from p in db.Person where p.ID == id select new Person { ID = p.ID + 1, FirstName = p.FirstName };
		}
Esempio n. 21
0
		protected GenericQueryBase(ITestDataContext ds)
		{
			m_ds = new IdlPatientSource(ds);
		}
Esempio n. 22
0
 private static void Delete(ITestDataContext db)
 {
     db.Types2.Delete(_ => _.ID != 100500);
 }
Esempio n. 23
0
		static int Count5(ITestDataContext db, Parent p, int n)
		{
			return (_count5Expression ?? (_count5Expression = Count5Expression().Compile()))(db, p, n);
		}
Esempio n. 24
0
 static int Count5(ITestDataContext db, Parent p, int n)
 {
     return((_count5Expression ?? (_count5Expression = Count5Expression().Compile()))(db, p, n));
 }
Esempio n. 25
0
			public GenericConcatQuery1(ITestDataContext ds, object[] args)
				: base(ds)
			{
				@p1 = (String)args[0];
				@p2 = (Int32) args[1];
			}
Esempio n. 26
0
			public GenericConcatJoinOrderQuery1(ITestDataContext ds, object[] args)
				: base(ds)
			{
				@p1 = (System.String)args[0];
				@p2 = (System.Int32)args[1];
			}
Esempio n. 27
0
		void ProcessItem(ITestDataContext db, int id)
		{
			var hashQuery1 = Parent.Where(t => t.ParentID == id);

			var groups1 = Child
				.Where(p => hashQuery1.Any(e => e.ParentID == p.ParentID))
				.GroupBy(e => e.ParentID)
				.Select(g => g.Key);

			var hashQuery2 = db.Parent.Where(t => t.ParentID == id);

			var groups2 = db.Child
				.Where(p => hashQuery2.Any(e => e.ParentID == p.ParentID))
				.GroupBy(e => e.ParentID)
				.Select(g => g.Key);

			AreEqual(groups1, groups2);
		}
Esempio n. 28
0
			public TestDataSource(ITestDataContext db)
			{
				m_db = db;
			}
Esempio n. 29
0
 private static void UpdateObject(ITestDataContext db)
 {
     db.Update(new LinqDataTypes2());
 }
Esempio n. 30
0
 private static void InsertOrUpdateObject(ITestDataContext db)
 {
     db.InsertOrReplace(new LinqDataTypes2());
 }
Esempio n. 31
0
 private static void InsertWithIdentityObject(ITestDataContext db)
 {
     db.InsertWithIdentity(new LinqDataTypes2());
 }
Esempio n. 32
0
 private static void InsertObject(ITestDataContext db)
 {
     db.Insert(new LinqDataTypes2());
 }
Esempio n. 33
0
		static IQueryable<Person> TestDirectParam(ITestDataContext db, int id)
		{
			var name = "John";
			return from p in db.Person where p.ID == id && p.FirstName == name select p;
		}
Esempio n. 34
0
		public void SubQuery2(ITestDataContext db)
		{
			var q1 = from p in db.Person where p.ID == 1 || p.ID == 2 select p;
			var q2 = from p in db.Person where !(p.ID == 2) select p;

			var q = 
				from p1 in q1
				from p2 in q2
				where p1.ID == p2.ID
				select new Person { ID = p1.ID, FirstName = p2.FirstName };

			foreach (var person in q)
			{
				Assert.AreEqual(1,      person.ID);
				Assert.AreEqual("John", person.FirstName);
			}
		}
Esempio n. 35
0
 static void TakeParam(ITestDataContext db, int n)
 {
     Assert.AreEqual(n, (from ch in db.Child select ch).Take(n).ToList().Count);
 }
Esempio n. 36
0
		public IdlPatientSource(ITestDataContext dc)
		{
			m_dc = dc;
		}
Esempio n. 37
0
			public Cleaner(ITestDataContext db)
			{
				_db = db;
				Clean();
			}
Esempio n. 38
0
 static IQueryable <Parent> GetParent(ITestDataContext db, Child ch)
 {
     throw new InvalidOperationException();
 }
Esempio n. 39
0
        static void GetData(ITestDataContext db, IEnumerable<int?> d)
        {
            var r1 = db.GrandChild
                .Where(x => d.Contains(x.ParentID))
                .ToList();

            foreach (var g in r1)
            {
                Assert.AreEqual(d.First().Value, g.ParentID);
            }
        }
Esempio n. 40
0
		static IQueryable<Parent> GetParent(ITestDataContext db, Child ch)
		{
			throw new InvalidOperationException();
		}
Esempio n. 41
0
		public static IQueryable<Parent> Filter(ITestDataContext db, int date)
		{
			throw new NotImplementedException();
		}
Esempio n. 42
0
		static DateTime DateTimeParams(ITestDataContext db, DateTime? dateTime)
		{
			var q =
				from t in db.Types2
				where t.DateTimeValue > dateTime
				select new
					{
						t.DateTimeValue,
						dateTime.Value
					};

			return q.First().Value;
		}
Esempio n. 43
0
 private static void Select(ITestDataContext db)
 {
     db.Types2.Where(_ => _.ID == 100500).ToList();
 }
Esempio n. 44
0
 IQueryable <Person> GetPersonQuery(ITestDataContext db, int id)
 {
     return(from p in db.Person where p.ID == id select new Person {
         ID = p.ID + 1, FirstName = p.FirstName
     });
 }
Esempio n. 45
0
 public static IQueryable <Parent> Filter(ITestDataContext db, int date)
 {
     throw new NotImplementedException();
 }
Esempio n. 46
0
        void SkipTake6(ITestDataContext db, bool doSkip)
        {
            var q1 = from g in db.GrandChild select g;

            if (doSkip)
                q1 = q1.Skip(12);
            q1 = q1.Take(3);

            var q2 =
                from c in db.Child
                from p in q1
                where c.ParentID == p.ParentID
                select c;

            var q3 = from g in GrandChild select g;

            if (doSkip)
                q3 = q3.Skip(12);
            q3 = q3.Take(3);

            var q4 =
                from c in Child
                from p in q3
                where c.ParentID == p.ParentID
                select c;

            AreEqual(q4, q2);
        }
Esempio n. 47
0
 static void TakeParam(ITestDataContext db, int n)
 {
     Assert.AreEqual(n, (from ch in db.Child select ch).Take(n).ToList().Count);
 }
Esempio n. 48
0
			public Test TestClosure(ITestDataContext db)
			{
				return db.Person.Select(_ => new Entity { TestField = this }).First().TestField;
			}
Esempio n. 49
0
 void TestContains(ITestDataContext db, Parent1 parent)
 {
     Assert.AreEqual(
            Parent1.Where(p => p.ParentID == 1).Contains(parent),
         db.Parent1.Where(p => p.ParentID == 1).Contains(parent));
 }