public void Scenario()
        {
            TestDbContext.Exec(context => {
                var dbSet = context.Set <DataItem>();

                dbSet.Add(new DataItem {
                    Int32 = 1, NullableByte = 1
                });
                dbSet.Add(new DataItem {
                    Int32 = 2, NullableByte = 2
                });

                context.SaveChanges();

                var loadResult = DataSourceLoader.Load(dbSet, new SampleLoadOptions {
                    TotalSummary = new[] {
                        new SummaryInfo {
                            SummaryType = "sum", Selector = nameof(DataItem.Int32)
                        },
                        new SummaryInfo {
                            SummaryType = "sum", Selector = nameof(DataItem.NullableByte)
                        }
                    }
                });

                Assert.Equal(
                    new object[] { 3m, 3m },
                    loadResult.summary
                    );
            });
        }
        public void Scenario()
        {
            TestDbContext.Exec(context => {
                var dbSet = context.SelectNotMapped_Data;

                dbSet.Add(new SelectNotMapped_DataItem {
                    Blob = new byte[] { 143, 93, 183 }
                });
                context.SaveChanges();

                var loadOptions = new SampleLoadOptions {
                    PreSelect = new[] { "ID", "Name", "BlobUrl" },
                };

                var error = Record.Exception(delegate {
                    DataSourceLoader.Load(dbSet, loadOptions).data.Cast <object>().First();
                });

                Assert.Contains("member 'BlobUrl' is not supported ", error.Message);

                loadOptions.RemoteSelect = false;
                var loadResult           = DataSourceLoader.Load(dbSet, loadOptions);
                var item = loadResult.data.Cast <IDictionary>().First();

                Assert.Equal(3, item.Keys.Count);
                Assert.True(item.Contains("ID"));
                Assert.True(item.Contains("Name"));
                Assert.Equal("blob:j123", item["BlobUrl"]);
            });
        }
        public void Scenario()
        {
            TestDbContext.Exec(context => {
                var dbSet = context.Bug112_Data;

                dbSet.AddRange(new[] {
                    new Bug112_DataItem {
                        Duration = TimeSpan.Parse("01:23")
                    },
                    new Bug112_DataItem {
                        Duration = TimeSpan.Parse("02:23")
                    },
                    new Bug112_DataItem {
                        Duration = TimeSpan.Zero
                    }
                });

                context.SaveChanges();

                var loadResult = DataSourceLoader.Load(dbSet, new SampleLoadOptions {
                    Filter = new[] { "Duration", "contains", "23" }
                });

                var data = (IEnumerable <Bug112_DataItem>)loadResult.data;
                Assert.Equal(2, data.Count());
            });
        }
Beispiel #4
0
        public void Scenario()
        {
            TestDbContext.Exec(context => {
                var dbSet = context.Bug239_Data;

                dbSet.Add(new Bug239_DataItem());
                dbSet.Add(new Bug239_DataItem {
                    OrderDate = new DateTime(2009, 9, 9), Freight = 199
                });
                context.SaveChanges();

                var loadResult = DataSourceLoader.Load(dbSet, new SampleLoadOptions {
                    Group = new[] {
                        new GroupingInfo {
                            Selector = "OrderDate", IsExpanded = false, GroupInterval = "quarter"
                        },
                        new GroupingInfo {
                            Selector = "Freight", IsExpanded = false, GroupInterval = "50"
                        }
                    }
                });

                var groups = loadResult.data.Cast <Group>().ToArray();

                Assert.Null(groups[0].key);
                Assert.Null((groups[0].items[0] as Group).key);

                Assert.Equal(3, groups[1].key);
                Assert.Equal(150m, (groups[1].items[0] as Group).key);
            });
        }
        public void Scenario()
        {
            TestDbContext.Exec(context => {
                var parent = new T640117_ParentItem {
                    ID = 123
                };
                var child = new T640117_ChildItem {
                    ID = 1
                };
                var orphan = new T640117_ChildItem {
                    ID = 2
                };

                parent.Children.Add(child);
                context.T640117_Parents.Add(parent);
                context.T640117_Children.Add(orphan);
                context.SaveChanges();

                {
                    var loadResut = DataSourceLoader.Load(context.T640117_Children, new SampleLoadOptions {
                        Select = new[] { "Parent.ID" },
                        Sort   = new[] {
                            new SortingInfo {
                                Selector = "Parent.ID"
                            }
                        }
                    });

                    dynamic items = loadResut.data.Cast <object>().ToArray();
                    Assert.Null(items[0].Parent.ID);
                    Assert.Equal(123, items[1].Parent.ID);
                }

                {
                    var loadResult = DataSourceLoader.Load(context.T640117_Children, new SampleLoadOptions {
                        Filter = new[] { "Parent.ID", null }
                    });

                    Assert.Single(loadResult.data);
                }

                {
                    var loadResult = DataSourceLoader.Load(context.T640117_Children, new SampleLoadOptions {
                        Filter = new[] { "Parent.ID", "<>", null }
                    });

                    Assert.Single(loadResult.data);
                }

                {
                    var loadResult = DataSourceLoader.Load(context.T640117_Children, new SampleLoadOptions {
                        Filter = new[] { "ID", null }
                    });

                    Assert.Empty(loadResult.data);
                }
            });
        }
        public void Scenario()
        {
            TestDbContext.Exec(context => {
                var dbSet = context.Set <DataItem>();

                dbSet.AddRange(SummaryTestHelper.GenerateTestData(() => new DataItem()));
                context.SaveChanges();

                SummaryTestHelper.Run(dbSet);
            });
        }
