public void ValidateSQLTranslationComplexData() { string constString = "s"; int[] array = { 1, 2, 3 }; var paramx = Expression.Parameter(typeof(int), "x"); const int Records = 100; const int MaxArraySize = 10; const int MaxStringLength = 50; Func <Random, complex> createDataObj = (random) => { var obj = new complex(); obj.b = random.NextDouble() < 0.5; obj.dbl = random.NextDouble(); obj.dblArray = new double[random.Next(MaxArraySize)]; for (int i = 0; i < obj.dblArray.Length; ++i) { obj.dblArray[i] = random.NextDouble() < 0.1 ? 3 : random.NextDouble(); } obj.inside = new simple() { x = random.Next(), y = random.Next() }; obj.str = random.NextDouble() < 0.1 ? "5" : LinqTestsCommon.RandomString(random, random.Next(MaxStringLength)); obj.id = Guid.NewGuid().ToString(); obj.pk = "Test"; return(obj); }; var getQuery = LinqTestsCommon.GenerateTestCosmosData <complex>(createDataObj, Records, testContainer); var inputs = new List <LinqTestInput>(); inputs.Add(new LinqTestInput("Select equality", b => getQuery(b).Select(s => s.str == "5"))); inputs.Add(new LinqTestInput("Select string concat", b => getQuery(b).Select(d => "x" + d.str))); inputs.Add(new LinqTestInput("Select string concat w const", b => getQuery(b).Select(d => "x" + constString + d.str))); inputs.Add(new LinqTestInput("SelectMany array", b => getQuery(b).SelectMany(d => d.dblArray))); inputs.Add(new LinqTestInput("SelectMany array property -> Filter x -> Select x expr", b => getQuery(b).SelectMany(z => z.dblArray).Where(x => x > 2).Select(x => x + 2))); inputs.Add(new LinqTestInput("SelectMany array property -> Filter x equality -> Select x expr", b => getQuery(b).SelectMany(z => z.dblArray.Where(x => x == 3).Select(x => x + 1)))); inputs.Add(new LinqTestInput("SelectMany array property -> Select identity", b => getQuery(b).SelectMany(d => d.dblArray.Select(x => x)))); inputs.Add(new LinqTestInput("SelectMany array property", b => getQuery(b).SelectMany(d => d.dblArray))); inputs.Add(new LinqTestInput("SelectMany array property -> Select x expr", b => getQuery(b).SelectMany(z => z.dblArray.Select(x => z.dbl + x)))); inputs.Add(new LinqTestInput("SelectMany array property -> Select new", b => getQuery(b).SelectMany(z => z.dblArray.Select(x => new { z.b, x = Math.Truncate(x * 100) })))); inputs.Add(new LinqTestInput("SelectMany identity", b => getQuery(b).SelectMany(x => x.dblArray))); inputs.Add(new LinqTestInput("SelectMany x -> Select y", b => getQuery(b).SelectMany(x => x.dblArray.Select(y => y)))); inputs.Add(new LinqTestInput("SelectMany x -> Select x.y", b => getQuery(b).SelectMany(x => x.dblArray.Select(y => y)))); inputs.Add(new LinqTestInput("SelectMany array", b => getQuery(b).SelectMany(x => x.dblArray))); this.ExecuteTestSuite(inputs); }
public static Func <bool, IQueryable <Family> > GenerateFamilyCosmosData( Cosmos.Database cosmosDatabase, out Container container) { // The test collection should have range index on string properties // for the orderby tests PartitionKeyDefinition partitionKeyDefinition = new PartitionKeyDefinition { Paths = new System.Collections.ObjectModel.Collection <string>(new[] { "/Pk" }), Kind = PartitionKind.Hash }; var newCol = new ContainerProperties() { Id = Guid.NewGuid().ToString(), PartitionKey = partitionKeyDefinition, IndexingPolicy = new Microsoft.Azure.Cosmos.IndexingPolicy() { IncludedPaths = new Collection <Cosmos.IncludedPath>() { new Cosmos.IncludedPath() { Path = "/*", Indexes = new System.Collections.ObjectModel.Collection <Microsoft.Azure.Cosmos.Index>() { Microsoft.Azure.Cosmos.Index.Range(Microsoft.Azure.Cosmos.DataType.Number, -1), Microsoft.Azure.Cosmos.Index.Range(Microsoft.Azure.Cosmos.DataType.String, -1) } } }, CompositeIndexes = new Collection <Collection <Cosmos.CompositePath> >() { new Collection <Cosmos.CompositePath>() { new Cosmos.CompositePath() { Path = "/FamilyId", Order = Cosmos.CompositePathSortOrder.Ascending }, new Cosmos.CompositePath() { Path = "/Int", Order = Cosmos.CompositePathSortOrder.Ascending } }, new Collection <Cosmos.CompositePath>() { new Cosmos.CompositePath() { Path = "/FamilyId", Order = Cosmos.CompositePathSortOrder.Ascending }, new Cosmos.CompositePath() { Path = "/Int", Order = Cosmos.CompositePathSortOrder.Descending } }, new Collection <Cosmos.CompositePath>() { new Cosmos.CompositePath() { Path = "/FamilyId", Order = Cosmos.CompositePathSortOrder.Ascending }, new Cosmos.CompositePath() { Path = "/Int", Order = Cosmos.CompositePathSortOrder.Ascending }, new Cosmos.CompositePath() { Path = "/IsRegistered", Order = Cosmos.CompositePathSortOrder.Descending } }, new Collection <Cosmos.CompositePath>() { new Cosmos.CompositePath() { Path = "/Int", Order = Cosmos.CompositePathSortOrder.Ascending }, new Cosmos.CompositePath() { Path = "/IsRegistered", Order = Cosmos.CompositePathSortOrder.Descending } }, new Collection <Cosmos.CompositePath>() { new Cosmos.CompositePath() { Path = "/IsRegistered", Order = Cosmos.CompositePathSortOrder.Ascending }, new Cosmos.CompositePath() { Path = "/Int", Order = Cosmos.CompositePathSortOrder.Descending } } } } }; container = cosmosDatabase.CreateContainerAsync(newCol).Result; const int Records = 100; const int MaxNameLength = 100; const int MaxThingStringLength = 50; const int MaxChild = 5; const int MaxPets = MaxChild; const int MaxThings = MaxChild; const int MaxGrade = 101; const int MaxTransaction = 20; const int MaxTransactionMinuteRange = 200; int MaxTransactionType = Enum.GetValues(typeof(TransactionType)).Length; Family createDataObj(Random random) { var obj = new Family { FamilyId = random.NextDouble() < 0.05 ? "some id" : Guid.NewGuid().ToString(), IsRegistered = random.NextDouble() < 0.5, NullableInt = random.NextDouble() < 0.5 ? (int?)random.Next() : null, Int = random.NextDouble() < 0.5 ? 5 : random.Next(), Id = Guid.NewGuid().ToString(), Pk = "Test", Parents = new Parent[random.Next(2) + 1] }; for (int i = 0; i < obj.Parents.Length; ++i) { obj.Parents[i] = new Parent() { FamilyName = LinqTestsCommon.RandomString(random, random.Next(MaxNameLength)), GivenName = LinqTestsCommon.RandomString(random, random.Next(MaxNameLength)) }; } obj.Tags = new string[random.Next(MaxChild)]; for (int i = 0; i < obj.Tags.Length; ++i) { obj.Tags[i] = (i + random.Next(30, 36)).ToString(); } obj.Children = new Child[random.Next(MaxChild)]; for (int i = 0; i < obj.Children.Length; ++i) { obj.Children[i] = new Child() { Gender = random.NextDouble() < 0.5 ? "male" : "female", FamilyName = obj.Parents[random.Next(obj.Parents.Length)].FamilyName, GivenName = LinqTestsCommon.RandomString(random, random.Next(MaxNameLength)), Grade = random.Next(MaxGrade) }; obj.Children[i].Pets = new List <Pet>(); for (int j = 0; j < random.Next(MaxPets); ++j) { obj.Children[i].Pets.Add(new Pet() { GivenName = random.NextDouble() < 0.5 ? LinqTestsCommon.RandomString(random, random.Next(MaxNameLength)) : "Fluffy" }); } obj.Children[i].Things = new Dictionary <string, string>(); for (int j = 0; j < random.Next(MaxThings) + 1; ++j) { obj.Children[i].Things.Add( j == 0 ? "A" : $"{j}-{random.Next().ToString()}", LinqTestsCommon.RandomString(random, random.Next(MaxThingStringLength))); } } obj.Records = new Logs { LogId = LinqTestsCommon.RandomString(random, random.Next(MaxNameLength)), Transactions = new Transaction[random.Next(MaxTransaction)] }; for (int i = 0; i < obj.Records.Transactions.Length; ++i) { var transaction = new Transaction() { Amount = random.Next(), Date = DateTime.Now.AddMinutes(random.Next(MaxTransactionMinuteRange)), Type = (TransactionType)(random.Next(MaxTransactionType)) }; obj.Records.Transactions[i] = transaction; } return(obj); } Func <bool, IQueryable <Family> > getQuery = LinqTestsCommon.GenerateTestCosmosData(createDataObj, Records, container); return(getQuery); }
internal static Func <bool, IQueryable <Family> > GenerateFamilyData( DocumentClient client, CosmosDatabaseSettings testDb, out CosmosContainerSettings testCollection) { // The test collection should have range index on string properties // for the orderby tests var newCol = new CosmosContainerSettings() { Id = Guid.NewGuid().ToString(), IndexingPolicy = new IndexingPolicy() { IncludedPaths = new System.Collections.ObjectModel.Collection <IncludedPath>() { new IncludedPath() { Path = "/*", Indexes = new System.Collections.ObjectModel.Collection <Index>() { Index.Range(DataType.Number, -1), Index.Range(DataType.String, -1) } } } } }; testCollection = client.CreateDocumentCollectionAsync(testDb, newCol).Result; const int Records = 100; const int MaxNameLength = 100; const int MaxThingStringLength = 50; const int MaxChild = 5; const int MaxPets = MaxChild; const int MaxThings = MaxChild; const int MaxGrade = 101; Func <Random, Family> createDataObj = random => { var obj = new Family(); obj.FamilyId = random.NextDouble() < 0.05 ? "some id" : Guid.NewGuid().ToString(); obj.IsRegistered = random.NextDouble() < 0.5; obj.NullableInt = random.NextDouble() < 0.5 ? (int?)random.Next() : null; obj.Int = random.NextDouble() < 0.5 ? 5 : random.Next(); obj.Parents = new Parent[random.Next(2) + 1]; for (int i = 0; i < obj.Parents.Length; ++i) { obj.Parents[i] = new Parent() { FamilyName = LinqTestsCommon.RandomString(random, random.Next(MaxNameLength)), GivenName = LinqTestsCommon.RandomString(random, random.Next(MaxNameLength)) }; } obj.Children = new Child[random.Next(MaxChild)]; for (int i = 0; i < obj.Children.Length; ++i) { obj.Children[i] = new Child() { Gender = random.NextDouble() < 0.5 ? "male" : "female", FamilyName = obj.Parents[random.Next(obj.Parents.Length)].FamilyName, GivenName = LinqTestsCommon.RandomString(random, random.Next(MaxNameLength)), Grade = random.Next(MaxGrade) }; obj.Children[i].Pets = new List <Pet>(); for (int j = 0; j < random.Next(MaxPets); ++j) { obj.Children[i].Pets.Add(new Pet() { GivenName = random.NextDouble() < 0.5 ? LinqTestsCommon.RandomString(random, random.Next(MaxNameLength)) : "Fluffy" }); } obj.Children[i].Things = new Dictionary <string, string>(); for (int j = 0; j < random.Next(MaxThings) + 1; ++j) { obj.Children[i].Things.Add( j == 0 ? "A" : $"{j}-{random.Next().ToString()}", LinqTestsCommon.RandomString(random, random.Next(MaxThingStringLength))); } } return(obj); }; Func <bool, IQueryable <Family> > getQuery = LinqTestsCommon.GenerateTestData(createDataObj, Records, client, testCollection); return(getQuery); }