コード例 #1
0
        public void Select_Intersect_Union_Test()
        {
            var query = MockQueryable <Entity> .Create(Database.FirstTable.Name);

            query.Intersect(MockQueryable <Entity> .Create(Database.SecondTable.Name).Union(MockQueryable <Entity> .Create(Database.ThirdTable.Name)).Where(x => x.Id <= 5), x => x.Id);
            var result = GetResult(query);

            result.ShouldImplement <IEnumerable <Entity> >();
            var results = ((IEnumerable <Entity>)result).ToList();

            results.Count().ShouldEqual(5);
            results.All(x => x.Id <= 5).ShouldEqual(true);
        }
コード例 #2
0
        public void should_not_return_null_comparison_values()
        {
            Database.ExecuteNonQuery("UPDATE [{0}] SET name=NULL WHERE id > 5", Database.FirstTable.Name);
            var query = MockQueryable <Entity> .Create(Database.FirstTable.Name);

            query.Where(x => x.Name != "ed");
            var result = GetResult(query);

            result.ShouldImplement <IEnumerable <Entity> >();
            var results = ((IEnumerable <Entity>)result).ToList();

            results.Count().ShouldEqual(10);
            results.Count(x => x.Name == "oh hai").ShouldEqual(5);
            results.Count(x => x.Name == null).ShouldEqual(5);
        }
コード例 #3
0
        public void Select_First_Or_Default_Test()
        {
            var query = MockQueryable <Entity> .Create(Database.FirstTable.Name);

            query.FirstOrDefault();
            var result = GetResult(query);

            result.ShouldBeType(typeof(Entity));
            var entity = (Entity)result;

            entity.Name.Length.ShouldBeGreaterThan(3);
            entity.Id.ShouldBeGreaterThan(0);
            entity.Values.Count.ShouldBeGreaterThan(2);
            ((string)entity.Values["type"]).Trim().ShouldEqual("U");
            ((DateTime)entity.Values["create_date"]).ShouldBeGreaterThan(DateTime.MinValue);
        }
コード例 #4
0
        public void should_return_single_with_filter()
        {
            var query = MockQueryable <Entity> .Create(Database.FirstTable.Name);

            query.Single(x => x.Id == 1);
            var result = GetResult(query);

            result.ShouldBeType(typeof(Entity));
            var entity = (Entity)result;

            entity.Name.Length.ShouldBeGreaterThan(3);
            entity.Id.ShouldBeGreaterThan(0);
            entity.Values.Count.ShouldBeGreaterThan(2);
            ((string)entity.Values["type"]).Trim().ShouldEqual("U");
            ((DateTime)entity.Values["create_date"]).ShouldBeGreaterThan(DateTime.MinValue);
        }
コード例 #5
0
        public void Select_Test()
        {
            var query = MockQueryable <Entity> .Create(Database.FirstTable.Name);

            var result = GetResult(query);

            result.ShouldImplement <IEnumerable <Entity> >();
            var results = ((IEnumerable <Entity>)result).ToList();

            results.Count().ShouldBeGreaterThan(2);
            results.All(x => x.Name.Length > 3).ShouldEqual(true);
            results.All(x => x.Id > 0).ShouldEqual(true);
            results.First().Values.Count.ShouldBeGreaterThan(2);
            ((string)results.First().Values["type"]).Trim().ShouldEqual("U");
            ((DateTime)results.First().Values["create_date"]).ShouldBeGreaterThan(DateTime.MinValue);
        }
コード例 #6
0
        public void Select_Randomize_Test()
        {
            var query = MockQueryable <Entity> .Create(Database.FirstTable.Name);

            query.Randomize();
            var result1 = GetResult(query);
            var result2 = GetResult(query);

            result1.ShouldImplement <IEnumerable <Entity> >();
            result2.ShouldImplement <IEnumerable <Entity> >();
            var results1 = (((IEnumerable <Entity>)result1).ToList()).ToList();
            var results2 = (((IEnumerable <Entity>)result2).ToList()).ToList();

            results1.Count().ShouldEqual(10);
            results2.Count().ShouldEqual(10);
            results1.Zip(results2, (x, y) => x.Id == y.Id).Any(x => !x).ShouldEqual(true);
        }
コード例 #7
0
        public void should_return_duplicates_by_double_sort_descending()
        {
            Database.ExecuteNonQuery("UPDATE [{0}] SET name='Tom', age=84 WHERE id = 1", Database.FirstTable.Name);
            Database.ExecuteNonQuery("UPDATE [{0}] SET name='Tom', age=84 WHERE id = 2", Database.FirstTable.Name);
            Database.ExecuteNonQuery("UPDATE [{0}] SET name='Tom', age=42 WHERE id = 3", Database.FirstTable.Name);
            Database.ExecuteNonQuery("UPDATE [{0}] SET name='Tom', age=42 WHERE id = 4", Database.FirstTable.Name);
            Database.ExecuteNonQuery("UPDATE [{0}] SET name='Dick', age=83 WHERE id = 5", Database.FirstTable.Name);
            Database.ExecuteNonQuery("UPDATE [{0}] SET name='Dick', age=43 WHERE id = 6", Database.FirstTable.Name);
            Database.ExecuteNonQuery("UPDATE [{0}] SET name='Harry', age=85 WHERE id = 7", Database.FirstTable.Name);
            Database.ExecuteNonQuery("UPDATE [{0}] SET name='Harry', age=85 WHERE id = 8", Database.FirstTable.Name);
            Database.ExecuteNonQuery("UPDATE [{0}] SET name='Harry', age=48 WHERE id = 9", Database.FirstTable.Name);
            Database.ExecuteNonQuery("UPDATE [{0}] SET name='Harry', age=48 WHERE id = 10", Database.FirstTable.Name);
            var query = MockQueryable <Entity> .Create(Database.FirstTable.Name);

            query.Duplicates(x => x.Name, x => x.Age, Order.Descending, x => x.Id, Order.Ascending);
            var result = GetResult(query);

            result.ShouldImplement <IEnumerable <Entity> >();
            var results = ((IEnumerable <Entity>)result).ToList();

            results.Count().ShouldEqual(7);
            results.Count(x => x.Name == "Dick").ShouldEqual(1);
            var subResults = results.Where(x => x.Name == "Tom").ToList();

            subResults.Count().ShouldEqual(3);
            subResults[0].Age.ShouldEqual(84);
            subResults[0].Id.ShouldEqual(2);
            subResults[1].Age.ShouldEqual(42);
            subResults[1].Id.ShouldEqual(3);
            subResults[2].Age.ShouldEqual(42);
            subResults[2].Id.ShouldEqual(4);
            subResults = results.Where(x => x.Name == "Harry").ToList();
            subResults.Count().ShouldEqual(3);
            subResults[0].Age.ShouldEqual(85);
            subResults[0].Id.ShouldEqual(8);
            subResults[1].Age.ShouldEqual(48);
            subResults[1].Id.ShouldEqual(9);
            subResults[2].Age.ShouldEqual(48);
            subResults[2].Id.ShouldEqual(10);
        }