Beispiel #7
0
        public void Scenario()
        {
            TestDbContext.Exec(context => {
                var dbSet = context.Set <DataItem>();

                dbSet.Add(new DataItem());
                context.SaveChanges();

                RemoteGroupingStressHelper.Run(dbSet);
            });
        }
        public void Scenario()
        {
            TestDbContext.Exec(context => {
                var dbSet = context.Set <DataItem>();

                dbSet.Add(new DataItem());
                context.SaveChanges();

                Assert.Null(Record.Exception(delegate {
                    RemoteGroupingStressHelper.Run(dbSet);
                }));
            });
        }
Beispiel #9
0
        public void Scenario()
        {
            TestDbContext.Exec(context => {
                var set = context.Set <PaginateViaPrimaryKey_DataItem>();
                foreach (var i in PaginateViaPrimaryKeyTestHelper.CreateTestData <PaginateViaPrimaryKey_DataItem>())
                {
                    set.Add(i);
                }
                context.SaveChanges();

                PaginateViaPrimaryKeyTestHelper.Run(set);
                PaginateViaPrimaryKeyTestHelper.Run(set.Select(i => new { i.K1, i.K2 }));
            });
        }
        public void Scenario()
        {
            TestDbContext.Exec(context => {
                var dbSet = context.Bug235_Data;

                dbSet.Add(new Bug235_DataItem {
                    ID = 1, Prop = 0
                });
                dbSet.Add(new Bug235_DataItem {
                    ID = 2, Prop = 2
                });
                dbSet.Add(new Bug235_DataItem {
                    ID = 0, Prop = 1
                });
                context.SaveChanges();

                var projection = dbSet.Select(i => new { i.ID, i.Prop });

                // Default settings: auto-sort by first sortable member (ID)
                {
                    var loadResult = DataSourceLoader.Load(projection, new SampleLoadOptions {
                        Skip = 1,
                        Take = 99
                    });

                    var data = ImplicitCast(projection, loadResult.data);

                    Assert.Equal(
                        new[] { 1, 2 },
                        data.Select(i => i.ID)
                        );
                }

                // User-provided DefaultSort
                {
                    var loadResult = DataSourceLoader.Load(projection, new SampleLoadOptions {
                        Skip        = 1,
                        Take        = 999,
                        DefaultSort = "Prop"
                    });

                    var data = ImplicitCast(projection, loadResult.data);

                    Assert.Equal(
                        new[] { 1, 2 },
                        data.Select(i => i.Prop)
                        );
                }
            });
        }
