Example #1
0
        public DeltaHashProvider(IDeltaCache deltaCache,
                                 ILogger logger,
                                 int capacity = 10_000)
        {
            _deltaCache = deltaCache;
            _logger     = logger;
            _deltaHashUpdatesSubject = new ReplaySubject <Cid>(0);
            var comparer = ComparerBuilder.For <Timestamp>().OrderBy(u => u, descending: true);

            _capacity = capacity;
            _hashesByTimeDescending = new SortedList <Timestamp, Cid>(comparer)
            {
                Capacity = _capacity
            };

            _hashesByTimeDescending.Add(Timestamp.FromDateTime(DateTime.MinValue.ToUniversalTime()),
                                        _deltaCache.GenesisHash);
        }
Example #2
0
        public void RecursiveInsertInto([CteContextSource(true, ProviderName.DB2)] string context)
        {
            var hierarchyData = GeHirarchyData();

            using (var db = GetDataContext(context))
            {
                using (var tree = db.CreateLocalTable(hierarchyData))
                    using (var resultTable = db.CreateLocalTable <HierarchyData>())
                    {
                        var hierarchy = GetHierarchyDown(tree, db);
                        hierarchy.Insert(resultTable, r => r);

                        var result   = resultTable.OrderBy(h => h.Id);
                        var expected = EnumerateDown(hierarchyData, 0, null).OrderBy(h => h.Id);

                        AreEqual(expected, result, ComparerBuilder <HierarchyData> .GetEqualityComparer());
                    }
            }
        }
Example #3
0
        public static IEqualityComparer <T> GetEqualityComparer <T>(
            this MappingSchema mappingSchema,
            [InstantHandle] Func <ColumnDescriptor, bool> columnPredicate)
        {
            if (mappingSchema == null)
            {
                throw new ArgumentNullException(nameof(mappingSchema));
            }
            if (columnPredicate == null)
            {
                throw new ArgumentNullException(nameof(columnPredicate));
            }

            var cols = new HashSet <MemberAccessor>(
                mappingSchema.GetEntityDescriptor(typeof(T)).Columns
                .Where(columnPredicate).Select(c => c.MemberAccessor));

            return(ComparerBuilder.GetEqualityComparer <T>(cols.Contains));
        }
Example #4
0
        public void SelectQueryFromList([IncludeDataSources(TestProvName.AllSQLite)] string context)
        {
            var items = new[]
            {
                new SampleClass {
                    Id = 1, Value = 11
                }, new SampleClass {
                    Id = 2, Value = 22
                },
                new SampleClass {
                    Id = 3, Value = 33
                }, new SampleClass {
                    Id = 4, Value = 44
                }
            };

            using (var db = GetDataContext(context))
            {
                IQueryable <SampleClass>?itemsQuery = null;

                for (int i = 0; i < items.Length; i++)
                {
                    var item    = items[i];
                    var current = i % 2 == 0
                                                ? db.SelectQuery(() => new SampleClass
                    {
                        Id    = item.Id,
                        Value = item.Value,
                    })
                                                : db.SelectQuery(() => new SampleClass
                    {
                        Value = item.Value,
                        Id    = item.Id,
                    });

                    itemsQuery = itemsQuery == null ? current : itemsQuery.Concat(current);
                }

                var result = itemsQuery !.AsCte().ToArray();

                AreEqual(items, result, ComparerBuilder.GetEqualityComparer <SampleClass>());
            }
        }
        public void TestUnionAll([IncludeDataSources(TestProvName.AllSQLite)] string context)
        {
            var testData = GenerateTestData();

            using (var db = GetDataContext(context))
                using (var table = db.CreateLocalTable(testData))
                {
                    var rs1   = table.Where(t => t.Id % 2 == 0);
                    var rs2   = table.Where(t => t.Id % 4 == 0);
                    var query = rs1.UnionAll(rs2);

                    var e1       = testData.AsQueryable().Where(t => t.Id % 2 == 0);
                    var e2       = testData.AsQueryable().Where(t => t.Id % 4 == 0);
                    var expected = e1.UnionAll(e2).ToArray();
                    var actual   = query.ToArray();

                    AreEqual(expected, actual, ComparerBuilder.GetEqualityComparer <SampleData>());
                }
        }
