Esempio n. 1
0
        public async Task SaveWithServerExit()
        {
            var em1 = await TestFns.NewEm(_serviceName);

            //  ok(true, "Skipped test - OData does not support server interception or alt resources");
            CreateParentAndChildren(em1);
            var so  = new SaveOptions("SaveWithExit", tag: "exit");
            var sr0 = await em1.SaveChanges(so);

            Assert.IsTrue(sr0.Entities.Count == 0);
        }
Esempio n. 2
0
        public async Task CustomersStartingWith()
        {
            var em1 = await TestFns.NewEm(_serviceName);

            var q         = new EntityQuery <Customer>("CustomersStartingWith").WithParameter("companyName", "A");
            var rp        = q.GetResourcePath(em1.MetadataStore);
            var customers = await q.Execute(em1);

            Assert.IsTrue(customers.Count() > 0, "should be some results");
            Assert.IsTrue(customers.All(c => c.CompanyName.StartsWith("A")));
        }
        public async Task QueryCheckUnique()
        {
            var em1 = await TestFns.NewEm(_serviceName);

            var q  = new EntityQuery <ItemOfProduce>();
            var r0 = await em1.ExecuteQuery(q);

            var hs = r0.Select(r => r.QuantityPerUnit).ToHashSet();

            Assert.IsTrue(hs.Count() > 2, "should be more than 2 unique values");
        }
Esempio n. 4
0
        public async Task WhereAnyNested()
        {
            var em1 = await TestFns.NewEm(_serviceName);

            var query1 = new EntityQuery <Customer>()
                         .Where(c => c.Orders.Any(o => o.OrderDetails.All(od => od.UnitPrice > 200)));

            var results = await query1.Execute(em1);

            Assert.IsTrue(results.Any());
        }
        public async Task SimplePred()
        {
            var entityManager = await TestFns.NewEm(_serviceName);

            // Orders with freight cost over 300.
            var pred      = PredicateBuilder.Create <Order>(o => o.Freight > 300);
            var query     = new EntityQuery <Order>().Where(pred);
            var orders300 = await entityManager.ExecuteQuery(query);

            Assert.IsTrue(orders300.Any(), "There should be orders with freight cost > 300");
        }
Esempio n. 6
0
        public async Task WithEntityManager()
        {
            var em1 = await TestFns.NewEm(_serviceName);

            var q       = new EntityQuery <Foo.Customer>("Customers");
            var q2      = q.Where(c => c.CompanyName.StartsWith("C"));
            var q3      = q2.OrderBy(c => c.CompanyName).Take(2);
            var results = await q3.With(em1).Execute();

            Assert.IsTrue(results.Count() == 2);
        }
Esempio n. 7
0
        public async Task ExpandNested3Levels()
        {
            var em1 = await TestFns.NewEm(_serviceName);

            var q0 = new EntityQuery <Order>().Take(5).Expand("OrderDetails.Product.Category");

            var r0 = await q0.Execute(em1);

            Assert.IsTrue(r0.Count() > 0, "should have returned some orders");
            Assert.IsTrue(r0.All(o => o.OrderDetails.Any(od => od.Product.Category != null)));
        }
Esempio n. 8
0
        public async Task FkFixup()
        {
            var em1 = await TestFns.NewEm(_serviceName);

            var cust1  = em1.CreateEntity <Customer>(EntityState.Unchanged);
            var order1 = em1.CreateEntity <Order>(EntityState.Unchanged);

            order1.CustomerID = cust1.CustomerID;
            Assert.IsTrue(cust1.Orders.Contains(order1), "should contain order1");
            Assert.IsTrue(order1.Customer == cust1, "customer should be attached");
        }
Esempio n. 9
0
        public async Task CreateEntityWithInitializer()
        {
            var em1 = await TestFns.NewEm(_serviceName);

            var cust = (Customer)em1.CreateEntity(typeof(Customer), new { CompanyName = "Testzzz", City = "Los Angeles", RowVersion = 3 });

            Assert.IsTrue(cust.EntityAspect.EntityState.IsAdded());
            Assert.IsTrue(cust.CompanyName == "Testzzz");
            Assert.IsTrue(cust.City == "Los Angeles");
            Assert.IsTrue(cust.RowVersion == 3);
        }
Esempio n. 10
0
        public async Task CheckDefaultValues()
        {
            var em1 = await TestFns.NewEm(_serviceName);

            var supplier    = em1.CreateEntity <Supplier>();
            var companyName = supplier.CompanyName;
            var location    = supplier.Location;

            Assert.IsTrue(location.GetType() == typeof(Location));
            var city = location.City;
        }
Esempio n. 11
0
        public async Task WhereContains()
        {
            var em1 = await TestFns.NewEm(_serviceName);

            var q = new EntityQuery <Customer>()
                    .Where(c => c.CompanyName.Contains("market"));

            var results = await em1.ExecuteQuery(q);

            Assert.IsTrue(results.Any());
        }
