Beispiel #1
0
        public void ReuseSkip2Test()
        {
            Require.AnyFeatureSupported(ProviderFeatures.RowNumber | ProviderFeatures.NativePaging);
            var totalCount = Session.Query.All <Customer>().Count();
            var result1    = SkipCustomersCorrect(1).Count();

            Assert.AreEqual(totalCount - 1, result1);
            var result2 = SkipCustomersCorrect(2).Count();

            Assert.AreEqual(totalCount - 2, result2);
        }
Beispiel #2
0
        public void MultipleTakeSkipRandomTest()
        {
            Require.AnyFeatureSupported(ProviderFeatures.RowNumber | ProviderFeatures.NativePaging);
            IQueryable <Customer> query = Session.Query.All <Customer>().OrderBy(customer => customer.CustomerId);
            int count         = query.Count();
            var expected      = query.AsEnumerable();
            var randomManager = RandomManager.CreateRandom();

            for (int i = 0; i < 5; i++)
            {
                int randomInt = randomManager.Next(0, 9);
                switch (randomInt)
                {
                case 0:
                    // Take with negative count
                    var takeNegativeCount = randomManager.Next(-count + 1, -1);
                    query    = query.Take(takeNegativeCount);
                    expected = expected.Take(takeNegativeCount);
                    break;

                case 1:
                case 2:
                case 3:
                case 4:
                    // Take
                    var takeCount = randomManager.Next((int)(count * 0.8), count);
                    query    = query.Take(takeCount);
                    expected = expected.Take(takeCount);
                    break;

                case 5:
                case 6:
                case 7:
                case 8:
                    // Skip
                    var skipCount = randomManager.Next((int)(count * 0.1), count);
                    query    = query.Skip(skipCount);
                    expected = expected.Skip(skipCount);
                    break;

                case 9:
                    // Skip with negative count
                    var skipNegativeCount = randomManager.Next((int)(-count * 0.1 + 1), -1);
                    query    = query.Skip(skipNegativeCount);
                    expected = expected.Skip(skipNegativeCount);
                    break;
                }
            }
            Assert.IsTrue(expected.SequenceEqual(query));
        }
Beispiel #3
0
        public void DistinctSkipTest()
        {
            Require.AnyFeatureSupported(ProviderFeatures.RowNumber | ProviderFeatures.NativePaging);
            var result = Session.Query.All <Customer>()
                         .Distinct()
                         .OrderBy(c => c.LastName)
                         .Skip(5);
            var expected = Customers
                           .Distinct()
                           .OrderBy(c => c.LastName)
                           .Skip(5);

            Assert.IsTrue(expected.SequenceEqual(result));
            Assert.Greater(result.ToList().Count, 0);
        }
        public void ReferencedEntityHasBeenFullyLoadedBeforeTaskActivationTest()
        {
            Require.AnyFeatureSupported(ProviderFeatures.RowNumber | ProviderFeatures.NativePaging);
            Key order0Key;
            Key employee0Key;
            Key order1Key;
            Key employee1Key;

            using (var session = Domain.OpenSession())
                using (var tx = session.OpenTransaction()) {
                    var order0 = session.Query.All <Order>().OrderBy(o => o.Id).First();
                    var order1 = session.Query.All <Order>().OrderBy(o => o.Id).Skip(1).First();
                    order0Key    = order0.Key;
                    employee0Key = order0.Employee.Key;
                    order1Key    = order1.Key;
                    employee1Key = order1.Employee.Key;
                }

            using (var session = Domain.OpenSession())
                using (session.OpenTransaction()) {
                    var prefetchManager   = (PrefetchManager)PrefetchProcessorField.GetValue(session.Handler);
                    var employeeNameField = Domain.Model.Types[typeof(Person)].Fields["Name"];
                    var employeeAgeField  = employee1Key.TypeInfo.Fields["Age"];
                    prefetchManager.InvokePrefetch(employee0Key, null,
                                                   new PrefetchFieldDescriptor(employeeNameField), new PrefetchFieldDescriptor(AgeField));
                    prefetchManager.InvokePrefetch(employee1Key, null, new PrefetchFieldDescriptor(AgeField));
                    prefetchManager.InvokePrefetch(order0Key, null, new PrefetchFieldDescriptor(OrderIdField));
                    prefetchManager.InvokePrefetch(order1Key, null, new PrefetchFieldDescriptor(OrderIdField));
                    prefetchManager.ExecuteTasks(true);

                    prefetchManager.InvokePrefetch(order0Key, null, new PrefetchFieldDescriptor(EmployeeField, true, true));
                    prefetchManager.InvokePrefetch(order1Key, null, new PrefetchFieldDescriptor(EmployeeField, true, true));
                    var graphContainers = (SetSlim <GraphContainer>)GraphContainersField.GetValue(prefetchManager);
                    Assert.AreEqual(2, graphContainers.Count);
                    Func <Key, ReferencedEntityContainer> taskSelector = containerKey => graphContainers
                                                                         .Where(container => container.Key == containerKey)
                                                                         .SelectMany(container => container.ReferencedEntityContainers).Single();
                    var entityContainer0 = taskSelector.Invoke(order0Key);
                    var entityContainer1 = taskSelector.Invoke(order1Key);
                    prefetchManager.ExecuteTasks(true);
                    Assert.IsNull(entityContainer0.Task);
                    Assert.IsNotNull(entityContainer1.Task);
                    PrefetchTestHelper.AssertOnlySpecifiedColumnsAreLoaded(employee0Key, employee0Key.TypeInfo, session,
                                                                           PrefetchTestHelper.IsFieldToBeLoadedByDefault);
                    PrefetchTestHelper.AssertOnlySpecifiedColumnsAreLoaded(employee1Key, employee1Key.TypeInfo, session,
                                                                           PrefetchTestHelper.IsFieldToBeLoadedByDefault);
                }
        }
