예제 #1
0
        public void DisalowFilterClause_QueryWithFilter_ResultsCountShouldBeDefaultToTake(string queryString)
        {
            using (var context = new AutoQueryableDbContext())
            {
                _profile.DisAllowedClauses = ClauseType.Filter;
                _queryStringAccessor.SetQueryString(queryString);

                DataInitializer.InitializeSeed(context);

                var query = context.Product.AutoQueryable(_autoQueryableContext) as IQueryable <object>;

                query.Count().Should().Be(DataInitializer.DefaultToTakeCount);
            }
        }
예제 #2
0
        public void DisalowSkipClause_QueryWithSkip_FirstResultIdShouldBe1(string queryString)
        {
            using (var context = new AutoQueryableDbContext())
            {
                _profile.DisAllowedClauses = ClauseType.Skip;
                _queryStringAccessor.SetQueryString(queryString);

                DataInitializer.InitializeSeed(context);

                var query = context.Product.AutoQueryable(_autoQueryableContext) as IQueryable <object>;
                var first = query.First();
                first.GetType().GetProperty("ProductId", BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.Public).GetValue(first).As <int>().Should().Be(1);;
            }
        }
예제 #3
0
        public void DateYearEquals2010()
        {
            using (var context = new AutoQueryableDbContext())
            {
                _queryStringAccessor.SetQueryString("SellStartDate:Year=2010");

                DataInitializer.InitializeSeed(context);
                DataInitializer.AddDateTimeSeeds(context);
                var query = context.Product.AutoQueryable(_autoQueryableContext)  as IQueryable <object>;


                query.Count().Should().Be(1);
            }
        }
예제 #4
0
        public void IdEquals5()
        {
            using (var context = new AutoQueryableDbContext())
            {
                _queryStringAccessor.SetQueryString("productid=5");

                DataInitializer.InitializeSeed(context);
                var query = context.Product.AutoQueryable(_autoQueryableContext)  as IQueryable <object>;
                query.Count().Should().Be(1);
                var first = query.First();
                var id    = first.GetType().GetProperty("ProductId").GetValue(first);
                id.Should().Be(5);
            }
        }
예제 #5
0
        public void NotEndsWithIgnoreCase()
        {
            using (var context = new AutoQueryableDbContext())
            {
                const string nameCheck = "dUcT 100";
                _queryStringAccessor.SetQueryString($"nameEndsWith:i!={nameCheck}");

                DataInitializer.InitializeSeed(context);
                var query = context.Product.AutoQueryable(_autoQueryableContext)  as IQueryable <object>;
                query.Should().OnlyContain(product =>
                                           product.GetType().GetProperty("Name").GetValue(product) == null ||
                                           !product.GetType().GetProperty("Name").GetValue(product).ToString().EndsWith(nameCheck, StringComparison.OrdinalIgnoreCase));
            }
        }
예제 #6
0
 public void SelectOrderBySellStartDateDesc()
 {
     using (AutoQueryableContext context = new AutoQueryableContext())
     {
         DataInitializer.InitializeSeed(context);
         var      query       = (context.Product.AutoQueryable("select=SellStartDate&orderbydesc=SellStartDate") as IEnumerable <dynamic>).ToList();
         DateTime currentDate = DateTime.MaxValue;
         foreach (var product in query)
         {
             var date = product.GetType().GetProperty("SellStartDate").GetValue(product);
             Assert.IsTrue(date < currentDate);
             currentDate = date;
         }
     }
 }
예제 #7
0
        public void DateEquals()
        {
            using (var context = new AutoQueryableDbContext())
            {
                _queryStringAccessor.SetQueryString($"SellStartDate={DateTime.Today.AddHours(8 * 2):o}");

                DataInitializer.InitializeSeed(context);
                var query = context.Product.AutoQueryable(_autoQueryableContext)  as IQueryable <object>;

                query.Count().Should().Be(1);
                var first = query.First();
                var id    = int.Parse(first.GetType().GetProperty("ProductId").GetValue(first).ToString());
                id.Should().Be(3);
            }
        }