Example #6
0
        public void NonCompileTestLocal([SQLiteDataSources] string context)
        {
            Expression <Func <SampleClass, bool> > predicate = c => c.Value > 1;
            var sampleData = GenerateData();

            using (var db = GetDataContext(context))
                using (var table = db.CreateLocalTable(sampleData))
                {
                    var query = from t in table
                                from t2 in table.Where(predicate)
                                select t;

                    var expected = from t in sampleData
                                   from t2 in table.Where(predicate)
                                   select t;

                    AreEqual(expected, query, ComparerBuilder <SampleClass> .GetEqualityComparer());
                }
        }
Example #7
0
        public void LocalInvocation([SQLiteDataSources] string context)
        {
            var sampleData = GenerateData();

            using (var db = GetDataContext(context))
                using (var table = db.CreateLocalTable(sampleData))
                {
                    var ids = new[] { 1, 2, 3, 4, 5, 6 };

                    var query = from t in table
                                where ids.Where(i => i < 3).GroupBy(i => i).Select(i => i.Key).Contains(t.Id)
                                select t;
                    var expected = from t in sampleData
                                   where ids.Where(i => i < 3).GroupBy(i => i).Select(i => i.Key).Contains(t.Id)
                                   select t;

                    AreEqual(expected, query, ComparerBuilder <SampleClass> .GetEqualityComparer());
                }
        }
Example #8
0
        public void Custom_comparer_should_be_used_for_collection_when_defined()
        {
            Test(() => {
                var x = _fixture.Create <ComparableObject <int[]> >();
                var y = _fixture.Create <ComparableObject <int[]> >();

                var referenceComparer = new ComparableObjectEqualityComparer <int[]>(new CustomizableEqualityComparer <int[]>(
                                                                                         (a, b) => a is null && b is null || !(a is null || b is null), _ => 0));
                var expected = referenceComparer.Equals(x, y);

                var equalsIsUsed = false;
                var hashIsUsed   = false;
                var comparer     = new ComparerBuilder(c => c
                                                       .SetDefaultCollectionsOrderIgnoring(_fixture.Create <bool>())
                                                       .SetCustomEqualityComparer(new CustomizableEqualityComparer <int>(
                                                                                      (__, _) => {
                    equalsIsUsed = true;
                    return(true);
                },
                                                                                      _ => {
                    hashIsUsed = true;
                    return(0);
                })))
                                   .GetEqualityComparer <ComparableObject <int[]> >();

                var actualEquals = comparer.Equals(x, y);
                var hashX        = comparer.GetHashCode(x);
                var hashY        = comparer.GetHashCode(y);

                using (new AssertionScope()) {
                    actualEquals.Should().Be(expected);
                    hashX.Should().NotBe(0);
                    hashY.Should().NotBe(0);
                    var fieldIsNull        = x.Field is null || y.Field is null;
                    var propertyIsNull     = x.Property is null || y.Property is null;
                    var fieldsAreNulls     = x.Field is null && y.Field is null;
                    var propertiesAreNulls = x.Property is null && y.Property is null;
                    equalsIsUsed.Should().Be(!fieldIsNull || fieldsAreNulls && !propertyIsNull, $"null checks are used.\n{x}\n{y}");
                    hashIsUsed.Should().Be(!fieldsAreNulls || !propertiesAreNulls, $"null checks are used.\n{x}\n{y}");
                }
            });
        }
        public void Enumerable_structs_with_nullables_are_comparable()
        {
            var referenceComparer =
                new CollectionComparer <SampleStruct <int?>?>(
                    new NullableComparer <SampleStruct <int?> >(new SampleStructComparer <int?>()));
            var comparer = new ComparerBuilder().GetComparer <EnumerableStruct <SampleStruct <int?>?> >();

            Helper.Parallel(() => {
                var x = _fixture.Create <EnumerableStruct <SampleStruct <int?>?> >();
                var y = _fixture.Create <EnumerableStruct <SampleStruct <int?>?> >();

                var expectedEquals = referenceComparer.Compare(x, y);
                var equals         = comparer.Compare(x, y);

                using (new AssertionScope()) {
                    comparer.Compare(x, x).Should().Be(0);
                    equals.Should().Be(expectedEquals);
                }
            });
        }