Beispiel #5
0
 public void GroupJoinTest()
 {
     Require.AnyFeatureSupported(ProviderFeatures.TemporaryTableEmulation | ProviderFeatures.TemporaryTables);
     using (var session = Domain.OpenSession())
         using (var tx = session.OpenTransaction()) {
             var items = new List <int> {
                 2, 3
             };
             var query =
                 from o in session.Query.All <NamedObject>()
                 join i in items on o.Id equals i
                 into j
                 select o;
             var result = query.ToList();
             Assert.That(result.Count, Is.EqualTo(3));
         }
 }
Beispiel #6
0
        public void ApplyTest()
        {
            Require.AnyFeatureSupported(ProviderFeatures.TemporaryTableEmulation | ProviderFeatures.TemporaryTables);
            using (var session = Domain.OpenSession())
                using (var tx = session.OpenTransaction()) {
                    var items = new List <int> {
                        1, 2, 3
                    };

                    var query =
                        from o in session.Query.All <NamedObject>()
                        from i in items
                        select new { Object = o, Item = i };

                    Assert.That(query.Count(), Is.EqualTo(9));
                }
        }
Beispiel #7
0
        public void SkipTest()
        {
            Require.AnyFeatureSupported(ProviderFeatures.RowNumber | ProviderFeatures.NativePaging);
            var result = Session.Query.All <Invoice>()
                         .OrderBy(o => o.InvoiceDate)
                         .Skip(5)
                         .Select(o => o.InvoiceDate)
                         .Distinct().OrderBy(d => d);
            var expected = Invoices
                           .OrderBy(o => o.InvoiceDate)
                           .Skip(5)
                           .Select(o => o.InvoiceDate)
                           .Distinct().OrderBy(d => d);

            Assert.IsTrue(expected.SequenceEqual(result));
            Assert.Greater(result.ToList().Count, 0);
        }