예제 #8
0
        public void DisalowSelectClause_QueryWithSelect_ResultsShouldCountainsAllProperties(string queryString)
        {
            using (var context = new AutoQueryableDbContext())
            {
                _profile.DisAllowedClauses = ClauseType.Select;
                _queryStringAccessor.SetQueryString(queryString);

                DataInitializer.InitializeSeed(context);

                var query      = context.Product.AutoQueryable(_autoQueryableContext) as IQueryable <object>;
                var properties = query.First().GetType().GetProperties();

                properties.Length.Should().Be(_baseProductPropertiesCount);
            }
        }
예제 #9
0
        public void IdEquals3Or4Or5()
        {
            using (AutoQueryableContext context = new AutoQueryableContext())
            {
                DataInitializer.InitializeSeed(context);
                var query = (context.Product.AutoQueryable("productid=3,4,5") as IEnumerable <dynamic>).ToList();
                Assert.AreEqual(query.Count(), 3);

                foreach (var product in query)
                {
                    int id = product.GetType().GetProperty("ProductId").GetValue(product);
                    Assert.IsTrue(id == 3 || id == 4 || id == 5);
                }
            }
        }
예제 #10
0
        public void RowGuidEqualsGuidString()
        {
            using (var context = new AutoQueryableDbContext())
            {
                _queryStringAccessor.SetQueryString($"rowguid={DataInitializer.GuidString}");

                DataInitializer.InitializeSeed(context);
                var query = context.Product.AutoQueryable(_autoQueryableContext)  as IQueryable <object>;

                query.Count().Should().Be(DataInitializer.ProductSampleCount);
                var first = query.First();
                var id    = first.GetType().GetProperty("Rowguid").GetValue(first);
                id.Should().Be(Guid.Parse(DataInitializer.GuidString));
            }
        }
예제 #11
0
        public void SelectAllProductsWithUnselectableProperties()
        {
            using (AutoQueryableContext context = new AutoQueryableContext())
            {
                DataInitializer.InitializeSeed(context);
                var query = context.Product.AutoQueryable("", new AutoQueryableProfile {
                    UnselectableProperties = new[] { "productid", "rowguid" }
                }) as IQueryable <object>;
                PropertyInfo[] properties = query.First().GetType().GetProperties();

                Assert.IsFalse(properties.Any(p => p.Name == "ProductId"));
                Assert.IsFalse(properties.Any(p => p.Name == "Rowguid"));

                Assert.AreEqual(query.Count(), DataInitializer.ProductSampleCount);
            }
        }
예제 #12
0
        public void SelectAllProductsWithNameAndColorIgnoreCase()
        {
            using (AutoQueryableContext context = new AutoQueryableContext())
            {
                DataInitializer.InitializeSeed(context);
                var            query      = context.Product.AutoQueryable("select=Name,COLOR") as IQueryable <object>;
                PropertyInfo[] properties = query.First().GetType().GetProperties();

                Assert.AreEqual(properties.Count(), 2);

                Assert.IsTrue(properties.Any(p => p.Name == "Name"));
                Assert.IsTrue(properties.Any(p => p.Name == "COLOR"));

                Assert.AreEqual(query.Count(), DataInitializer.ProductSampleCount);
            }
        }
예제 #13
0
 public void CreateAqWithUseBaseTypeAndUnSelectable_Query_CheckIfResultsDoesNotContainsUnselectabe()
 {
     using (var context = new AutoQueryableDbContext())
     {
         _queryStringAccessor.SetQueryString("namecontains:i=product");
         DataInitializer.InitializeSeed(context);
         _profile.UseBaseType            = true;
         _profile.UnselectableProperties = typeof(Product).GetProperties().Where(p => p.Name != "Name")
                                           .Select(p => p.Name).ToArray();
         var query    = context.Product.AutoQueryable(_autoQueryableContext) as IQueryable <object>;
         var products = (query as IEnumerable <Product>)?.ToList();
         products.Should().NotBeNull();
         products.Should().NotContain(p => p.Color != null || p.ProductId != 0);
         products.Count().Should().Be(DataInitializer.DefaultToTakeCount);
     }
 }