Example #10
0
        public async Task DeleteWithOutputAsyncTest([IncludeDataSources(true, TestProvName.AllSqlServer2008Plus)] string context, [Values(100, 200)] int param)
        {
            var sourceData = GetSourceData();

            using (var db = GetDataContext(context))
                using (var source = db.CreateLocalTable(sourceData))
                {
                    var expected = source
                                   .Where(s => s.Id > 3)
                                   .ToArray();

                    var output = await source
                                 .Where(s => s.Id > 3)
                                 .DeleteWithOutputAsync();

                    AreEqual(
                        expected,
                        output,
                        ComparerBuilder.GetEqualityComparer <TableWithData>());
                }
        }
Example #11
0
        public async Task DeleteWithOutputAsyncTestSingleRecord([IncludeDataSources(true, FeatureDeleteOutputSingle)] string context, [Values(100, 200)] int param)
        {
            var sourceData = GetSourceData();

            using (var db = GetDataContext(context))
                using (var source = db.CreateLocalTable(sourceData))
                {
                    var expected = source
                                   .Where(s => s.Id == 3)
                                   .ToArray();

                    var output = await source
                                 .Where(s => s.Id == 3)
                                 .DeleteWithOutputAsync();

                    AreEqual(
                        expected,
                        output,
                        ComparerBuilder.GetEqualityComparer <TableWithData>());
                }
        }
Example #12
0
        public void TestExcept([DataSources(ProviderName.SqlServer2000)] string context)
        {
            var testData = GenerateTestData();

            using (var db = GetDataContext(context))
                using (var table = db.CreateLocalTable(testData))
                {
                    var rs1 = table.Where(t => t.Id % 2 == 0);
                    rs1 = rs1.Concat(rs1);
                    var rs2   = table.Where(t => t.Id % 4 == 0);
                    var query = rs1.Except(rs2);

                    var e1 = testData.Where(t => t.Id % 2 == 0);
                    e1 = e1.Concat(e1);
                    var e2       = testData.Where(t => t.Id % 4 == 0);
                    var expected = e1.Except(e2).ToArray();
                    var actual   = query.ToArray();

                    AreEqual(expected, actual, ComparerBuilder.GetEqualityComparer <SampleData>());
                }
        }
        public void Test_Patient_SelectAll([IncludeDataSources(TestProvName.AllAccess)] string context)
        {
            using (var db = new TestDataConnection(context))
                using (db.BeginTransaction())
                {
                    var res = Patient_SelectAll(db, context == ProviderName.AccessOdbc);

                    AreEqual(
                        db.Patient.Select(p => new PatientResult()
                    {
                        PersonID   = p.Person.ID,
                        FirstName  = p.Person.FirstName,
                        LastName   = p.Person.LastName,
                        MiddleName = p.Person.MiddleName,
                        Gender     = p.Person.Gender,
                        Diagnosis  = p.Diagnosis
                    }).OrderBy(_ => _.PersonID),
                        res.OrderBy(_ => _.PersonID),
                        ComparerBuilder.GetEqualityComparer <PatientResult>());
                }
        }
        public void After_change_custom_comparer_new_dynamic_comparer_should_be_created()
        {
            Test(() => {
                var x         = _fixture.Create <Tuple <int, string> >();
                var y         = _fixture.Create <Tuple <int, string> >();
                var expected1 = x.Item1.CompareTo(y.Item1);
                var expected2 = x.Item2?.CompareTo(y.Item2) ?? -y.Item2?.CompareTo(null) ?? 0;

                var builder   = new ComparerBuilder(c => c.SetCustomComparer(new CustomizableComparer <string>((__, _) => 0)));
                var comparer1 = builder.GetComparer <Tuple <int, string> >();
                var comparer2 =
                    builder.Configure(c => c.SetCustomComparer <string>(null)
                                      .SetCustomComparer(new CustomizableComparer <int>((__, _) => 0)))
                    .GetComparer <Tuple <int, string> >();

                using (new AssertionScope()) {
                    comparer1.Compare(x, y).Normalize().Should().Be(expected1.Normalize());
                    comparer2.Compare(x, y).Normalize().Should().Be(expected2.Normalize());
                }
            });
        }