Beispiel #8
0
        public void ElementAtOrDefaultIsNotRootTest()
        {
            Require.AnyFeatureSupported(ProviderFeatures.RowNumber | ProviderFeatures.NativePaging);
            var customers = Session.Query.All <Customer>().OrderBy(customer => customer.CustomerId).ToList();

            Assert.IsTrue(customers.Count > 0);
            for (int i = -100; i < customers.Count + 100; i++)
            {
                if (i < 0 || i >= customers.Count)
                {
                    Assert.IsNull(Session.Query.All <Customer>().OrderBy(customer => customer.CustomerId).ElementAtOrDefault(i));
                }
                else
                {
                    Assert.AreEqual(customers[i], Session.Query.All <Customer>().OrderBy(customer => customer.CustomerId).ElementAtOrDefault(i));
                }
            }
        }
        public void CombinedTest()
        {
            Require.AnyFeatureSupported(ProviderFeatures.RowNumber | ProviderFeatures.NativePaging);
            using (var session = Domain.OpenSession())
                for (int i = 0; i < iterationCount; i++)
                {
                    GetAction().Invoke();
                }

            using (var session = Domain.OpenSession())
                using (session.OpenTransaction()) {
                    var  trees      = Session.Demand().Query.All <Tree>().ToList();
                    long totalCount = 0;
                    foreach (var tree in trees)
                    {
                        totalCount += ValidateNodes(tree.Root) + 1;
                    }
                    Assert.AreEqual(nodesData.Count, totalCount);
                }
        }
        public void Test02()
        {
            Require.AnyFeatureSupported(ProviderFeatures.TemporaryTableEmulation | ProviderFeatures.TemporaryTables);

            using (var session = Domain.OpenSession())
                using (var t = session.OpenTransaction()) {
                    var controlId = Guid.NewGuid();
                    var messageId = Guid.NewGuid();
                    var control   = new Control(controlId);
                    var message   = new ControlMessage(messageId)
                    {
                        Owner = control
                    };
                    session.SaveChanges();

                    var ids    = new[] { controlId, messageId };
                    var itemsA = session.Query.All <Control>().Where(a => ids.Any(id => a.Messages.Select(b => b.Id).Contains(id))).ToList();
                    Assert.AreEqual(1, itemsA.Count);
                    Assert.AreSame(control, itemsA[0]);
                }
        }
        public void Test1()
        {
            Require.AnyFeatureSupported(ProviderFeatures.TransactionalDdl);

            using (var initialDomain = Domain.Build(BuildConfiguration(true, typeof(model.V1.Initial.TestEntity))))
                using (var session = initialDomain.OpenSession())
                    using (var transaction = session.OpenTransaction()) {
                        for (int i = 0; i < 10; i++)
                        {
                            new model.V1.Initial.TestEntity()
                            {
                                Name           = "Name",
                                ReferenceField = new model.V1.Initial.TestReferencedEntity(),
                                StateField     = model.V1.Initial.State.Live,
                                TimeSpanField  = new TimeSpan(3, 3, 3, 3),
                            };
                        }
                        transaction.Complete();
                    }

            Assert.Throws <CheckConstraintViolationException>(
                () => {
                Domain domain = null;
                try {
                    domain = Domain.Build(BuildConfiguration(false, typeof(model.V1.Final.TestEntity)));
                }
                finally {
                    if (domain != null)
                    {
                        domain.Dispose();
                    }
                }
            });
            using (var domain = Domain.Build(BuildConfiguration(false, typeof(model.V1.Initial.TestEntity))))
                using (var session = domain.OpenSession())
                    using (var transaction = session.OpenTransaction()) {
                        var entities = session.Query.All <model.V1.Initial.TestEntity>().ToList();
                        Assert.That(entities.Count, Is.EqualTo(10));
                    }
        }
        public void QueryPlanReusingTest()
        {
            Require.AnyFeatureSupported(ProviderFeatures.RowNumber | ProviderFeatures.NativePaging);
            Key customer0Key;
            Key customer1Key;

            using (var session = Domain.OpenSession())
                using (var tx = session.OpenTransaction()) {
                    customer0Key = session.Query.All <Customer>().OrderBy(c => c.Id).First().Key;
                    customer1Key = session.Query.All <Customer>().OrderBy(c => c.Id).Skip(1).First().Key;
                }

            using (var session = Domain.OpenSession())
                using (session.OpenTransaction()) {
                    var prefetchManager = (PrefetchManager)PrefetchProcessorField.GetValue(session.Handler);
                    prefetchManager.InvokePrefetch(customer0Key, null, new PrefetchFieldDescriptor(CityField));
                    prefetchManager.ExecuteTasks(true);

                    prefetchManager.InvokePrefetch(customer1Key, null, new PrefetchFieldDescriptor(CityField));
                    prefetchManager.ExecuteTasks(true);
                }
        }
Beispiel #13
0
        public void ElementAtIsRootTest()
        {
            Require.AnyFeatureSupported(ProviderFeatures.RowNumber | ProviderFeatures.NativePaging);
            var customers = Session.Query.All <Customer>().ToList();

            Assert.IsTrue(customers.Count > 0);
            for (int i = -100; i < customers.Count + 100; i++)
            {
                if (i < 0)
                {
                    int index = i;
                    AssertEx.ThrowsArgumentOutOfRangeException(() => Session.Query.All <Customer>().ElementAt(index));
                }
                else if (i >= customers.Count)
                {
                    int index = i;
                    AssertEx.ThrowsInvalidOperationException(() => Session.Query.All <Customer>().ElementAt(index));
                }
                else
                {
                    Assert.AreEqual(customers[i], Session.Query.All <Customer>().ElementAt(i));
                }
            }
        }
