コード例 #1
0
ファイル: OrderQueryableGenerator.cs プロジェクト: Reris/Riql
        private static (IQueryable <Order>, IDisposable) BuildOrdersLinq2DbContext()
        {
            var connection = new SqliteConnection("DataSource=:memory:");

            try
            {
                connection.Open();

                var linq2Db = new OrderLinq2Db(connection);
                linq2Db.CreateTable <Employee>();
                foreach (var employee in TestSamples.GetEmployees())
                {
                    linq2Db.Insert(employee);
                }

                linq2Db.CreateTable <Order>();
                foreach (var order in TestSamples.GetOrders())
                {
                    linq2Db.Insert(order);
                }

                return(linq2Db.Orders, connection);
            }
            catch
            {
                connection.Dispose();
                throw;
            }
        }
コード例 #2
0
        public IEnumerator <object[]> GetEnumerator()
        {
            yield return(new object[] { TestSamples.GetEmployees().AsQueryable(), new DisposableMock() });

            var(efQueryable, efConnection) = EmployeeQueryableGenerator.BuildEmployeesEfContext();
            yield return(new object[] { efQueryable, efConnection });

            var(linq2dbQueryable, linq2dbConnection) = EmployeeQueryableGenerator.BuildEmployeesLinq2DbContext();
            yield return(new object[] { linq2dbQueryable, linq2dbConnection });
        }
コード例 #3
0
ファイル: OrderQueryableGenerator.cs プロジェクト: Reris/Riql
        public IEnumerator <object[]> GetEnumerator()
        {
            var employees = TestSamples.GetEmployees();

            yield return(new object[]
            {
                TestSamples.GetOrders().Select(
                    (o) =>
                {
                    o.Manager = employees.FirstOrDefault(e => e.Id == o.ManagerId);
                    return o;
                }).AsQueryable(),
                new DisposableMock()
            });

            var(efQueryable, efConnection) = OrderQueryableGenerator.BuildOrdersEfContext();
            yield return(new object[] { efQueryable, efConnection });

            var(linq2dbQueryable, linq2dbConnection) = OrderQueryableGenerator.BuildOrdersLinq2DbContext();
            yield return(new object[] { linq2dbQueryable, linq2dbConnection });
        }
コード例 #4
0
        private static (IQueryable <Employee>, IDisposable) BuildEmployeesEfContext()
        {
            var connection = new SqliteConnection("DataSource=:memory:");

            try
            {
                connection.Open();
                var options = new DbContextOptionsBuilder <EmployeeDbContext>()
                              .UseSqlite(connection)
                              .Options;
                var context         = new EmployeeDbContext(options);
                var databaseCreator = (RelationalDatabaseCreator)context.Database.GetService <IDatabaseCreator>();
                databaseCreator.CreateTables();
                context.Employees.AddRange(TestSamples.GetEmployees());
                context.SaveChanges();
                return(context.Employees, connection);
            }
            catch
            {
                connection.Dispose();
                throw;
            }
        }
コード例 #5
0
ファイル: TestSamples.cs プロジェクト: Reris/Riql
        public static Order[] GetOrders()
        {
            var employees = TestSamples.GetEmployees();

            return(new[]
            {
                new Order
                {
                    Id = 1,
                    Requirement = "MUST do 1",
                    ManagerId = employees[1].Id,
                    Started = new DateTime(2019, 7, 24, 17, 50, 33),
                    Price = 50,
                    Accepted = true,
                    Flags = OrderFlags.Important
                },
                new Order
                {
                    Id = 2,
                    Requirement = null,
                    ManagerId = null,
                    Started = null,
                    Price = null,
                    Accepted = null,
                    Flags = null
                },
                new Order
                {
                    Id = 3,
                    Requirement = "MUST do 3",
                    ManagerId = employees[3].Id,
                    Started = new DateTime(2013, 3, 4, 13, 37, 33),
                    Price = 3,
                    Accepted = false,
                    Flags = OrderFlags.Deprecated | OrderFlags.Reconcider
                },
                new Order
                {
                    Id = 4,
                    Requirement = "MUST do 4",
                    ManagerId = employees[1].Id,
                    Started = new DateTime(2014, 4, 5, 14, 57, 0),
                    Price = 300,
                    Accepted = false,
                    Flags = OrderFlags.Escalated | OrderFlags.Reconcider
                },
                new Order
                {
                    Id = 5,
                    Requirement = "MUST do 5",
                    ManagerId = employees[5].Id,
                    Started = null,
                    Price = 500,
                    Accepted = null,
                    Flags = null
                },
                new Order
                {
                    Id = 6,
                    Requirement = "MUST do 6",
                    ManagerId = employees[2].Id,
                    Started = null,
                    Price = 606,
                    Accepted = true,
                    Flags = null
                },
                new Order
                {
                    Id = 7,
                    Requirement = "MUST do 7",
                    ManagerId = employees[1].Id,
                    Started = null,
                    Price = 42,
                    Accepted = null,
                    Flags = null
                },
                new Order
                {
                    Id = 8,
                    Requirement = "MUST do 8",
                    ManagerId = employees[5].Id,
                    Started = null,
                    Price = 56,
                    Accepted = false,
                    Flags = null
                },
                new Order
                {
                    Id = 9,
                    Requirement = "MUST do 9",
                    ManagerId = employees[4].Id,
                    Started = new DateTime(2018, 8, 1),
                    Price = -100,
                    Accepted = true,
                    Flags = OrderFlags.Escalated
                },
                new Order
                {
                    Id = 10,
                    Requirement = "MUST do 10",
                    ManagerId = employees[3].Id,
                    Started = null,
                    Price = 500,
                    Accepted = null,
                    Flags = null
                },
                new Order
                {
                    Id = 11,
                    Requirement = "MUST do 11",
                    ManagerId = null,
                    Started = null,
                    Price = -5.5m,
                    Accepted = null,
                    Flags = null
                },
                new Order
                {
                    Id = 12,
                    Requirement = "MUST do 12",
                    ManagerId = employees[4].Id,
                    Started = null,
                    Price = null,
                    Accepted = null,
                    Flags = null
                }
            });
        }