Example #15
0
        public void Test([IncludeDataSources(ProviderName.SQLite, ProviderName.SQLiteClassic, ProviderName.SQLiteMS)] string context)
        {
            var typeId = Guid.NewGuid();

            var resources = new[] { new WmsResourceTypeDTO {
                                        Depth = 256, Height = 110, Id = typeId, Name = "Resource Name", ShortName = "RN", Width = 333
                                    } };

            var carriersA = new[] { new WmsLoadCarrierDTO {
                                        Id = Guid.NewGuid(), TypeID = typeId
                                    } };
            var carriersB = new[] { new WmsLoadCarrierDTO {
                                        Id = Guid.NewGuid(), TypeID = typeId
                                    } };

            using (var db = GetDataContext(context))
                using (db.CreateLocalTable <WmsResourceTypeDTO>(resources))
                    using (db.CreateLocalTable <WmsLoadCarrierDTO>(carriersA))
                        using (db.CreateLocalTable <WmsLoadCarrierDTO>("WMS_ResourceA", carriersB))
                        {
                            var qryUnion = from res in db.GetTable <WmsLoadCarrierDTO>().Union(db.GetTable <WmsLoadCarrierDTO>().TableName("WMS_ResourceA"))
                                           join type in db.GetTable <WmsResourceTypeDTO>() on res.TypeID equals type.Id into tpList
                                           from tp in tpList.DefaultIfEmpty()
                                           select new WmsResourceCombinedDTO {
                                LoadCarrier = res, ResourceType = tp
                            };

                            var staticResult = from res in carriersA.Union(carriersB)
                                               join type in resources on res.TypeID equals type.Id into tpList
                                               from tp in tpList.DefaultIfEmpty()
                                               select new WmsResourceCombinedDTO {
                                LoadCarrier = res, ResourceType = tp
                            };

                            var actual   = qryUnion.ToArray();
                            var expected = staticResult.ToArray();

                            AreEqual(expected, actual, ComparerBuilder <WmsResourceCombinedDTO> .GetEqualityComparer());
                        }
        }
Example #16
0
        public void InvocationTestByInvoke([SQLiteDataSources] string context, [Values(1, 2)] int param)
        {
            var sampleData = GenerateData();

            Expression <Func <int, int, int> > func = (p1, p2) => p1 * 10 + p2 * 2;

            using (var db = GetDataContext(context))
                using (var table = db.CreateLocalTable(sampleData))
                {
                    var query = table.AsQueryable();

                    query.Set(q => q.Value, q => func.Compile()(param, q.Value)).Update();

                    var compiled = func.Compile();
                    foreach (var sd in sampleData)
                    {
                        sd.Value = compiled(param, sd.Value);
                    }

                    AreEqual(sampleData, query, ComparerBuilder <SampleClass> .GetEqualityComparer());
                }
        }
        public void Compare_enumerables_of_enumerables()
        {
            var collectionComparer = new CollectionComparer <List <int?> >(new CollectionComparer <int?>());
            var referenceComparer  = new CollectionComparer <EnumerableStruct <List <int?> >?>(
                new NullableComparer <EnumerableStruct <List <int?> > >(
                    new CustomizableComparer <EnumerableStruct <List <int?> > >((a, b) =>
                                                                                collectionComparer.Compare(a, b))));
            var comparer = new ComparerBuilder().GetComparer <IEnumerable <EnumerableStruct <List <int?> >?> >();

            Helper.Parallel(() => {
                var x = _fixture.CreateMany <EnumerableStruct <List <int?> >?>().RandomNulls().ToList();
                var y = _fixture.CreateMany <EnumerableStruct <List <int?> >?>().RandomNulls().ToList();

                var expectedEquals = referenceComparer.Compare(x, y);
                var equals         = comparer.Compare(x, y);

                using (new AssertionScope()) {
                    comparer.Compare(x, x).Should().Be(0);
                    equals.Should().Be(expectedEquals);
                }
            });
        }