Esempio n. 12
0
        public async Task ExpandNested()
        {
            var em1 = await TestFns.NewEm(_serviceName);

            var q0 = new EntityQuery <OrderDetail>().Take(5).Expand(od => od.Order.Customer);

            var r0 = await q0.Execute(em1);

            Assert.IsTrue(r0.Count() > 0, "should have returned some orderDetails");
            Assert.IsTrue(r0.All(od => od.Order != null && od.Order.Customer != null));
        }
Esempio n. 13
0
        public async Task SelectAnonSingleDp()
        {
            var em1 = await TestFns.NewEm(_serviceName);

            var q = new EntityQuery <Customer>("Customers")
                    .Where(c => c.CompanyName.StartsWith("C"))
                    .Select(c => new { c.CompanyName });

            var results = await q.Execute(em1);

            Assert.IsTrue(results.Any());
        }
Esempio n. 14
0
        public async Task WithOnlyExpand()
        {
            var em1 = await TestFns.NewEm(_serviceName);

            var q  = new EntityQuery <Customer>().Take(3);
            var r0 = await em1.ExecuteQuery(q);

            var q1 = new EntityQuery <Customer>().Expand("Orders");
            var r1 = q1.ExecuteLocally(em1);

            Assert.IsTrue(r0.Count() == r1.Count());
        }
Esempio n. 15
0
        public async Task NonGenericQuery()
        {
            var em1 = await TestFns.NewEm(_serviceName);

            var q  = new EntityQuery <Foo.Customer>("Customers");
            var q2 = q.Where(c => c.CompanyName.StartsWith("C")).Take(3);
            var q3 = (EntityQuery)q2;

            var results = await em1.ExecuteQuery(q3);

            Assert.IsTrue(results.Cast <Object>().Count() == 3);
        }
Esempio n. 16
0
        public async Task SelectSimpleAnonEntityCollection()
        {
            var em1 = await TestFns.NewEm(_serviceName);

            var q1 = new EntityQuery <Customer>().Where(c => c.CompanyName.StartsWith("C")).Select(c => new { c.Orders });
            var r1 = await q1.Execute(em1);

            Assert.IsTrue(r1.Count() > 0);
            var ok = r1.All(r => r.Orders.Count() > 0);

            Assert.IsTrue(ok);
        }
Esempio n. 17
0
        public async Task SelectSimpleAnonEntity()
        {
            var em1 = await TestFns.NewEm(_serviceName);

            var q1 = new EntityQuery <Order>().Select(o => new { o.Customer }).Take(5);
            var r1 = await q1.Execute(em1);

            Assert.IsTrue(r1.Count() == 5);
            var ok = r1.All(r => r.Customer.GetType() == typeof(Customer));

            Assert.IsTrue(ok);
        }
Esempio n. 18
0
        public async Task AttachDetachReattach()
        {
            var em1 = await TestFns.NewEm(_serviceName);

            var order = em1.CreateEntity <Order>(null, EntityState.Unchanged);

            Assert.IsTrue(order.EntityAspect.IsAttached && order.EntityAspect.EntityState.IsUnchanged());
            em1.DetachEntity(order);
            Assert.IsTrue(order.EntityAspect.IsDetached);
            em1.AttachEntity(order);
            Assert.IsTrue(order.EntityAspect.IsAttached && order.EntityAspect.EntityState.IsUnchanged());
        }
Esempio n. 19
0
        public async Task AddDetachReadd()
        {
            var em1 = await TestFns.NewEm(_serviceName);

            var order = em1.CreateEntity <Order>();

            Assert.IsTrue(order.EntityAspect.IsAttached && order.EntityAspect.EntityState.IsAdded());
            em1.DetachEntity(order);
            Assert.IsTrue(order.EntityAspect.IsDetached);
            em1.AttachEntity(order, EntityState.Added);
            Assert.IsTrue(order.EntityAspect.IsAttached && order.EntityAspect.EntityState.IsAdded());
        }
Esempio n. 20
0
        public async Task WhereOrderByTake()
        {
            var em1 = await TestFns.NewEm(_serviceName);

            var q       = new EntityQuery <Foo.Customer>("Customers");
            var q2      = q.Where(c => c.CompanyName.StartsWith("C"));
            var q3      = q2.OrderBy(c => c.CompanyName).Take(2);
            var results = await q3.Execute(em1);

            Assert.IsTrue(results.Count() == 2);
            Assert.IsTrue(results.All(r1 => r1.GetType() == typeof(Foo.Customer)), "should all get customers");
        }