예제 #14
0
        public async Task PagedResultTest()
        {
            using (var context = new AutoQueryableDbContext())
            {
                _queryStringAccessor.SetQueryString("page=1");
                _profile.UseBaseType = true;

                DataInitializer.InitializeSeed(context);
                var query = context.Product.AutoQueryable(_autoQueryableContext) as IQueryable <Product>;
                //var pagedResult = await query.ToPagedResultAsync(_autoQueryableContext);

                //pagedResult.RowCount.Should().Be(_profile.DefaultToTake);
                //pagedResult.TotalCount.Should().Be(await context.Product.CountAsync());
                //pagedResult.Result.Count.Should().Be(_profile.DefaultToTake);
            }
        }
예제 #15
0
 public void SellStartDateEqualsTodayOrTodayPlus8HourJsonFormatted()
 {
     using (AutoQueryableContext context = new AutoQueryableContext())
     {
         DataInitializer.InitializeSeed(context);
         string todayJsonFormated          = DateTime.Today.ToString("yyyy-MM-dd");
         string todayPlus8HourJsonFormated = DateTime.Today.AddHours(8).ToString("yyyy-MM-ddThh:mm:ss");
         var    query = (context.Product.AutoQueryable($"SellStartDate={todayJsonFormated},{todayPlus8HourJsonFormated}") as IEnumerable <dynamic>).ToList();
         Assert.AreEqual(2, query.Count);
         foreach (var product in query)
         {
             DateTime sellStartDate = product.GetType().GetProperty("SellStartDate").GetValue(product);
             Assert.IsTrue(sellStartDate == DateTime.Today || sellStartDate == DateTime.Today.AddHours(8));
         }
     }
 }
예제 #16
0
        public void SellStartDateEqualsTodayJsonFormatted()
        {
            using (var context = new AutoQueryableDbContext())
            {
                var todayJsonFormated = DateTime.Today.ToString("yyyy-MM-dd");
                _queryStringAccessor.SetQueryString($"SellStartDate={todayJsonFormated}");

                DataInitializer.InitializeSeed(context);
                var query = context.Product.AutoQueryable(_autoQueryableContext) as IQueryable <object>;

                query.Count().Should().Be(1);
                var first         = query.First();
                var sellStartDate = DateTime.Parse(first.GetType().GetProperty("SellStartDate").GetValue(first).ToString());
                sellStartDate.Should().Be(DateTime.Today);
            }
        }
예제 #17
0
        public void SelectAllProductsWithUnselectableProperties()
        {
            using (var context = new AutoQueryableDbContext())
            {
                _profile.UnselectableProperties = new[] { "productid", "rowguid" };

                DataInitializer.InitializeSeed(context);
                var query      = context.Product.AutoQueryable(_autoQueryableContext) as IQueryable <object>;
                var properties = query.First().GetType().GetProperties();

                properties.Should().NotContain(p => p.Name == "ProductId");
                properties.Should().NotContain(p => p.Name == "Rowguid");

                query.Count().Should().Be(DataInitializer.DefaultToTakeCount);
            }
        }
예제 #18
0
        public void SelectAllProductsWithDtoProjection()
        {
            using (var context = new AutoQueryableDbContext())
            {
                DataInitializer.InitializeSeed(context);
                var query = context.Product.Select(p => new ProductDto
                {
                    Name = p.Name
                }).AutoQueryable(_autoQueryableContext) as IQueryable <object>;
                var properties = query.First().GetType().GetProperties();
                properties.Length.Should().Be(1);

                properties.Should().Contain(p => p.Name == "Name");

                query.Count().Should().Be(DataInitializer.DefaultToTakeCount);
            }
        }
예제 #19
0
        public void SelectOrderBySellStartDateDesc()
        {
            using (var context = new AutoQueryableDbContext())
            {
                _queryStringAccessor.SetQueryString("select=SellStartDate&orderby=-SellStartDate");

                DataInitializer.InitializeSeed(context);
                var query       = context.Product.AutoQueryable(_autoQueryableContext).ToList();
                var currentDate = DateTime.MaxValue;
                foreach (var product in query)
                {
                    var date = (DateTime)product.GetType().GetProperty("SellStartDate").GetValue(product);
                    date.Should().BeBefore(currentDate);
                    currentDate = date;
                }
            }
        }