Example #18
0
        public void DeleteWithOutputTest([IncludeDataSources(true, FeatureDeleteOutputMultiple)] string context, [Values(100, 200)] int param)
        {
            var sourceData = GetSourceData();

            using (var db = GetDataContext(context))
                using (var source = db.CreateLocalTable(sourceData))
                {
                    var expected = source
                                   .Where(s => s.Id > 3)
                                   .ToArray();

                    var output = source
                                 .Where(s => s.Id > 3)
                                 .DeleteWithOutput()
                                 .ToArray();

                    AreEqual(
                        expected,
                        output,
                        ComparerBuilder.GetEqualityComparer <TableWithData>());
                }
        }
Example #19
0
        public void TestConcatInheritance([IncludeDataSources(ProviderName.SQLiteClassic)] string context)
        {
            var testData = new BaseEntity[]
            {
                new BaseEntity {
                    Discr = 0, EntityId = 1, Value = "VBase1"
                },
                new BaseEntity {
                    Discr = 0, EntityId = 2, Value = "VBase2"
                },
                new BaseEntity {
                    Discr = 0, EntityId = 3, Value = "VBase3"
                },

                new DerivedEntity {
                    Discr = 1, EntityId = 10, Value = "Derived1"
                },
                new DerivedEntity {
                    Discr = 1, EntityId = 20, Value = "Derived2"
                },
                new DerivedEntity {
                    Discr = 1, EntityId = 30, Value = "Derived3"
                }
            };

            using (var db = GetDataContext(context))
                using (db.CreateLocalTable(testData))
                {
                    var result = db.GetTable <BaseEntity>().OfType <BaseEntity>()
                                 .Concat(db.GetTable <BaseEntity>().OfType <DerivedEntity>())
                                 .ToArray();

                    var expected = testData.Where(t => t.GetType() == typeof(BaseEntity))
                                   .Concat(testData.OfType <DerivedEntity>())
                                   .ToArray();

                    AreEqual(expected, result, ComparerBuilder <BaseEntity> .GetEqualityComparer());
                }
        }
        public void Should_use_delayed_comparison()
        {
            var x = _fixture.CreateMany <SampleEqualityStruct <EnumSmall?>?>().ToArray();
            var y = _fixture.CreateMany <SampleEqualityStruct <EnumSmall?>?>().ToArray();

            var referenceComparer = new CollectionEqualityComparer <SampleEqualityStruct <EnumSmall?>?>(
                new NullableEqualityComparer <SampleEqualityStruct <EnumSmall?> >());

            var comparer = new ComparerBuilder().GetEqualityComparer <object>();

            var expectedHashX = referenceComparer.GetHashCode(x);
            var expectedHashY = referenceComparer.GetHashCode(y);
            var actualHashX   = comparer.GetHashCode(x);
            var actualHashY   = comparer.GetHashCode(y);
            var expected      = referenceComparer.Equals(x, y);
            var actual        = comparer.Equals(x, y);

            using (new AssertionScope()) {
                actualHashX.Should().Be(expectedHashX);
                actualHashY.Should().Be(expectedHashY);
                actual.Should().Be(expected);
            }
        }