Beispiel #14
0
        public void ReuseElementAt2Test()
        {
            Require.AnyFeatureSupported(ProviderFeatures.RowNumber | ProviderFeatures.NativePaging);
            var customers = Session.Query.All <Customer>().OrderBy(customer => customer.CustomerId).ToList();

            Assert.IsTrue(customers.Count > 0);
            for (int i = -100; i < customers.Count + 100; i++)
            {
                if (i < 0)
                {
                    int index = i;
                    AssertEx.ThrowsInvalidOperationException(() => ElementAtCorrect(index));
                }
                else if (i >= customers.Count)
                {
                    int index = i;
                    AssertEx.ThrowsInvalidOperationException(() => ElementAtCorrect(index));
                }
                else
                {
                    Assert.AreEqual(customers[i], ElementAtCorrect(i));
                }
            }
        }
Beispiel #15
0
 private void CheckRequirements()
 {
     Require.AnyFeatureSupported(ProviderFeatures.FullTextColumnDataTypeSpecification);
 }
Beispiel #16
0
 protected override void CheckRequirements()
 {
     base.CheckRequirements();
     Require.AnyFeatureSupported(ProviderFeatures.RowNumber | ProviderFeatures.NativePaging);
 }
Beispiel #17
0
        public void UpgradeGeneratorsTest()
        {
            Require.AnyFeatureSupported(ProviderFeatures.Sequences | ProviderFeatures.ArbitraryIdentityIncrement);

            var generatorCacheSize = 3;

            BuildDomain("1", DomainUpgradeMode.Recreate, generatorCacheSize, typeof(Address), typeof(Person));
            using (var session = domain.OpenSession()) {
                using (var t = session.OpenTransaction()) {
                    for (int i = 0; i < generatorCacheSize; i++)
                    {
                        new Person {
                            Address = new Address {
                                City = "City", Country = "Country"
                            }
                        }
                    }
                    ;
                    Assert.LessOrEqual(session.Query.All <Person>().Max(p => p.Id), 4);
                    Assert.GreaterOrEqual(session.Query.All <Person>().Max(p => p.Id), 3);
                    t.Complete();
                }
            }
            BuildDomain("1", DomainUpgradeMode.Perform, generatorCacheSize, typeof(Address), typeof(Person));
            using (var session = domain.OpenSession()) {
                using (var t = session.OpenTransaction()) {
                    for (int i = 0; i < generatorCacheSize; i++)
                    {
                        new Person {
                            Address = new Address {
                                City = "City", Country = "Country"
                            }
                        }
                    }
                    ;
                    Assert.LessOrEqual(session.Query.All <Person>().Max(p => p.Id), 8);
                    Assert.GreaterOrEqual(session.Query.All <Person>().Max(p => p.Id), 6);
                    t.Complete();
                }
            }

            generatorCacheSize = 2;
            BuildDomain("1", DomainUpgradeMode.Perform, generatorCacheSize, typeof(Address), typeof(Person));
            using (var session = domain.OpenSession()) {
                using (var t = session.OpenTransaction()) {
                    new Person {
                        Address = new Address {
                            City = "City", Country = "Country"
                        }
                    };
                    new Person {
                        Address = new Address {
                            City = "City", Country = "Country"
                        }
                    };
                    new Person {
                        Address = new Address {
                            City = "City", Country = "Country"
                        }
                    };
                    Assert.LessOrEqual(session.Query.All <Person>().Max(p => p.Id), 13);
                    Assert.GreaterOrEqual(session.Query.All <Person>().Max(p => p.Id), 12);
                    t.Complete();
                }
            }
        }
Beispiel #18
0
 protected override void CheckRequirements()
 => Require.AnyFeatureSupported(ProviderFeatures.TemporaryTableEmulation | ProviderFeatures.TemporaryTables);
 public void FixtureSetUp()
 {
     Require.AnyFeatureSupported(ProviderFeatures.DateTimeOffset | ProviderFeatures.DateTimeOffsetEmulation);
 }
        protected static readonly TimeSpan WrongOffset = new TimeSpan(4, 35, 0); // +04:35

        protected override void CheckRequirements()
        {
            Require.AnyFeatureSupported(ProviderFeatures.DateTimeOffset | ProviderFeatures.DateTimeOffsetEmulation);
        }