Beispiel #11
0
        public void Scenario()
        {
            TestDbContext.Exec(context => {
                var dbSet = context.Bug240_Data;

                dbSet.Add(new Bug240_DataItem());
                context.SaveChanges();

                var loadResult = DataSourceLoader.Load(dbSet, new SampleLoadOptions {
                    Select = new[] { "Date.Year", "Text.Length" }
                });

                var items = loadResult.data.Cast <dynamic>().ToArray();

                Assert.Null(items[0]["Date"]["Year"]);
                Assert.Null(items[0]["Text"]["Length"]);
            });
        }
        public void Scenario()
        {
            TestDbContext.Exec(context => {
                var dbSet = context.Bug179_Data;

                dbSet.AddRange(new[] {
                    new Bug179_DataItem {
                        Group = "A", Value = 1
                    },
                    new Bug179_DataItem {
                        Group = "A", Value = 3
                    },
                    new Bug179_DataItem {
                        Group = "A", Value = null
                    },
                    new Bug179_DataItem {
                        Group = "B", Value = 5
                    },
                    new Bug179_DataItem {
                        Group = "B", Value = null
                    },
                });

                context.SaveChanges();

                var loadResult = DataSourceLoader.Load(dbSet, new SampleLoadOptions {
                    Group = new[] {
                        new GroupingInfo {
                            Selector = "Group", IsExpanded = false
                        }
                    },
                    GroupSummary = new[] {
                        new SummaryInfo {
                            SummaryType = "avg", Selector = "Value"
                        },
                        new SummaryInfo {
                            SummaryType = "count"
                        },
                        new SummaryInfo {
                            SummaryType = "sum", Selector = "Value"
                        }
                    },
                    TotalSummary = new[] {
                        new SummaryInfo {
                            SummaryType = "sum", Selector = "Value"
                        },
                        new SummaryInfo {
                            SummaryType = "count"
                        },
                        new SummaryInfo {
                            SummaryType = "avg", Selector = "Value"
                        }
                    }
                });

                var loadResultGroups = loadResult.data.Cast <ResponseModel.Group>().ToArray();

                var referenceGroups = dbSet
                                      .GroupBy(i => i.Group)
                                      .OrderBy(g => g.Key)
                                      .Select(g => new {
                    Avg   = g.Average(i => i.Value),
                    Count = g.Count(),
                    Sum   = g.Sum(i => i.Value)
                })
                                      .ToArray();

                for (var g = 0; g < 2; g++)
                {
                    Assert.Equal((decimal)referenceGroups[g].Avg, loadResultGroups[g].summary[0]);
                    Assert.Equal(referenceGroups[g].Count, loadResultGroups[g].summary[1]);
                    Assert.Equal((decimal)referenceGroups[g].Sum, loadResultGroups[g].summary[2]);
                }

                Assert.Equal((decimal)dbSet.Sum(i => i.Value), loadResult.summary[0]);
                Assert.Equal(dbSet.Count(), loadResult.summary[1]);
                Assert.Equal((decimal)dbSet.Average(i => i.Value), loadResult.summary[2]);
            });
        }
        public void Scenario()
        {
            TestDbContext.Exec(context => {
                var dbSet = context.Bug_FindInList_ItemA;

                dbSet.AddRange(new[] {
                    new Bug_FindInList_DataItemA {
                        ID    = 1, Date = DateTime.Now, Text = "qqqq1",
                        Items = new List <Bug_FindInList_DataItemB> {
                            new Bug_FindInList_DataItemB {
                                Id = 1, Name = "b_0011"
                            },
                            new Bug_FindInList_DataItemB {
                                Id = 2, Name = "b_0012"
                            },
                            new Bug_FindInList_DataItemB {
                                Id = 3, Name = "b_0013"
                            }
                        }
                    },
                    new Bug_FindInList_DataItemA {
                        ID    = 2, Date = DateTime.Now, Text = "qqqq2",
                        Items = new List <Bug_FindInList_DataItemB> {
                            new Bug_FindInList_DataItemB {
                                Id = 21, Name = "b_0021"
                            },
                            new Bug_FindInList_DataItemB {
                                Id = 22, Name = "b_0022"
                            },
                            new Bug_FindInList_DataItemB {
                                Id = 23, Name = "b_0023"
                            }
                        }
                    },
                    new Bug_FindInList_DataItemA {
                        ID    = 3, Date = DateTime.Now, Text = "qqqq3",
                        Items = new List <Bug_FindInList_DataItemB> {
                            new Bug_FindInList_DataItemB {
                                Id = 31, Name = "b_0031"
                            },
                            new Bug_FindInList_DataItemB {
                                Id = 32, Name = "b_0032"
                            },
                            new Bug_FindInList_DataItemB {
                                Id = 33, Name = "b_0033"
                            }
                        }
                    }
                });

                context.SaveChanges();

                // we implement "any" operator for search in collections
                var filter = new List <object> {
                    "Items", "any", new List <object> {
                        "Id", ">", "1"
                    }
                };
                var loadResult = DataSourceLoader.Load(dbSet, new SampleLoadOptions {
                    Filter = filter
                });

                /*// 2nd variant: by prepare expression
                 *  var queryableData = objectSpace.GetObjectsQuery<ServiceDeskRequest>();
                 *  var parameter = Expression.Parameter(typeof(ServiceDeskRequest), "A");
                 *  var expression = GetNavigationPropertyExpression(parameter, someUserOid, "Group", "Individuals", "Oid");
                 *  var whereCallExpression = Expression.Call(
                 *      typeof(Queryable), "Where", new Type[] { queryableData.ElementType }, queryableData.Expression, expression);
                 *  var results = queryableData.Provider.CreateQuery<ServiceDeskRequest>(whereCallExpression).Take(10);
                 *  foreach (ServiceDeskRequest item in results)
                 *      Console.WriteLine(item);*/

                var data      = (IEnumerable <Bug_FindInList_DataItemA>)loadResult.data;
                var dataCount = data.Count();
                Assert.Equal(2, dataCount);
            });
        }