Example #21
0
        public void After_clean_custom_comparer_for_value_type_dynamic_comparer_should_be_created()
        {
            var x = _fixture.Create <ComparableObject <ComparableStruct <string> > >();
            var y = _fixture.Create <ComparableObject <ComparableStruct <string> > >();

            var reference          = new ComparableObjectEqualityComparer <ComparableStruct <string> >(new ComparableStructEqualityComparer <string>());
            var expectedEquals     = reference.Equals(x, y);
            var expectedHash       = reference.GetHashCode(x);
            var expectedCustomHash = HashCodeCombiner.Combine(0, 0);

            var builder         = new ComparerBuilder(c => c.SetCustomEqualityComparer <SampleStructCustomEqualityComparer>());
            var comparerCustom  = builder.GetEqualityComparer <ComparableObject <ComparableStruct <string> > >();
            var comparerDefault =
                builder.Configure(c => c.SetCustomEqualityComparer <ComparableStruct <string> >(null))
                .GetEqualityComparer <ComparableObject <ComparableStruct <string> > >();

            using (new AssertionScope()) {
                comparerCustom.Equals(x, y).Should().BeTrue();
                comparerCustom.GetHashCode(x).Should().Be(expectedCustomHash);
                comparerDefault.Equals(x, y).Should().Be(expectedEquals);
                comparerDefault.GetHashCode(x).Should().Be(expectedHash);
            }
        }
        public void Custom_comparer_should_be_used_for_collection_when_defined()
        {
            Test(() => {
                var x = _fixture.Create <SampleObject <int[]> >();
                var y = _fixture.Create <SampleObject <int[]> >();

                var referenceComparer = new SampleObjectComparer <int[]>(new CustomizableComparer <int[]>((a, b) => {
                    if (a == b)
                    {
                        return(0);
                    }

                    if (b is null)
                    {
                        return(1);
                    }

                    if (a is null)
                    {
                        return(-1);
                    }

                    return(0);
                }));
                var expected = referenceComparer.Compare(x, y);

                var comparer =
                    new ComparerBuilder(c => c.SetDefaultCollectionsOrderIgnoring(_fixture.Create <bool>())
                                        .SetCustomComparer(new CustomizableComparer <int>((__, _) => 0)))
                    .GetComparer <SampleObject <int[]> >();

                var actual = comparer.Compare(x, y);

                actual.Should().Be(expected);
            });
        }
Example #23
0
        public void StringComparer_Null()
        {
            var frameworkStringComparer  = StringComparer.Ordinal;
            var frameworkDefaultComparer = EqualityComparer <string> .Default;
            var nitoStringComparer       = ComparerBuilder.For <string>().OrderBy(x => x, StringComparer.Ordinal);

            // The string comparer allows equating to null
            Assert.True(frameworkStringComparer.Equals(null, null));
            Assert.False(frameworkStringComparer.Equals("test", null));

            // But throws if null is passed to GetHashCode
            //   https://github.com/dotnet/corefx/blob/36e812b0e974fa113c50be71e1701735a8a63481/src/Common/src/CoreLib/System/StringComparer.cs#L150-L153
            Assert.ThrowsAny <ArgumentException>(() => frameworkStringComparer.GetHashCode(null));

            // The framework default comparer does not throw
            Assert.True(frameworkDefaultComparer.Equals(null, null));
            Assert.False(frameworkDefaultComparer.Equals("test", null));
            frameworkDefaultComparer.GetHashCode(null);

            // And neither does the Nito string comparer wrapper.
            Assert.True(nitoStringComparer.Equals(null, null));
            Assert.False(nitoStringComparer.Equals("test", null));
            nitoStringComparer.GetHashCode(null);
        }