예제 #20
0
        public void SelectSkipAndTake50()
        {
            using (var context = new AutoQueryableDbContext())
            {
                _queryStringAccessor.SetQueryString("select=ProductId,name,color&skip=50&take=50");

                DataInitializer.InitializeSeed(context);
                var query = context.Product.AutoQueryable(_autoQueryableContext) as IQueryable <object>;

                var first = query.First();
                var type  = first.GetType();
                var value = int.Parse(type.GetProperty("ProductId").GetValue(first).ToString());

                value.Should().Be(51);
                query.Count().Should().Be(50);
            }
        }
예제 #21
0
        public void SelectAllProductsWithSelectProjection3()
        {
            using (AutoQueryableContext context = new AutoQueryableContext())
            {
                DataInitializer.InitializeSeed(context);
                var query = context.Product.AutoQueryable("select=SalesOrderDetail.Product.ProductId") as IQueryable <object>;

                PropertyInfo[] properties = query.First().GetType().GetProperties();
                Assert.AreEqual(properties.Count(), 1);

                var salesOrderDetailProperty = properties.FirstOrDefault(p => p.Name == "SalesOrderDetail").PropertyType.GenericTypeArguments[0];
                var productProperty          = salesOrderDetailProperty.GetProperties().FirstOrDefault(x => x.Name == "Product");
                Assert.IsNotNull(productProperty);
                Assert.IsTrue(productProperty.PropertyType.GetProperties().Any(x => x.Name == "ProductId"));
                Assert.AreEqual(query.Count(), DataInitializer.ProductSampleCount);
            }
        }
예제 #22
0
        public void SelectAllProductsWithDtoProjection()
        {
            using (AutoQueryableContext context = new AutoQueryableContext())
            {
                DataInitializer.InitializeSeed(context);
                var query = context.Product.Select(p => new ProductDto
                {
                    Name = p.Name
                }).AutoQueryable("") as IQueryable <object>;
                PropertyInfo[] properties = query.First().GetType().GetProperties();
                Assert.AreEqual(1, properties.Count());

                Assert.IsTrue(properties.Any(p => p.Name == "Name"));

                Assert.AreEqual(query.Count(), DataInitializer.ProductSampleCount);
            }
        }
예제 #23
0
        public void SelectAllProductsWithNameAndColorIgnoreCase()
        {
            using (var context = new AutoQueryableDbContext())
            {
                _queryStringAccessor.SetQueryString("select=Name,COLOR&top=0");

                DataInitializer.InitializeSeed(context);
                var query      = context.Product.AutoQueryable(_autoQueryableContext) as IQueryable <object>;
                var properties = query.First().GetType().GetProperties();

                properties.Length.Should().Be(2);

                properties.Should().Contain(p => p.Name == "Name");
                properties.Should().Contain(p => p.Name == "COLOR");

                query.Count().Should().Be(DataInitializer.ProductSampleCount);
            }
        }
예제 #24
0
        public void IdEquals3Or4Or5()
        {
            using (var context = new AutoQueryableDbContext())
            {
                _queryStringAccessor.SetQueryString("productid=3,4,5");

                DataInitializer.InitializeSeed(context);
                var query = context.Product.AutoQueryable(_autoQueryableContext)  as IQueryable <object>;

                query.Count().Should().Be(3);

                foreach (var product in query)
                {
                    var id = int.Parse(product.GetType().GetProperty("ProductId").GetValue(product).ToString());
                    id.Should().BeOneOf(3, 4, 5);
                }
            }
        }
예제 #25
0
        public void SelectAllWithSelectInclude()
        {
            using (var context = new AutoQueryableDbContext())
            {
                _queryStringAccessor.SetQueryString("top=50&select=name,SalesOrderDetail,productcategory");
                _profile.UnselectableProperties = new[] { "color" };

                DataInitializer.InitializeSeed(context);
                var query      = context.Product.AutoQueryable(_autoQueryableContext)  as IQueryable <object>;
                var properties = query.First().GetType().GetProperties();

                properties.Length.Should().Be(3);
                properties.Should().Contain(p => p.Name == "name");
                properties.Should().Contain(p => p.Name == "SalesOrderDetail");
                properties.Should().Contain(p => p.Name == "productcategory");

                query.Count().Should().Be(50);
            }
        }