Esempio n. 21
0
        public async Task SimpleCall()
        {
            //return;
            var em1 = await TestFns.NewEm(_dataService);

            var initParameters = InitialParameters();
            var q = new EntityQuery <Make>().From("vehicle/makerepository/findall")
                    .WithParameters(initParameters).With(new EdmundsJsonResultsAdapter());
            var r = await em1.ExecuteQuery(q);

            Assert.IsTrue(r.Any());
        }
        public async Task LoadNavigationPropertyScalar()
        {
            var em1 = await TestFns.NewEm(_serviceName);

            TestFns.RunInWpfSyncContext(async() => {
                var q0 = new EntityQuery <Order>().Where(o => o.Customer != null).Take(3);
                var r0 = await q0.Execute(em1);
                // Task.WaitAll(r0.Select(o => o.EntityAspect.LoadNavigationProperty("Customer")).ToArray());
                await Task.WhenAll(r0.Select(o => o.EntityAspect.LoadNavigationProperty("Customer")));
                Assert.IsTrue(r0.All(o => o.Customer != null));
            });
        }
Esempio n. 23
0
        public async Task LookupsSimple()
        {
            var entityManager = await TestFns.NewEm(_serviceName);

            var query = EntityQuery.From("Lookup1Array", new {
                regions = new List <Region>()
            });

            var r0 = await query.Execute(entityManager);

            Assert.IsTrue(r0.Any());
        }
        public async Task LoadNavigationPropertyNonscalar()
        {
            var em1 = await TestFns.NewEm(_serviceName);

            TestFns.RunInWpfSyncContext(async() => {
                var q0 = new EntityQuery <Customer>().Where(c => c.Orders.Any()).Take(3);
                var r0 = await q0.Execute(em1);
                // Task.WaitAll(r0.Select(c => c.EntityAspect.LoadNavigationProperty("Orders")).ToArray());
                await Task.WhenAll(r0.Select(c => c.EntityAspect.LoadNavigationProperty("Orders")));
                Assert.IsTrue(r0.All(c => c.Orders.Count() > 0));
            });
        }
Esempio n. 25
0
        public async Task SelectScalarNpNoAnon()
        {
            Assert.Inconclusive("Known issue with OData - use an anon projection instead");
            var em1 = await TestFns.NewEm(_serviceName);

            var q1 = new EntityQuery <Order>().Where(o => true).Select(o => o.Customer).Take(5);
            var r1 = await q1.Execute(em1);

            Assert.IsTrue(r1.Count() == 5);
            var ok = r1.All(r => r.GetType() == typeof(Customer));

            Assert.IsTrue(ok);
        }
Esempio n. 26
0
        public async Task CreateEntity()
        {
            var em1 = await TestFns.NewEm(_serviceName);

            var emp1 = em1.CreateEntity(typeof(Employee));

            Assert.IsTrue(emp1.EntityAspect.EntityState == EntityState.Added);
            var emp3 = em1.CreateEntity <Employee>(null, EntityState.Detached);

            emp3.LastName = "Smith";
            Assert.IsTrue(emp3.EntityAspect.EntityState.IsDetached());
            Assert.IsTrue(emp3.LastName == "Smith");
        }
Esempio n. 27
0
        public async Task WhereFnMonth()
        {
            var em1 = await TestFns.NewEm(_serviceName);

            var q0 = new EntityQuery <Employee>().Where(e => e.HireDate.Value.Month > 6 && e.HireDate.Value.Month < 11);
            var r0 = await q0.Execute(em1);

            Assert.IsTrue(r0.Count() > 0);
            Assert.IsTrue(r0.All(e => e.HireDate.Value.Month > 6 && e.HireDate.Value.Month < 11));
            var r1 = q0.ExecuteLocally(em1);

            Assert.IsTrue(r1.Count() == r0.Count());
        }
Esempio n. 28
0
        public async Task WhereFnAdd()
        {
            var em1 = await TestFns.NewEm(_serviceName);

            var q0 = new EntityQuery <Employee>().Where(e => e.EmployeeID + e.ReportsToEmployeeID.Value > 3);
            var r0 = await q0.Execute(em1);

            Assert.IsTrue(r0.Count() > 0);
            Assert.IsTrue(r0.All(e => e.EmployeeID + e.ReportsToEmployeeID > 3));
            var r1 = q0.ExecuteLocally(em1);

            Assert.IsTrue(r1.Count() == r0.Count());
        }
Esempio n. 29
0
        public async Task NoWhere()
        {
            var em1 = await TestFns.NewEm(_serviceName);

            var q = new EntityQuery <Customer>();

            var results = await em1.ExecuteQuery(q);

            Assert.IsTrue(results.Cast <Object>().Count() > 0);
            var r1 = await em1.ExecuteQuery(q.Take(2));

            Assert.IsTrue(r1.Count() == 2);
        }
Esempio n. 30
0
        public async Task Take0WithInlineCount()
        {
            var em1 = await TestFns.NewEm(_serviceName);

            var q0 = new EntityQuery <Customer>().Take(0).InlineCount();

            var r0 = await q0.Execute(em1);

            Assert.IsTrue(r0.Count() == 0);
            var count = ((IHasInlineCount)r0).InlineCount;

            Assert.IsTrue(count > 0);
        }