Example #24
0
        public void TestIntersectAll([DataSources] string context)
        {
            var testData = GenerateTestData();

            using (var db = GetDataContext(context))
                using (var table = db.CreateLocalTable(testData))
                {
                    var rs1 = table.Where(t => t.Id % 2 == 0);
                    rs1 = rs1.Concat(rs1);
                    var rs2   = table.Where(t => t.Id % 4 == 0);
                    var query = rs1.IntersectAll(rs2);

                    var e1 = testData.Where(t => t.Id % 2 == 0);
                    e1 = e1.Concat(e1);
                    var e2       = testData.Where(t => t.Id % 4 == 0);
                    var expected = e1.Where(e => e2.Contains(e, ComparerBuilder.GetEqualityComparer <SampleData>())).ToArray();
                    var actual   = query.ToArray();

                    if (!context.Contains(ProviderName.PostgreSQL))             // postgres has a bug?
                    {
                        AreEqual(expected, actual, ComparerBuilder.GetEqualityComparer <SampleData>());
                    }
                }
        }
Example #25
0
 protected void AreEqualWithComparer <T>(IEnumerable <T> expected, IEnumerable <T> result, Func <MemberAccessor, bool> memberPredicate)
 {
     AreEqual(t => t, expected, result, ComparerBuilder.GetEqualityComparer <T>(memberPredicate));
 }
Example #26
0
 protected void AreEqualWithComparer <T>(IEnumerable <T> expected, IEnumerable <T> result)
 {
     AreEqual(t => t, expected, result, ComparerBuilder.GetEqualityComparer <T>());
 }
Example #27
0
        public void TestComparerBuilder()
        {
            // Create two identical lists, save for the order.
            IEnumerable<Tester> a = new List<Tester>
            {
                new Tester(1, 2),
                new Tester(14, 432),
                new Tester(4, 10),
                new Tester(3, 4),
                new Tester(10, 12)
            };
            IEnumerable<Tester> b = new List<Tester>
            {
                new Tester(1, 2),
                new Tester(3, 4),
                new Tester(4, 10),
                new Tester(10, 12),
                new Tester(14, 432)
            };

            // Create comparer that compares A then B
            ComparerBuilder<Tester> comparer =
                new ComparerBuilder<Tester>((x, y) => (x.A != y.A) ? x.B.CompareTo(y.B) : x.A.CompareTo(y.A));

            Assert.IsFalse(b.SequenceEqual(a, comparer));

            // Sort using the comparer
            IOrderedEnumerable<Tester> c = a.OrderBy(t => t, comparer);

            // Now check sequence equality again
            Assert.IsTrue(b.SequenceEqual(c, comparer));
        }
Example #28
0
        public void ForElementsOfT_ReturnsBuilderForT_WithoutEnumeratingSequence()
        {
            var result = ComparerBuilder.ForElementsOf(ThrowEnumerable());

            Assert.IsType <ComparerBuilderFor <int> >(result);
        }
Example #29
0
        public void ForT_ReturnsBuilderForT()
        {
            var result = ComparerBuilder.For <int>();

            Assert.IsType <ComparerBuilderFor <int> >(result);
        }
Example #30
0
 /// <summary>
 /// Sort the element of a queryable sequence by a given sort expression.
 /// </summary>
 /// <typeparam name="T">Type of items in sequence.</typeparam>
 /// <param name="source">Sequence to be sorted.</param>
 /// <param name="sortExpression">A SQL-like sort expression with comma separated property names (and optional direction specifiers) (e.g. "Age DESC, Name")</param>
 /// <returns>A queryable object that can enumerate the elements in the input sequence ordered according to the given sort expression.</returns>
 /// <exception cref="System.ArgumentNullException"><paramref name="source"/> is null or <paramref name="sortExpression"/> is null</exception>
 /// <exception cref="ParserException">If <paramref name="sortExpression"/> is an invalid sort expression.</exception>
 public static IOrderedQueryable OrderBy(this IQueryable source, String sortExpression)
 {
     return(ComparerBuilder.OrderBy(source.ElementType, source, sortExpression));
 }