예제 #26
0
        public void SellStartDateEqualsTodayOrTodayPlus8HourJsonFormatted()
        {
            using (var context = new AutoQueryableDbContext())
            {
                var todayJsonFormated          = DateTime.Today.ToString("yyyy-MM-dd");
                var todayPlus8HourJsonFormated = DateTime.Today.AddHours(8).ToString("yyyy-MM-ddThh:mm:ss");
                _queryStringAccessor.SetQueryString($"SellStartDate={todayJsonFormated},{todayPlus8HourJsonFormated}");

                DataInitializer.InitializeSeed(context);
                var query = context.Product.AutoQueryable(_autoQueryableContext)  as IQueryable <object>;

                query.Count().Should().Be(2);
                foreach (var product in query)
                {
                    var sellStartDate = DateTime.Parse(product.GetType().GetProperty("SellStartDate").GetValue(product).ToString());
                    sellStartDate.Should().BeOneOf(DateTime.Today, DateTime.Today.AddHours(8));
                }
            }
        }
예제 #27
0
        public void SelectAllWithSelectInclude()
        {
            using (AutoQueryableContext context = new AutoQueryableContext())
            {
                DataInitializer.InitializeSeed(context);
                var query = context.Product.AutoQueryable("top=50&select=name,SalesOrderDetail,productcategory", new AutoQueryableProfile {
                    UnselectableProperties = new[] { "color" }
                }) as IQueryable <object>;
                PropertyInfo[] properties = query.First().GetType().GetProperties();

                Assert.AreEqual(properties.Count(), 3);

                Assert.IsTrue(properties.Any(p => p.Name == "name"));
                Assert.IsTrue(properties.Any(p => p.Name == "SalesOrderDetail"));
                Assert.IsTrue(properties.Any(p => p.Name == "productcategory"));

                Assert.AreEqual(query.Count(), 50);
            }
        }
예제 #28
0
        public void SelectAllProductsWithSelectProjection3()
        {
            using (var context = new AutoQueryableDbContext())
            {
                _queryStringAccessor.SetQueryString("select=SalesOrderDetail.Product.ProductId&top=0");

                DataInitializer.InitializeSeed(context);
                var query = context.Product.AutoQueryable(_autoQueryableContext) as IQueryable <object>;

                var properties = query.First().GetType().GetProperties();
                properties.Length.Should().Be(1);

                var salesOrderDetailProperty = properties.FirstOrDefault(p => p.Name == "SalesOrderDetail").PropertyType
                                               .GenericTypeArguments[0];
                var productProperty = salesOrderDetailProperty.GetProperties().FirstOrDefault(x => x.Name == "Product");
                productProperty.Should().NotBeNull();
                productProperty.PropertyType.GetProperties().Should().Contain(x => x.Name == "ProductId");
                query.Count().Should().Be(DataInitializer.ProductSampleCount);
            }
        }
        public void AllowMultipleClauses()
        {
            using (AutoQueryableContext context = new AutoQueryableContext())
            {
                DataInitializer.InitializeSeed(context);
                var query = (context.Product.AutoQueryable("select=productId&top=10&skip=100", new AutoQueryableProfile
                {
                    AllowedClauses = ClauseType.Select | ClauseType.Top
                }) as IEnumerable <dynamic>).ToList();

                Assert.AreEqual(10, query.Count());
                var first = query.First();

                int propertiesCount = ((Type)first.GetType()).GetProperties().Count();
                Assert.IsTrue(1 == propertiesCount);

                int productid = first.GetType().GetProperty("productId").GetValue(first);
                Assert.IsTrue(1 == productid);
            }
        }
        public void AllowOnlyOneClause()
        {
            using (AutoQueryableContext context = new AutoQueryableContext())
            {
                DataInitializer.InitializeSeed(context);
                var query = (context.Product.AutoQueryable("select=name&top=10", new AutoQueryableProfile
                {
                    AllowedClauses = ClauseType.Select
                }) as IEnumerable <dynamic>).ToList();

                Assert.AreEqual(DataInitializer.ProductSampleCount, query.Count());
                var first = query.First();

                int propertiesCount = ((Type)first.GetType()).GetProperties().Count();
                Assert.IsTrue(1 == propertiesCount);

                string name = first.GetType().GetProperty("name").GetValue(first);
                Assert.IsNotNull(name);
            }
        }