public void ManyToManyRelationshipAttributeSingleEntity()
        {
            // Asserts if the query result for a simple binary join is equal
            // to a handcrafted query
            var ModelData = QueryBuilderParser.ParseMapping(Utils.ReadMappingFile("Mappings/many-to-many-relationship-attribute-single-entity.mapping"));

            // Load handcrafted query
            string HandcraftedQuery = Utils.ReadQueryFromFile("HandcraftedQueries/manyToManyRelationshipAttributes.js");

            // Assert if the handcrafted query is not null
            Assert.IsNotNull(HandcraftedQuery);

            // Prepare query generator
            string         QueryString = "from Person rjoin <Insurance> (Car) select *";
            QueryGenerator QueryGen    = QueryBuilderParser.ParseQuery(QueryString, ModelData);

            string GeneratedQuery = QueryGen.Run();

            // Assert if generated query is not null
            Assert.IsNotNull(GeneratedQuery);

            // Run Queries
            QueryRunner Runner = new QueryRunner("mongodb://localhost:27017", "researchManyToManyRelationshipAttributes");

            string HandcraftedResult = Runner.GetJSON(HandcraftedQuery);
            string GeneratedResult   = Runner.GetJSON(GeneratedQuery);

            // Check if either result is null
            Assert.IsNotNull(HandcraftedResult);
            Assert.IsNotNull(GeneratedResult);

            // Check if both results are equal
            Assert.IsTrue(JToken.DeepEquals(JToken.Parse(HandcraftedResult), JToken.Parse(GeneratedResult)));
        }
Esempio n. 2
0
        public void CartesianProduct()
        {
            // Asserts if the query result for a relationship join operation is equal
            // to a handcrafted query
            var ModelData = QueryBuilderParser.ParseMapping(Utils.ReadMappingFile("Mappings/cartesian.mapping"));

            // Load handcrafted query
            string HandcraftedQuery = Utils.ReadQueryFromFile("HandcraftedQueries/cartersianProduct-1.js");

            // Assert if the handcrafted query is not null
            Assert.IsNotNull(HandcraftedQuery);

            string         QueryString = "from Person cartesianproduct Car cartesianproduct Supplier select *";
            QueryGenerator QueryGen    = QueryBuilderParser.ParseQuery(QueryString, ModelData);

            string GeneratedQuery = QueryGen.Run();

            // Assert if generated query is not null
            Assert.IsNotNull(GeneratedQuery);

            // Run Queries
            QueryRunner Runner = new QueryRunner("mongodb://localhost:27017", "ceManyToMany2");

            string HandcraftedResult = Runner.GetJSON(HandcraftedQuery);
            string GeneratedResult   = Runner.GetJSON(GeneratedQuery);

            // Check if either result is null
            Assert.IsNotNull(HandcraftedResult);
            Assert.IsNotNull(GeneratedResult);

            // Check if both results are equal
            Assert.IsTrue(JToken.DeepEquals(JToken.Parse(HandcraftedResult), JToken.Parse(GeneratedResult)));
        }
        public void ManyToManyTargetEmbedded()
        {
            var ModelData = QueryBuilderParser.ParseMapping(Utils.ReadMappingFile("Mappings/many-to-many-embedded-target.mapping"));

            // Load handcrafted query
            string HandcraftedQuery = Utils.ReadQueryFromFile("HandcraftedQueries/manyToManyEmbedded.js");

            // Assert if the handcrafted query is not null
            Assert.IsNotNull(HandcraftedQuery);

            string         QueryString = "from Person rjoin <Drives> (Car) select *";
            QueryGenerator QueryGen    = QueryBuilderParser.ParseQuery(QueryString, ModelData);

            string GeneratedQuery = QueryGen.Run();

            Assert.IsNotNull(GeneratedQuery);

            // Run Queries
            QueryRunner Runner = new QueryRunner("mongodb://localhost:27017", "manyToManyEmbedded");

            string HandcraftedResult = Runner.GetJSON(HandcraftedQuery);
            string GeneratedResult   = Runner.GetJSON(GeneratedQuery);

            // Check if either result is null
            Assert.IsNotNull(HandcraftedResult);
            Assert.IsNotNull(GeneratedResult);

            // Check if both results are equal
            Assert.IsTrue(JToken.DeepEquals(JToken.Parse(HandcraftedResult), JToken.Parse(GeneratedResult)));
        }
        public void OneToOneEmbeddedNoMasterAttribute()
        {
            // Asserts if the query result for a simple binary join is equal
            // to a handcrafted query
            var ModelData = QueryBuilderParser.ParseMapping(Utils.ReadMappingFile("Mappings/one-to-one-embedded-no-master-attribute.mapping"));

            // Load handcrafted query
            string HandcraftedQuery = Utils.ReadQueryFromFile("HandcraftedQueries/personCarOneToOne_3.js");

            // Assert if the handcrafted query is not null
            Assert.IsNotNull(HandcraftedQuery);

            // Prepare query generator
            string         QueryString = "from Person rjoin <Drives> (Car) select *";
            QueryGenerator QueryGen    = QueryBuilderParser.ParseQuery(QueryString, ModelData);

            string GeneratedQuery = QueryGen.Run();

            // Assert if generated query is not null
            Assert.IsNotNull(GeneratedQuery);

            // Run Queries
            QueryRunner Runner = new QueryRunner("mongodb://localhost:27017", "researchDatabase");

            string HandcraftedResult = Runner.GetJSON(HandcraftedQuery);
            string GeneratedResult   = Runner.GetJSON(GeneratedQuery);

            // Check if either result is null
            Assert.IsNotNull(HandcraftedResult);
            Assert.IsNotNull(GeneratedResult);

            // Check if both results are equal
            Assert.IsTrue(JToken.DeepEquals(JToken.Parse(HandcraftedResult), JToken.Parse(GeneratedResult)));
        }
        public void ManyToManyComputedEntityOneToOne()
        {
            // Asserts if the query result for a relationship join operation is equal
            // to a handcrafted query
            var ModelData = QueryBuilderParser.ParseMapping(Utils.ReadMappingFile("Mappings/many-to-many-computed-entity-2.mapping"));

            // Load handcrafted query
            string HandcraftedQuery = Utils.ReadQueryFromFile("HandcraftedQueries/ceManyToMany-2.js");

            // Assert if the handcrafted query is not null
            Assert.IsNotNull(HandcraftedQuery);

            // Prepare query generator
            string         QueryString = "from Person rjoin <Owns> (Car rjoin <ManufacturedBy> (Manufacturer)) select *";
            QueryGenerator QueryGen    = QueryBuilderParser.ParseQuery(QueryString, ModelData);
            // FIXED?

            string GeneratedQuery = QueryGen.Run();

            // Assert if generated query is not null
            Assert.IsNotNull(GeneratedQuery);

            // Run Queries
            QueryRunner Runner = new QueryRunner("mongodb://localhost:27017", "ceManyToMany2");

            string HandcraftedResult = Runner.GetJSON(HandcraftedQuery);
            string GeneratedResult   = Runner.GetJSON(GeneratedQuery);

            // Check if either result is null
            Assert.IsNotNull(HandcraftedResult);
            Assert.IsNotNull(GeneratedResult);

            // Check if both results are equal
            Assert.IsTrue(JToken.DeepEquals(JToken.Parse(HandcraftedResult), JToken.Parse(GeneratedResult)));
        }
Esempio n. 6
0
        public void OneToManyRelationshipAttributesEmbeddedAtSource()
        {
            // Load mapping
            var ModelData = QueryBuilderParser.ParseMapping(Utils.ReadMappingFile("Mappings/one-to-many-relationship-attributes-embedded-at-source.mapping"));

            string HandcraftedQuery = Utils.ReadQueryFromFile("HandcraftedQueries/oneToManyEmbeddedRelationshipAttributesAtSource.js");

            Assert.IsNotNull(HandcraftedQuery);

            string QueryString = "from Person rjoin <Drives> (Car) select *";

            QueryGenerator QueryGen = QueryBuilderParser.ParseQuery(QueryString, ModelData);

            string GeneratedQuery = QueryGen.Run();

            Assert.IsNotNull(GeneratedQuery);

            QueryRunner Runner = new QueryRunner("mongodb://localhost:27017", "paper_test_1");

            string HandcraftedResult = Runner.GetJSON(HandcraftedQuery);
            string GeneratedResult   = Runner.GetJSON(GeneratedQuery);

            // Check if either result is null
            Assert.IsNotNull(HandcraftedResult);
            Assert.IsNotNull(GeneratedResult);

            // Check if both results are equal
            Assert.IsTrue(JToken.DeepEquals(JToken.Parse(HandcraftedResult), JToken.Parse(GeneratedResult)));
        }
Esempio n. 7
0
        public void OneToManyEmbeddedWithRelatedMainMappingUseLookup()
        {
            // Load mapping
            var ModelData = QueryBuilderParser.ParseMapping(Utils.ReadMappingFile("Mappings/one-to-many-embedded-duplicated-main.mapping"));

            string HandcraftedQuery = Utils.ReadQueryFromFile("HandcraftedQueries/oneToManyEmbeddedDuplicatedMain.js");

            Assert.IsNotNull(HandcraftedQuery);

            string         QueryString = "from Person rjoin <Drives> (Car) select Person.name, Car.plate";
            QueryGenerator QueryGen    = QueryBuilderParser.ParseQuery(QueryString, ModelData);

            string GeneratedQuery = QueryGen.Run();

            Assert.IsNotNull(GeneratedQuery);

            QueryRunner Runner = new QueryRunner("mongodb://localhost:27017", "oneToManyEmbeddedDuplicatedMain");

            string HandcraftedResult = Runner.GetJSON(HandcraftedQuery);
            string GeneratedResult   = Runner.GetJSON(GeneratedQuery);

            // Check if either result is null
            Assert.IsNotNull(HandcraftedResult);
            Assert.IsNotNull(GeneratedResult);

            // Check if both results are equal
            Assert.IsTrue(JToken.DeepEquals(JToken.Parse(HandcraftedResult), JToken.Parse(GeneratedResult)));
        }
        public void ManyToManyComputedEntityMultipleEntities()
        {
            // Asserts if the query result for a relationship join operation is equal
            // to a handcrafted query
            RequiredDataContainer ModelData = ComputedEntityDataProvider.ManyToManyComputedEntity();

            // Load handcrafted query
            string HandcraftedQuery = Utils.ReadQueryFromFile("HandcraftedQueries/ceManyToMany.js");

            // Assert if the handcrafted query is not null
            Assert.IsNotNull(HandcraftedQuery);

            // Prepare query generator
            ComputedEntity CarRepairedByGarage = new ComputedEntity("CarRepairedByGarage",
                                                                    new QueryableEntity(( Entity)ModelData.EntityRelationshipModel.FindByName("Car"), "car"),
                                                                    (Relationship)ModelData.EntityRelationshipModel.FindByName("Repaired"),
                                                                    new List <QueryableEntity> {
                new QueryableEntity((Entity)ModelData.EntityRelationshipModel.FindByName("Garage"), "garage"),
                new QueryableEntity((Entity)ModelData.EntityRelationshipModel.FindByName("Supplier"), "supplier")
            });

            RelationshipJoinOperator RJoinOp = new RelationshipJoinOperator(
                new QueryableEntity(( Entity)ModelData.EntityRelationshipModel.FindByName("Person"), "person"),
                (Relationship)ModelData.EntityRelationshipModel.FindByName("Owns"),
                new List <QueryableEntity> {
                new QueryableEntity(CarRepairedByGarage),
                new QueryableEntity((Entity)ModelData.EntityRelationshipModel.FindByName("Insurance"), "insurance")
            },
                ModelData.ERMongoMapping);

            List <AlgebraOperator> OpList = new List <AlgebraOperator> {
                RJoinOp
            };
            FromArgument StartArg = new FromArgument(new QueryableEntity(ModelData.EntityRelationshipModel.FindByName("Person")),
                                                     ModelData.ERMongoMapping);

            QueryGenerator QueryGen = new QueryGenerator(StartArg, OpList);

            string GeneratedQuery = QueryGen.Run();

            // Assert if generated query is not null
            Assert.IsNotNull(GeneratedQuery);

            // Run Queries
            QueryRunner Runner = new QueryRunner("mongodb://localhost:27017", "ceManyToMany");

            string HandcraftedResult = Runner.GetJSON(HandcraftedQuery);
            string GeneratedResult   = Runner.GetJSON(GeneratedQuery);

            // Check if either result is null
            Assert.IsNotNull(HandcraftedResult);
            Assert.IsNotNull(GeneratedResult);

            // Check if both results are equal
            Assert.IsTrue(JToken.DeepEquals(JToken.Parse(HandcraftedResult), JToken.Parse(GeneratedResult)));
        }
Esempio n. 9
0
        public void ProjectSimpleAttributes()
        {
            // Asserts if the query result for a relationship join operation is equal
            // to a handcrafted query
            //RequiredDataContainer ModelData = ProjectDataProvider.SimpleModel();
            var ModelData = QueryBuilderParser.ParseMapping(Utils.ReadMappingFile("Mappings/project-simple.mapping"));

            // Load handcrafted query
            string HandcraftedQuery = Utils.ReadQueryFromFile("HandcraftedQueries/projectQuerySimple.js");

            // Assert if the handcrafted query is not null
            Assert.IsNotNull(HandcraftedQuery);

            // Prepare query generator
            //QueryableEntity Person = new QueryableEntity( ModelData.EntityRelationshipModel.FindByName( "Person" ) );

            //List<ProjectArgument> Arguments = new List<ProjectArgument>();
            //Arguments.Add( new ProjectArgument( Person.GetAttribute( "personId" ), Person, new BooleanExpr( false ) ) );
            //Arguments.Add( new ProjectArgument( Person.GetAttribute( "name" ), Person, new BooleanExpr( true ) ) );
            //Arguments.Add( new ProjectArgument( Person.GetAttribute( "age" ), Person, new BooleanExpr( true ) ) );

            //ProjectStage ProjectOp = new ProjectStage( Arguments, ModelData.ERMongoMapping );

            //List<AlgebraOperator> OpList = new List<AlgebraOperator> { ProjectOp };
            //FromArgument StartArg = new FromArgument( new QueryableEntity( ModelData.EntityRelationshipModel.FindByName( "Person" ) ),
            //    ModelData.ERMongoMapping );

            //QueryGenerator QueryGen = new QueryGenerator( StartArg, OpList );

            string QueryString = "from Person select Person.name, Person.age";
            // FIXED?
            // Consulta: from Person select Person.name, Person.age
            // Problema: Parser não gerou operação de projeção.
            QueryGenerator QueryGen = QueryBuilderParser.ParseQuery(QueryString, ModelData);

            string GeneratedQuery = QueryGen.Run();

            // Assert if generated query is not null
            Assert.IsNotNull(GeneratedQuery);

            // Run Queries
            QueryRunner Runner = new QueryRunner("mongodb://localhost:27017", "ceManyToMany2");

            string HandcraftedResult = Runner.GetJSON(HandcraftedQuery);
            string GeneratedResult   = Runner.GetJSON(GeneratedQuery);

            // Check if either result is null
            Assert.IsNotNull(HandcraftedResult);
            Assert.IsNotNull(GeneratedResult);

            // Check if both results are equal
            Assert.IsTrue(JToken.DeepEquals(JToken.Parse(HandcraftedResult), JToken.Parse(GeneratedResult)));
        }
Esempio n. 10
0
        public void ManyToManyMultipleEntities()
        {
            // Asserts if the query result for a simple binary join is equal
            // to a handcrafted query
            RequiredDataContainer ModelData = ManyToManyRelationshipsDataProvider.ManyToManyMultipleEntities();

            // Load handcrafted query
            string HandcraftedQuery = Utils.ReadQueryFromFile("HandcraftedQueries/personCarInsCompanyManyToMany.js");

            // Assert if the handcrafted query is not null
            Assert.IsNotNull(HandcraftedQuery);

            // Prepare query generator

            // FROM Person RJOIN (Car, InsCompany)

            RelationshipJoinOperator RJoinOp = new RelationshipJoinOperator(
                new QueryableEntity(( Entity)ModelData.EntityRelationshipModel.FindByName("Person"), "person"),
                (Relationship)ModelData.EntityRelationshipModel.FindByName("Insurance"),
                new List <QueryableEntity> {
                new QueryableEntity((Entity)ModelData.EntityRelationshipModel.FindByName("Car"), "car"),
                new QueryableEntity((Entity)ModelData.EntityRelationshipModel.FindByName("InsCompany"), "inscompany")
            },
                ModelData.ERMongoMapping);

            List <AlgebraOperator> OpList = new List <AlgebraOperator> {
                RJoinOp
            };
            FromArgument StartArg = new FromArgument(new QueryableEntity(ModelData.EntityRelationshipModel.FindByName("Person")),
                                                     ModelData.ERMongoMapping);

            QueryGenerator QueryGen = new QueryGenerator(StartArg, OpList);

            string GeneratedQuery = QueryGen.Run();

            // Assert if generated query is not null
            Assert.IsNotNull(GeneratedQuery);

            // Run Queries
            QueryRunner Runner = new QueryRunner("mongodb://localhost:27017", "researchManyToMany");

            string HandcraftedResult = Runner.GetJSON(HandcraftedQuery);
            string GeneratedResult   = Runner.GetJSON(GeneratedQuery);

            // Check if either result is null
            Assert.IsNotNull(HandcraftedResult);
            Assert.IsNotNull(GeneratedResult);

            // Check if both results are equal
            Assert.IsTrue(JToken.DeepEquals(JToken.Parse(HandcraftedResult), JToken.Parse(GeneratedResult)));
        }
        public void OneToOneEmbeddedMixed()
        {
            //TODO: Check why it isn't working and why it didn't have a TestMethod attribute before
            // Asserts if the query result for a simple binary join is equal
            // to a handcrafted query
            //RequiredDataContainer ModelData = OneToOneRelationshipsDataProvider.OneToOneEmbeddedMixed();
            var ModelData = QueryBuilderParser.ParseMapping(Utils.ReadMappingFile("Mappings/one-to-one-embedded-mixed.mapping"));

            // Load handcrafted query
            string HandcraftedQuery = Utils.ReadQueryFromFile("HandcraftedQueries/personCarOneToOne_4.js");

            // Assert if the handcrafted query is not null
            Assert.IsNotNull(HandcraftedQuery);

            // Prepare query generator
            RelationshipJoinOperator RJoinOp = new RelationshipJoinOperator(
                new QueryableEntity(( Entity)ModelData.EntityRelationshipModel.FindByName("Person"), "person"),
                (Relationship)ModelData.EntityRelationshipModel.FindByName("Drives"),
                new List <QueryableEntity> {
                new QueryableEntity((Entity)ModelData.EntityRelationshipModel.FindByName("Car"), "car")
            },
                ModelData.ERMongoMapping);

            List <AlgebraOperator> OpList = new List <AlgebraOperator> {
                RJoinOp
            };
            FromArgument StartArg = new FromArgument(new QueryableEntity(ModelData.EntityRelationshipModel.FindByName("Person")),
                                                     ModelData.ERMongoMapping);

            QueryGenerator QueryGen = new QueryGenerator(StartArg, OpList);

            string GeneratedQuery = QueryGen.Run();

            // Assert if generated query is not null
            Assert.IsNotNull(GeneratedQuery);

            // Run Queries
            QueryRunner Runner = new QueryRunner("mongodb://localhost:27017", "researchDatabase");

            string HandcraftedResult = Runner.GetJSON(HandcraftedQuery);
            string GeneratedResult   = Runner.GetJSON(GeneratedQuery);

            // Check if either result is null
            Assert.IsNotNull(HandcraftedResult);
            Assert.IsNotNull(GeneratedResult);

            // Check if both results are equal
            Assert.IsTrue(JToken.DeepEquals(JToken.Parse(HandcraftedResult), JToken.Parse(GeneratedResult)));
        }
Esempio n. 12
0
        public void CartesianProduct()
        {
            // Asserts if the query result for a relationship join operation is equal
            // to a handcrafted query
            RequiredDataContainer ModelData = CartesianProductDataProvider.SampleData();

            // Load handcrafted query
            string HandcraftedQuery = Utils.ReadQueryFromFile("HandcraftedQueries/cartersianProduct-1.js");

            // Assert if the handcrafted query is not null
            Assert.IsNotNull(HandcraftedQuery);

            // Prepare query generator
            CartesianProductOperator CartesianOp = new CartesianProductOperator(
                new QueryableEntity(ModelData.EntityRelationshipModel.FindByName("Person"), "person"),
                new QueryableEntity(ModelData.EntityRelationshipModel.FindByName("Car"), "car"),
                ModelData.ERMongoMapping);

            CartesianProductOperator CartesianOp2 = new CartesianProductOperator(
                new QueryableEntity(ModelData.EntityRelationshipModel.FindByName("Person"), "person"),
                new QueryableEntity(ModelData.EntityRelationshipModel.FindByName("Supplier"), "supplier"),
                ModelData.ERMongoMapping);

            FromArgument StartArg = new FromArgument(new QueryableEntity(ModelData.EntityRelationshipModel.FindByName("Person")),
                                                     ModelData.ERMongoMapping);
            QueryGenerator QueryGen = new QueryGenerator(StartArg, new List <AlgebraOperator>()
            {
                CartesianOp, CartesianOp2
            });

            string GeneratedQuery = QueryGen.Run();

            // Assert if generated query is not null
            Assert.IsNotNull(GeneratedQuery);

            // Run Queries
            QueryRunner Runner = new QueryRunner("mongodb://localhost:27017", "ceManyToMany2");

            string HandcraftedResult = Runner.GetJSON(HandcraftedQuery);
            string GeneratedResult   = Runner.GetJSON(GeneratedQuery);

            // Check if either result is null
            Assert.IsNotNull(HandcraftedResult);
            Assert.IsNotNull(GeneratedResult);

            // Check if both results are equal
            Assert.IsTrue(JToken.DeepEquals(JToken.Parse(HandcraftedResult), JToken.Parse(GeneratedResult)));
        }
Esempio n. 13
0
        public static void Main()
        {
            Console.WriteLine("Running...");

            DataContainer data = MarketingCMSDataProvider.MapEntitiesToCollections();

            QueryableEntity User     = new QueryableEntity(data.EntityRelationshipModel.FindByName("User"));
            QueryableEntity Product  = new QueryableEntity(data.EntityRelationshipModel.FindByName("Product"));
            QueryableEntity Store    = new QueryableEntity(data.EntityRelationshipModel.FindByName("Store"));
            QueryableEntity Category = new QueryableEntity(data.EntityRelationshipModel.FindByName("Category"));

            string Query = MarketingCMS._getQueryForTestAllProducts(data, Product, Store, Category, User);

            QueryRunner Runner = new QueryRunner("mongodb://127.0.0.1:27017", "pesquisa_cms");
            string      result = Runner.GetJSON(Query);

            JToken JSONResult = JToken.Parse(result);

            if (JSONResult.Type == JTokenType.Array)
            {
                Console.WriteLine("This is an array");

                JContainer ResultArray = (JContainer)JSONResult;
                Console.WriteLine("Count: {0}", ResultArray.Count);
            }

            using (StreamWriter sw = new StreamWriter(@"result.json", false))
            {
                sw.Write(result);
                sw.Close();
            }
        }
Esempio n. 14
0
        public void GetProductTitleAndUserName()
        {
            var DataMap                   = QueryBuilderParser.ParseMapping(Utils.ReadMappingFile("Mappings/MarketingCMS/entities-to-collections.mapping"));
            var DataMapDuplicates         = QueryBuilderParser.ParseMapping(Utils.ReadMappingFile("Mappings/MarketingCMS/entities-to-collections-duplicates.mapping"));
            var DataMapCategoryDuplicated = QueryBuilderParser.ParseMapping(Utils.ReadMappingFile("Mappings/MarketingCMS/entities-to-collections-category-duplicated.mapping"));
            var DataMapStoreDuplicated    = QueryBuilderParser.ParseMapping(Utils.ReadMappingFile("Mappings/MarketingCMS/entities-to-collections-store-duplicated.mapping"));
            var DataMapUserDuplicated     = QueryBuilderParser.ParseMapping(Utils.ReadMappingFile("Mappings/MarketingCMS/entities-to-collections-user-duplicated.mapping"));

            string QueryString = "from Product rjoin <UserProducts> (User) select Product.Title, User.UserName";

            QueryGenerator GeneratorMap1 = QueryBuilderParser.ParseQuery(QueryString, DataMap);
            QueryGenerator GeneratorMap2 = QueryBuilderParser.ParseQuery(QueryString, DataMapDuplicates);
            QueryGenerator GeneratorMap3 = QueryBuilderParser.ParseQuery(QueryString, DataMapCategoryDuplicated);
            QueryGenerator GeneratorMap4 = QueryBuilderParser.ParseQuery(QueryString, DataMapStoreDuplicated);
            QueryGenerator GeneratorMap5 = QueryBuilderParser.ParseQuery(QueryString, DataMapUserDuplicated);

            string QueryMap1 = GeneratorMap1.Run();
            string QueryMap2 = GeneratorMap2.Run();
            string QueryMap3 = GeneratorMap3.Run();
            string QueryMap4 = GeneratorMap4.Run();
            string QueryMap5 = GeneratorMap5.Run();

            Assert.IsNotNull(QueryMap1, "Query [Map1] cannot be null");
            Assert.IsNotNull(QueryMap2, "Query [Map2] cannot be null");
            Assert.IsNotNull(QueryMap3, "Query [Map3] cannot be null");
            Assert.IsNotNull(QueryMap4, "Query [Map4] cannot be null");
            Assert.IsNotNull(QueryMap5, "Query [Map5] cannot be null");

            QueryRunner RunnerMap1 = new QueryRunner("mongodb://localhost:27017", "pesquisa_cms");
            QueryRunner RunnerMap2 = new QueryRunner("mongodb://localhost:27017", "pesquisa_cms_duplicados");
            QueryRunner RunnerMap3 = new QueryRunner("mongodb://localhost:27017", "pesquisa_cms_category_duplicado");
            QueryRunner RunnerMap4 = new QueryRunner("mongodb://localhost:27017", "pesquisa_cms_store_duplicado");
            QueryRunner RunnerMap5 = new QueryRunner("mongodb://localhost:27017", "pesquisa_cms_user_duplicado");

            string ResultMap1 = RunnerMap1.GetJSON(QueryMap1);
            string ResultMap2 = RunnerMap2.GetJSON(QueryMap2);
            string ResultMap3 = RunnerMap3.GetJSON(QueryMap3);
            string ResultMap4 = RunnerMap4.GetJSON(QueryMap4);
            string ResultMap5 = RunnerMap5.GetJSON(QueryMap5);

            Assert.IsNotNull(ResultMap1, "Result [Map1] cannot be null");
            Assert.IsNotNull(ResultMap2, "Result [Map2] cannot be null");
            Assert.IsNotNull(ResultMap3, "Result [Map3] cannot be null");
            Assert.IsNotNull(ResultMap4, "Result [Map4] cannot be null");
            Assert.IsNotNull(ResultMap5, "Result [Map5] cannot be null");

            Assert.IsTrue(ResultMap1 != string.Empty, "Result [Map1] cannot be empty");
            Assert.IsTrue(ResultMap2 != string.Empty, "Result [Map2] cannot be empty");
            Assert.IsTrue(ResultMap3 != string.Empty, "Result [Map3] cannot be empty");
            Assert.IsTrue(ResultMap4 != string.Empty, "Result [Map4] cannot be empty");
            Assert.IsTrue(ResultMap5 != string.Empty, "Result [Map5] cannot be empty");

            JToken TokenResult1 = JToken.Parse(ResultMap1);

            TokenResult1.Should().BeEquivalentTo(JToken.Parse(ResultMap2));
            TokenResult1.Should().BeEquivalentTo(JToken.Parse(ResultMap3));
            TokenResult1.Should().BeEquivalentTo(JToken.Parse(ResultMap4));
            TokenResult1.Should().BeEquivalentTo(JToken.Parse(ResultMap5));
        }
Esempio n. 15
0
        public void NotInArray()
        {
            RequiredDataContainer ModelData = SelectDataProvider.GetData();

            string HandcraftedQuery = Utils.ReadQueryFromFile("HandcraftedQueries/selectNotInArray.js");

            Assert.IsNotNull(HandcraftedQuery);

            MapRule PersonRule = ModelData.ERMongoMapping.Rules.First(R => R.Source.Name == "Person");
            string  AgeMap     = PersonRule.Rules.First(R => R.Key == "age").Value;

            LogicalExpression left = new LogicalExpression($"${AgeMap}", LogicalOperator.NOT_IN,
                                                           new JSArray(new List <object>()
            {
                26, 27, 28, 29
            }));

            SelectArgument Arg      = new SelectArgument(left);
            SelectStage    SelectOp = new SelectStage(Arg, ModelData.ERMongoMapping);

            List <AlgebraOperator> OperatorsToExecute = new List <AlgebraOperator>()
            {
                SelectOp
            };
            FromArgument StartArg = new FromArgument(new QueryableEntity(ModelData.EntityRelationshipModel.FindByName("Person")),
                                                     ModelData.ERMongoMapping);
            QueryGenerator QueryGen = new QueryGenerator(StartArg, OperatorsToExecute);

            string GeneratedQuery = QueryGen.Run();

            Assert.IsNotNull(GeneratedQuery);

            QueryRunner Runner = new QueryRunner("mongodb://localhost:27017", "select");

            string HandcraftedResult = Runner.GetJSON(HandcraftedQuery);
            string GeneratedResult   = Runner.GetJSON(GeneratedQuery);

            // Check if either result is null
            Assert.IsNotNull(HandcraftedResult);
            Assert.IsNotNull(GeneratedResult);

            // Check if both results are equal
            Assert.IsTrue(JToken.DeepEquals(JToken.Parse(HandcraftedResult), JToken.Parse(GeneratedResult)));
        }
Esempio n. 16
0
        public void Equal()
        {
            //RequiredDataContainer ModelData = SelectDataProvider.GetData();
            var ModelData = QueryBuilderParser.ParseMapping(Utils.ReadMappingFile("Mappings/select.mapping"));

            string HandcraftedQuery = Utils.ReadQueryFromFile("HandcraftedQueries/selectEqual.js");

            Assert.IsNotNull(HandcraftedQuery);

            //MapRule PersonRule = ModelData.ERMongoMapping.Rules.First( R => R.Source.Name == "Person" );
            //string AgeMap = PersonRule.Rules.First( R => R.Key == "age" ).Value;
            //LogicalExpression left = new LogicalExpression( $"${AgeMap}", LogicalOperator.EQUAL, 27 );

            //SelectArgument Arg = new SelectArgument( left );
            //SelectStage SelectOp = new SelectStage( Arg, ModelData.ERMongoMapping );

            //List<AlgebraOperator> OperatorsToExecute = new List<AlgebraOperator>() { SelectOp };
            //FromArgument StartArg = new FromArgument( new QueryableEntity( ModelData.EntityRelationshipModel.FindByName( "Person" ) ),
            //    ModelData.ERMongoMapping );
            //QueryGenerator QueryGen = new QueryGenerator( StartArg, OperatorsToExecute );

            string QueryString = "from Person select * where Person.age = 27";
            // FIXME
            // Consulta: from Person where Person.age = 27 select *
            // Problema: Parser não gerou operação de seleção.

            QueryGenerator QueryGen = QueryBuilderParser.ParseQuery(QueryString, ModelData);

            string GeneratedQuery = QueryGen.Run();

            Assert.IsNotNull(GeneratedQuery);

            QueryRunner Runner = new QueryRunner("mongodb://localhost:27017", "select");

            string HandcraftedResult = Runner.GetJSON(HandcraftedQuery);
            string GeneratedResult   = Runner.GetJSON(GeneratedQuery);

            // Check if either result is null
            Assert.IsNotNull(HandcraftedResult);
            Assert.IsNotNull(GeneratedResult);

            // Check if both results are equal
            Assert.IsTrue(JToken.DeepEquals(JToken.Parse(HandcraftedResult), JToken.Parse(GeneratedResult)));
        }
Esempio n. 17
0
        public void OrMultiple()
        {
            //RequiredDataContainer ModelData = SelectDataProvider.GetData();
            var ModelData = QueryBuilderParser.ParseMapping(Utils.ReadMappingFile("Mappings/select.mapping"));

            string HandcraftedQuery = Utils.ReadQueryFromFile("HandcraftedQueries/selectOrMultiple.js");

            Assert.IsNotNull(HandcraftedQuery);

            //MapRule PersonRule = ModelData.ERMongoMapping.Rules.First( R => R.Source.Name == "Person" );
            //string AgeMap = PersonRule.Rules.First( R => R.Key == "age" ).Value;
            //OrExpr expr = new OrExpr( $"${AgeMap}", new List<object>() { 18, 21, 36 } );

            //SelectArgument Arg = new SelectArgument( expr );
            //SelectStage SelectOp = new SelectStage( Arg, ModelData.ERMongoMapping );

            //List<AlgebraOperator> OperatorsToExecute = new List<AlgebraOperator>() { SelectOp };
            //FromArgument StartArg = new FromArgument( new QueryableEntity( ModelData.EntityRelationshipModel.FindByName( "Person" ) ),
            //    ModelData.ERMongoMapping );
            //QueryGenerator QueryGen = new QueryGenerator( StartArg, OperatorsToExecute );

            string         QueryString = "from Person select * where Person.age = 18 or Person.age = 21 or Person.age = 36";
            QueryGenerator QueryGen    = QueryBuilderParser.ParseQuery(QueryString, ModelData);

            string GeneratedQuery = QueryGen.Run();

            Assert.IsNotNull(GeneratedQuery);

            QueryRunner Runner = new QueryRunner("mongodb://localhost:27017", "select");

            string HandcraftedResult = Runner.GetJSON(HandcraftedQuery);
            string GeneratedResult   = Runner.GetJSON(GeneratedQuery);

            // Check if either result is null
            Assert.IsNotNull(HandcraftedResult);
            Assert.IsNotNull(GeneratedResult);

            // Check if both results are equal
            Assert.IsTrue(JToken.DeepEquals(JToken.Parse(HandcraftedResult), JToken.Parse(GeneratedResult)));
        }
        public void OneToOneComputedEntity()
        {
            // Asserts if the query result for a relationship join operation is equal
            // to a handcrafted query
            var ModelData = QueryBuilderParser.ParseMapping(Utils.ReadMappingFile("Mappings/one-to-one-computed-entity.mapping"));

            // Load handcrafted query
            string HandcraftedQuery = Utils.ReadQueryFromFile("HandcraftedQueries/ceOneToOne.js");

            // Assert if the handcrafted query is not null
            Assert.IsNotNull(HandcraftedQuery);

            // Prepare query generator
            string QueryString = "from Person rjoin <Drives> (Car rjoin <Repaired> (Garage)) select *";
            // FIXED?
            // Consulta: from person rjoin <Drives> (Car rjoin <Repaired> (Garage)) select *
            // Problema: Parser gera duas operações rjoin (car rjoin garage) e (person rjoin (car rjoin garage)).
            // Solução: Nesse caso basta gerar apenas uma operação (person rjoin (car rjoin garage)).
            QueryGenerator QueryGen = QueryBuilderParser.ParseQuery(QueryString, ModelData);

            string GeneratedQuery = QueryGen.Run();

            // Assert if generated query is not null
            Assert.IsNotNull(GeneratedQuery);

            // Run Queries
            QueryRunner Runner = new QueryRunner("mongodb://localhost:27017", "ceOneToOne");

            string HandcraftedResult = Runner.GetJSON(HandcraftedQuery);
            string GeneratedResult   = Runner.GetJSON(GeneratedQuery);

            // Check if either result is null
            Assert.IsNotNull(HandcraftedResult);
            Assert.IsNotNull(GeneratedResult);

            // Check if both results are equal
            Assert.IsTrue(JToken.DeepEquals(JToken.Parse(HandcraftedResult), JToken.Parse(GeneratedResult)));
        }
        public void OneToOneRelationshipAttributes()
        {
            // Asserts if the query result for a simple binary join is equal
            // to a handcrafted query
            var ModelData = QueryBuilderParser.ParseMapping(Utils.ReadMappingFile("Mappings/one-to-one-relationship-attributes.mapping"));

            // Load handcrafted query
            string HandcraftedQuery = Utils.ReadQueryFromFile("HandcraftedQueries/personCarOneToOneRelationshipAttributes.js");

            // Assert if the handcrafted query is not null
            Assert.IsNotNull(HandcraftedQuery);

            // Prepare query generator
            string QueryString = "from Person rjoin <HasInsurance> (Car, Insurance) select *";
            // FIXED?
            // Consulta: from Person rjoin <HasInsurance> (Car, Insurance) select *
            // Problema: Parser considera que Insurance é um alias de Car e não a inclui como parte da junção.
            // Solução: Incluir Insurance na lista de entidades 'alvo' do rjoin.
            QueryGenerator QueryGen = QueryBuilderParser.ParseQuery(QueryString, ModelData);

            string GeneratedQuery = QueryGen.Run();

            // Assert if generated query is not null
            Assert.IsNotNull(GeneratedQuery);

            // Run Queries
            QueryRunner Runner = new QueryRunner("mongodb://localhost:27017", "researchOneToOneRelationshipAttribute");

            string HandcraftedResult = Runner.GetJSON(HandcraftedQuery);
            string GeneratedResult   = Runner.GetJSON(GeneratedQuery);

            // Check if either result is null
            Assert.IsNotNull(HandcraftedResult);
            Assert.IsNotNull(GeneratedResult);

            // Check if both results are equal
            Assert.IsTrue(JToken.DeepEquals(JToken.Parse(HandcraftedResult), JToken.Parse(GeneratedResult)));
        }
        public void OneToOneComputedEntityMultiple()
        {
            // Asserts if the query result for a relationship join operation is equal
            // to a handcrafted query
            var ModelData = QueryBuilderParser.ParseMapping(Utils.ReadMappingFile("Mappings/one-to-one-computed-entity-multiple.mapping"));

            // Load handcrafted query
            string HandcraftedQuery = Utils.ReadQueryFromFile("HandcraftedQueries/ceOneToOne-Multiple.js");

            // Assert if the handcrafted query is not null
            Assert.IsNotNull(HandcraftedQuery);

            // Prepare query generator
            string QueryString = "from Person rjoin <Drives> (Car rjoin <Repaired> (Garage, Supplier)) select *";
            // FIXED?
            // Consulta: from Person rjoin <Drives> (Car rjoin <Repaired> (Garage, Supplier)) select *
            // Problema: Parser gera duas operações (car rjoin garage) e (person rjoin (car rjoin garage)) a primeira operação não é necessária, e a segunda não incluiu a entidade Supplier na junção.
            // Solução: Junções aninhadas devem gerar apenas uma operação, nesse exemplo a junção entre Car, Garage e Supplier é representada por uma entidade computada.
            QueryGenerator QueryGen = QueryBuilderParser.ParseQuery(QueryString, ModelData);

            string GeneratedQuery = QueryGen.Run();

            // Assert if generated query is not null
            Assert.IsNotNull(GeneratedQuery);

            // Run Queries
            QueryRunner Runner = new QueryRunner("mongodb://localhost:27017", "ceOneToOneMultiple");

            string HandcraftedResult = Runner.GetJSON(HandcraftedQuery);
            string GeneratedResult   = Runner.GetJSON(GeneratedQuery);

            // Check if either result is null
            Assert.IsNotNull(HandcraftedResult);
            Assert.IsNotNull(GeneratedResult);

            // Check if both results are equal
            Assert.IsTrue(JToken.DeepEquals(JToken.Parse(HandcraftedResult), JToken.Parse(GeneratedResult)));
        }
        public void OneToOneComputedEntityMultiple2()
        {
            // Asserts if the query result for a relationship join operation is equal
            // to a handcrafted query
            var ModelData = QueryBuilderParser.ParseMapping(Utils.ReadMappingFile("Mappings/one-to-one-computed-entity-multiple-2.mapping"));

            // Load handcrafted query
            string HandcraftedQuery = Utils.ReadQueryFromFile("HandcraftedQueries/ceOneToOne-Multiple2.js");

            // Assert if the handcrafted query is not null
            Assert.IsNotNull(HandcraftedQuery);

            // Prepare query generator
            string QueryString = "from Person rjoin <Drives> (Car rjoin <Repaired> (Garage, Supplier)) rjoin <HasInsurance> (Insurance) select *";
            // FIXED?
            // Consulta: from Person rjoin <Drives> (Car rjoin <Repaired> (Garage, Supplier)) rjoin <HasInsurance> (Insurance) select *
            // Problema: Neste existem dois problemas, o primeiro é o mesmo do exemplo anterior (Person rjoin <Drives> (Car rjoin <Repaired> (Garage, Supplier))) e o segundo problema é ao gerar a junção de Insurance com o resultado da junção anterior.
            // Solução: Na situação atual do algoritmo quando houver várias junções de mesmo nível, ou seja, quando o resultado de uma junção é o ponto de partida para a próxima junção, pode-se usar a entidade Person (a mesma do argumento From). Uma das limitações do algoritmo é a falta de suporte para herança de relacionamentos (da forma que foi proposto na álgebra) e por isso as junções subsequentes devem ser entre entidades relacionadas a entidade de entrada.
            QueryGenerator QueryGen = QueryBuilderParser.ParseQuery(QueryString, ModelData);

            string GeneratedQuery = QueryGen.Run();

            // Assert if generated query is not null
            Assert.IsNotNull(GeneratedQuery);

            // Run Queries
            QueryRunner Runner = new QueryRunner("mongodb://localhost:27017", "ceOneToOneMultiple2");

            string HandcraftedResult = Runner.GetJSON(HandcraftedQuery);
            string GeneratedResult   = Runner.GetJSON(GeneratedQuery);

            // Check if either result is null
            Assert.IsNotNull(HandcraftedResult);
            Assert.IsNotNull(GeneratedResult);

            // Check if both results are equal
            Assert.IsTrue(JToken.DeepEquals(JToken.Parse(HandcraftedResult), JToken.Parse(GeneratedResult)));
        }
Esempio n. 22
0
        public void GetAllProducts()
        {
            var DataMap  = QueryBuilderParser.ParseMapping(Utils.ReadMappingFile("Mappings/MarketingCMS/entities-to-collections.mapping"));
            var DataMap2 = QueryBuilderParser.ParseMapping(Utils.ReadMappingFile("Mappings/MarketingCMS/entities-to-collections-duplicates.mapping"));
            var DataMap3 = QueryBuilderParser.ParseMapping(Utils.ReadMappingFile("Mappings/MarketingCMS/entities-to-collections-category-duplicated.mapping"));
            var DataMap4 = QueryBuilderParser.ParseMapping(Utils.ReadMappingFile("Mappings/MarketingCMS/entities-to-collections-store-duplicated.mapping"));
            var DataMap5 = QueryBuilderParser.ParseMapping(Utils.ReadMappingFile("Mappings/MarketingCMS/entities-to-collections-user-duplicated.mapping"));

            string QueryString = "from Product rjoin <UserProducts> (User) rjoin <StoreProducts> (Store) rjoin <CategoryProducts> (Category) select *";

            QueryGenerator QueryGen  = QueryBuilderParser.ParseQuery(QueryString, DataMap);
            QueryGenerator QueryGen2 = QueryBuilderParser.ParseQuery(QueryString, DataMap2);
            QueryGenerator QueryGen3 = QueryBuilderParser.ParseQuery(QueryString, DataMap3);
            QueryGenerator QueryGen4 = QueryBuilderParser.ParseQuery(QueryString, DataMap4);
            QueryGenerator QueryGen5 = QueryBuilderParser.ParseQuery(QueryString, DataMap5);

            string Query  = QueryGen.Run();
            string Query2 = QueryGen2.Run();
            string Query3 = QueryGen3.Run();
            string Query4 = QueryGen4.Run();
            string Query5 = QueryGen5.Run();

            QueryRunner Runner = new QueryRunner("mongodb://localhost:27017", "pesquisa_cms");
            string      Result = Runner.GetJSON(Query);

            QueryRunner Runner2 = new QueryRunner("mongodb://localhost:27017", "pesquisa_cms_duplicados");
            string      Result2 = Runner2.GetJSON(Query2);

            QueryRunner Runner3 = new QueryRunner("mongodb://localhost:27017", "pesquisa_cms_category_duplicado");
            string      Result3 = Runner3.GetJSON(Query3);

            QueryRunner Runner4 = new QueryRunner("mongodb://localhost:27017", "pesquisa_cms_store_duplicado");
            string      Result4 = Runner4.GetJSON(Query4);

            QueryRunner Runner5 = new QueryRunner("mongodb://localhost:27017", "pesquisa_cms_user_duplicado");
            string      Result5 = Runner5.GetJSON(Query5);

            Assert.IsNotNull(Result);
            Assert.IsNotNull(Result2);
            Assert.IsNotNull(Result3);
            Assert.IsNotNull(Result4);
            Assert.IsNotNull(Result5);

            JToken ResultJson = JToken.Parse(Result);

            Assert.IsTrue(JToken.DeepEquals(ResultJson, JToken.Parse(Result2)));
            Assert.IsTrue(JToken.DeepEquals(ResultJson, JToken.Parse(Result3)));
            Assert.IsTrue(JToken.DeepEquals(ResultJson, JToken.Parse(Result4)));
            Assert.IsTrue(JToken.DeepEquals(ResultJson, JToken.Parse(Result5)));
        }
        public void ManyToManyComputedEntityMultipleEntities()
        {
            // Asserts if the query result for a relationship join operation is equal
            // to a handcrafted query
            var ModelData = QueryBuilderParser.ParseMapping(Utils.ReadMappingFile("Mappings/many-to-many-computed-entity.mapping"));

            // Load handcrafted query
            string HandcraftedQuery = Utils.ReadQueryFromFile("HandcraftedQueries/ceManyToMany.js");

            // Assert if the handcrafted query is not null
            Assert.IsNotNull(HandcraftedQuery);

            // Prepare query generator
            string QueryString = "from Person rjoin <Owns> (Car rjoin <Repaired> (Garage, Supplier), Insurance) select *";
            // FIXED?
            // Consulta: from Person rjoin <Owns> (Car rjoin <Repaired> (Garage, Supplier), Insurance) select *
            // Comentário: Nesse caso o parser gerou uma operação rjoin entre Car e Garage (mesmo problema dos exemplos anteriores) e também gerou uma junção entre Person, (Car e Garage) e Insurance, a última operação incluiu multiplas entidades apenas falhou ao não incluir Supplier na junção com Car e Garage.
            QueryGenerator QueryGen = QueryBuilderParser.ParseQuery(QueryString, ModelData);

            string GeneratedQuery = QueryGen.Run();

            // Assert if generated query is not null
            Assert.IsNotNull(GeneratedQuery);

            // Run Queries
            QueryRunner Runner = new QueryRunner("mongodb://localhost:27017", "ceManyToMany");

            string HandcraftedResult = Runner.GetJSON(HandcraftedQuery);
            string GeneratedResult   = Runner.GetJSON(GeneratedQuery);

            // Check if either result is null
            Assert.IsNotNull(HandcraftedResult);
            Assert.IsNotNull(GeneratedResult);

            // Check if both results are equal
            Assert.IsTrue(JToken.DeepEquals(JToken.Parse(HandcraftedResult), JToken.Parse(GeneratedResult)));
        }
Esempio n. 24
0
        public void GetAllProductsFromStore()
        {
            var DataMap                   = QueryBuilderParser.ParseMapping(Utils.ReadMappingFile("Mappings/MarketingCMS/entities-to-collections.mapping"));
            var DataMapDuplicates         = QueryBuilderParser.ParseMapping(Utils.ReadMappingFile("Mappings/MarketingCMS/entities-to-collections-duplicates.mapping"));
            var DataMapCategoryDuplicated = QueryBuilderParser.ParseMapping(Utils.ReadMappingFile("Mappings/MarketingCMS/entities-to-collections-category-duplicated.mapping"));
            var DataMapStoreDuplicated    = QueryBuilderParser.ParseMapping(Utils.ReadMappingFile("Mappings/MarketingCMS/entities-to-collections-store-duplicated.mapping"));
            var DataMapUserDuplicated     = QueryBuilderParser.ParseMapping(Utils.ReadMappingFile("Mappings/MarketingCMS/entities-to-collections-user-duplicated.mapping"));

            string QueryString = "from Store rjoin <StoreProducts> (Product) select *";

            QueryGenerator GeneratorMap1 = QueryBuilderParser.ParseQuery(QueryString, DataMap);
            QueryGenerator GeneratorMap2 = QueryBuilderParser.ParseQuery(QueryString, DataMapDuplicates);
            QueryGenerator GeneratorMap3 = QueryBuilderParser.ParseQuery(QueryString, DataMapCategoryDuplicated);
            QueryGenerator GeneratorMap4 = QueryBuilderParser.ParseQuery(QueryString, DataMapStoreDuplicated);
            QueryGenerator GeneratorMap5 = QueryBuilderParser.ParseQuery(QueryString, DataMapUserDuplicated);

            string QueryMap1 = GeneratorMap1.Run();

            Assert.ThrowsException <ImpossibleOperationException>(GeneratorMap2.Run);
            string QueryMap3 = GeneratorMap3.Run();

            Assert.ThrowsException <ImpossibleOperationException>(GeneratorMap4.Run);
            string QueryMap5 = GeneratorMap5.Run();

            Assert.IsNotNull(QueryMap1, "Query [Map1] cannot be null");
            Assert.IsNotNull(QueryMap3, "Query [Map3] cannot be null");
            Assert.IsNotNull(QueryMap5, "Query [Map5] cannot be null");

            QueryRunner RunnerMap1 = new QueryRunner("mongodb://localhost:27017", "pesquisa_cms");
            QueryRunner RunnerMap3 = new QueryRunner("mongodb://localhost:27017", "pesquisa_cms_category_duplicado");
            QueryRunner RunnerMap5 = new QueryRunner("mongodb://localhost:27017", "pesquisa_cms_user_duplicado");

            string ResultMap1 = RunnerMap1.GetJSON(QueryMap1);
            string ResultMap3 = RunnerMap3.GetJSON(QueryMap3);
            string ResultMap5 = RunnerMap5.GetJSON(QueryMap5);

            Assert.IsNotNull(ResultMap1, "Result [Map1] cannot be null");
            Assert.IsNotNull(ResultMap3, "Result [Map3] cannot be null");
            Assert.IsNotNull(ResultMap5, "Result [Map5] cannot be null");

            Assert.IsTrue(ResultMap1 != string.Empty, "Result [Map1] cannot be empty");
            Assert.IsTrue(ResultMap3 != string.Empty, "Result [Map3] cannot be empty");
            Assert.IsTrue(ResultMap5 != string.Empty, "Result [Map5] cannot be empty");

            JToken TokenResult1 = JToken.Parse(ResultMap1);

            TokenResult1.Should().BeEquivalentTo(JToken.Parse(ResultMap3));
            TokenResult1.Should().BeEquivalentTo(JToken.Parse(ResultMap5));
        }
Esempio n. 25
0
        public void GetAllUsers()
        {
            var DataMap                   = QueryBuilderParser.ParseMapping(Utils.ReadMappingFile("Mappings/MarketingCMS/entities-to-collections.mapping"));
            var DataMapDuplicates         = QueryBuilderParser.ParseMapping(Utils.ReadMappingFile("Mappings/MarketingCMS/entities-to-collections-duplicates.mapping"));
            var DataMapCategoryDuplicated = QueryBuilderParser.ParseMapping(Utils.ReadMappingFile("Mappings/MarketingCMS/entities-to-collections-category-duplicated.mapping"));
            var DataMapStoreDuplicated    = QueryBuilderParser.ParseMapping(Utils.ReadMappingFile("Mappings/MarketingCMS/entities-to-collections-store-duplicated.mapping"));
            var DataMapUserDuplicated     = QueryBuilderParser.ParseMapping(Utils.ReadMappingFile("Mappings/MarketingCMS/entities-to-collections-user-duplicated.mapping"));

            string QueryString = "from User select *";

            QueryGenerator QueryGenMap1 = QueryBuilderParser.ParseQuery(QueryString, DataMap);
            QueryGenerator QueryGenMap2 = QueryBuilderParser.ParseQuery(QueryString, DataMapDuplicates);
            QueryGenerator QueryGenMap3 = QueryBuilderParser.ParseQuery(QueryString, DataMapCategoryDuplicated);
            QueryGenerator QueryGenMap4 = QueryBuilderParser.ParseQuery(QueryString, DataMapStoreDuplicated);
            QueryGenerator QueryGenMap5 = QueryBuilderParser.ParseQuery(QueryString, DataMapUserDuplicated);

            string QueryStringMap1 = QueryGenMap1.Run();

            Assert.ThrowsException <ImpossibleOperationException>(QueryGenMap2.Run);
            string QueryStringMap3 = QueryGenMap3.Run();
            string QueryStringMap4 = QueryGenMap4.Run();

            Assert.ThrowsException <ImpossibleOperationException>(QueryGenMap5.Run);

            QueryRunner RunnerMap1 = new QueryRunner("mongodb://localhost:27017", "pesquisa_cms");
            QueryRunner RunnerMap3 = new QueryRunner("mongodb://localhost:27017", "pesquisa_cms_category_duplicado");
            QueryRunner RunnerMap4 = new QueryRunner("mongodb://localhost:27017", "pesquisa_cms_store_duplicado");

            string ResultMap1 = RunnerMap1.GetJSON(QueryStringMap1);
            string ResultMap3 = RunnerMap3.GetJSON(QueryStringMap3);
            string ResultMap4 = RunnerMap4.GetJSON(QueryStringMap4);

            Assert.IsNotNull(ResultMap1, "Result [Map1] cannot be null");
            Assert.IsNotNull(ResultMap3, "Result [Map3] cannot be null");
            Assert.IsNotNull(ResultMap4, "Result [Map4] cannot be null");

            Assert.IsTrue(ResultMap1 != string.Empty, "Result [Map1] cannot be empty");
            Assert.IsTrue(ResultMap3 != string.Empty, "Result [Map3] cannot be empty");
            Assert.IsTrue(ResultMap4 != string.Empty, "Result [Map4] cannot be empty");

            Assert.IsTrue(JToken.DeepEquals(JToken.Parse(ResultMap1), JToken.Parse(ResultMap3)));
            Assert.IsTrue(JToken.DeepEquals(JToken.Parse(ResultMap1), JToken.Parse(ResultMap4)));
        }
Esempio n. 26
0
        public void GetCategoryThatIsNamedHome()
        {
            var DataMap                   = QueryBuilderParser.ParseMapping(Utils.ReadMappingFile("Mappings/MarketingCMS/entities-to-collections.mapping"));
            var DataMapDuplicates         = QueryBuilderParser.ParseMapping(Utils.ReadMappingFile("Mappings/MarketingCMS/entities-to-collections-duplicates.mapping"));
            var DataMapCategoryDuplicated = QueryBuilderParser.ParseMapping(Utils.ReadMappingFile("Mappings/MarketingCMS/entities-to-collections-category-duplicated.mapping"));
            var DataMapStoreDuplicated    = QueryBuilderParser.ParseMapping(Utils.ReadMappingFile("Mappings/MarketingCMS/entities-to-collections-store-duplicated.mapping"));
            var DataMapUserDuplicated     = QueryBuilderParser.ParseMapping(Utils.ReadMappingFile("Mappings/MarketingCMS/entities-to-collections-user-duplicated.mapping"));

            string QueryString = "from Category where CategoryName = 'Home' select *";

            QueryGenerator GeneratorMap1 = QueryBuilderParser.ParseQuery(QueryString, DataMap);
            QueryGenerator GeneratorMap4 = QueryBuilderParser.ParseQuery(QueryString, DataMapStoreDuplicated);
            QueryGenerator GeneratorMap5 = QueryBuilderParser.ParseQuery(QueryString, DataMapUserDuplicated);

            string QueryMap1 = GeneratorMap1.Run();
            string QueryMap4 = GeneratorMap4.Run();
            string QueryMap5 = GeneratorMap5.Run();

            Assert.IsNotNull(QueryMap1, "Query [Map1] cannot be null");
            Assert.IsNotNull(QueryMap4, "Query [Map4] cannot be null");
            Assert.IsNotNull(QueryMap5, "Query [Map5] cannot be null");

            QueryRunner RunnerMap1 = new QueryRunner("mongodb://localhost:27017", "pesquisa_cms");
            QueryRunner RunnerMap4 = new QueryRunner("mongodb://localhost:27017", "pesquisa_cms_store_duplicado");
            QueryRunner RunnerMap5 = new QueryRunner("mongodb://localhost:27017", "pesquisa_cms_user_duplicado");

            string ResultMap1 = RunnerMap1.GetJSON(QueryMap1);
            string ResultMap4 = RunnerMap4.GetJSON(QueryMap4);
            string ResultMap5 = RunnerMap5.GetJSON(QueryMap5);

            Assert.IsNotNull(ResultMap1, "Result [Map1] cannot be null");
            Assert.IsNotNull(ResultMap4, "Result [Map4] cannot be null");
            Assert.IsNotNull(ResultMap5, "Result [Map5] cannot be null");

            Assert.IsTrue(ResultMap1 != string.Empty, "Result [Map1] cannot be empty");
            Assert.IsTrue(ResultMap4 != string.Empty, "Result [Map4] cannot be empty");
            Assert.IsTrue(ResultMap5 != string.Empty, "Result [Map5] cannot be empty");

            JToken TokenResult1 = JToken.Parse(ResultMap1);

            TokenResult1.Should().BeEquivalentTo(JToken.Parse(ResultMap4));
            TokenResult1.Should().BeEquivalentTo(JToken.Parse(ResultMap5));
        }
Esempio n. 27
0
        private void GenerateQuery(RequiredDataContainer Container, string Database)
        {
            QueryableEntity Aluno    = new QueryableEntity(Container.EntityRelationshipModel.FindByName("Aluno"));
            QueryableEntity Endereco = new QueryableEntity(Container.EntityRelationshipModel.FindByName("Endereco"));

            RelationshipJoinOperator RJoinOp = new RelationshipJoinOperator(
                Aluno,
                (Relationship)Container.EntityRelationshipModel.FindByName("AlunoMora"),
                new List <QueryableEntity>()
            {
                Endereco
            },
                Container.ERMongoMapping);

            SortArgument SortArg = new SortArgument(Aluno, Aluno.Element.GetIdentifierAttribute(), MongoDBSort.Ascending);
            SortStage    SortOp  = new SortStage(new List <SortArgument>()
            {
                SortArg
            }, Container.ERMongoMapping);

            List <AlgebraOperator> OperatorList = new List <AlgebraOperator>()
            {
                RJoinOp, SortOp
            };

            FromArgument FromArg = new FromArgument(Aluno, Container.ERMongoMapping);

            QueryGenerator QueryGen = new QueryGenerator(FromArg, OperatorList);

            string Query = QueryGen.Run();

            Beautifier jsB = new Beautifier();

            queryBox.Text = jsB.Beautify(Query);

            QueryRunner QueryRunner = new QueryRunner("mongodb://localhost:27017", Database);

            string Result = QueryRunner.GetJSON(Query);

            resultBox.Text = Result.PrettyPrintJson();
        }
Esempio n. 28
0
        public void GetAllProductsTest()
        {
            DataContainer DataMap  = MarketingCMSDataProvider.MapEntitiesToCollections();
            DataContainer DataMap2 = MarketingCMSDataProvider.MapEntitiesToCollectionDuplicates();
            DataContainer DataMap3 = MarketingCMSDataProvider.MapEntitiesToCollectionCategoryDuplicated();
            DataContainer DataMap4 = MarketingCMSDataProvider.MapEntitiesToCollectionsStoreDuplicated();
            DataContainer DataMap5 = MarketingCMSDataProvider.MapEntitiesToCollectionsUserDuplicated();

            QueryableEntity Product  = new QueryableEntity(DataMap.EntityRelationshipModel.FindByName("Product"));
            QueryableEntity Store    = new QueryableEntity(DataMap.EntityRelationshipModel.FindByName("Store"));
            QueryableEntity Category = new QueryableEntity(DataMap.EntityRelationshipModel.FindByName("Category"));
            QueryableEntity User     = new QueryableEntity(DataMap.EntityRelationshipModel.FindByName("User"));

            string Query  = _getQueryForTestAllProducts(DataMap, Product, Store, Category, User);
            string Query2 = _getQueryForTestAllProducts(DataMap2, Product, Store, Category, User);
            string Query3 = _getQueryForTestAllProducts(DataMap3, Product, Store, Category, User);
            string Query4 = _getQueryForTestAllProducts(DataMap4, Product, Store, Category, User);
            string Query5 = _getQueryForTestAllProducts(DataMap5, Product, Store, Category, User);

            QueryRunner Runner = new QueryRunner("mongodb://localhost:27017", "pesquisa_cms");
            string      Result = Runner.GetJSON(Query);

            QueryRunner Runner2 = new QueryRunner("mongodb://localhost:27017", "pesquisa_cms_duplicados");
            string      Result2 = Runner2.GetJSON(Query2);

            //QueryRunner Runner3 = new QueryRunner( "mongodb://localhost:27017", "pesquisa_cms_category_duplicado" );
            //string Result3 = Runner3.GetJSON( Query3 );

            //QueryRunner Runner4 = new QueryRunner( "mongodb://localhost:27017", "pesquisa_cms_store_duplicado" );
            //string Result4 = Runner4.GetJSON( Query4 );

            //QueryRunner Runner5 = new QueryRunner( "mongodb://localhost:27017", "pesquisa_cms_user_duplicado" );
            //string Result5 = Runner5.GetJSON( Query5 );

            JToken ResultJson  = JToken.Parse(Result);
            JToken ResultJson2 = JToken.Parse(Result2);
            //JToken ResultJson3 = JToken.Parse( Result3 );
            //JToken ResultJson4 = JToken.Parse( Result4 );
            //JToken ResultJson5 = JToken.Parse( Result5 );
        }
Esempio n. 29
0
        static void Main(string[] args)
        {
            var mapping = QueryBuilderParser.ParseMapping(new FileStream(args[0], FileMode.Open));

            Console.WriteLine($"ERModel: {mapping.EntityRelationshipModel.Name}");

            Console.WriteLine("\n\n****** ER Model ********\n\n");

            foreach (var e in mapping.EntityRelationshipModel.Elements.FindAll(e => e.GetType() == typeof(Entity)))
            {
                Console.WriteLine($"Entity: {e.Name}");
                e.Attributes.ForEach(a =>
                {
                    Console.WriteLine($"   Attribute: {a.Name} of type {a.OfType}, multivalued={a.MultiValued}");
                });
            }

            foreach (var r in mapping.EntityRelationshipModel.Elements.FindAll(e => e.GetType() == typeof(Relationship)).ConvertAll <Relationship>(e => (Relationship)e))
            {
                Console.WriteLine($"Relationship: {r.Name}");

                r.Ends.ForEach(e =>
                {
                    Console.WriteLine($"   End: {e.TargetEntity.Name}");
                });
                r.Attributes.ForEach(a =>
                {
                    Console.WriteLine($"   Attribute: {a.Name} of type {a.OfType}, multivalued={a.MultiValued}");
                });
            }

            Console.WriteLine("\n\n****** Mongo DB Schema ********\n\n");


            foreach (var c in mapping.MongoDBSchema.Collections)
            {
                Console.WriteLine($"Collection: {c.Name}");
                c.DocumentSchema.Attributes.ForEach(a =>
                {
                    Console.WriteLine($"   Field: {a.Name} of type {a.OfType}, multivalued={a.MultiValued}");
                });
            }

            Console.WriteLine("\n\n****** Mapping ********\n\n");


            foreach (var r in mapping.ERMongoMapping.Rules)
            {
                Console.WriteLine($"Rule: {r.Source.Name} = {r.Target.Name} (Main={r.IsMain})");
                foreach (var sr in r.Rules)
                {
                    Console.WriteLine($"   {sr.Key} - {sr.Value}");
                }
            }

            Console.WriteLine("\n\n****** Warnings and Errors ********\n\n");


            mapping.Warnings.ForEach(w => Console.WriteLine(w));
            mapping.Errors.ForEach(e => Console.WriteLine(e));

            //string[] queries = { "from Author a rjoin <BookAndAuthor ba> (Book b)" };
            string[] queries = { "from Author a rjoin <BookAndAuthor ba> (Book b rjoin <PublishedBy pb> (Publisher p))" };

            // string[] queries = { "from Person p rjoin <Insurance i> (Car c, InsuranceCompany ic)",
            //                      "from Car c rjoin <Repaired r> (Garage g)",
            //                      "from Person p rjoin <Insurance i> (Car c rjoin <Repaired r> (Garage g), InsuranceCompany ic)",
            //                      "from (Person p rjoin <Drives d> (Car c)) rjoin <Repaired r> (Garage g)",
            //                      "from (Person p rjoin <Drives d> (Car c rjoin <Repaired r> (Garage g)))",
            //                      "from Person p rjoin <Drives d> (Car c rjoin <Repaired r> (Garage g))" };

            foreach (var q in queries)
            {
                Console.WriteLine(q);
                var generatedQuery = QueryBuilderParser.ParseQuery(q, mapping);

                Console.WriteLine("*************");
                Console.WriteLine($"Start Argument: {generatedQuery.StartArgument.Entity.Element.Name} AS {generatedQuery.StartArgument.Entity.Alias}");
                var i = 1;
                foreach (var Op in generatedQuery.PipelineOperators)
                {
                    Console.WriteLine($"Operator {i++}: {Op.ToString()}");
                }
                Console.WriteLine("*************");

                QueryRunner runner = new QueryRunner("mongodb://localhost:27017", "sampleAuthorBookPublisher");
                Console.WriteLine(runner.GetJSON(generatedQuery.Run()));
            }

            // Nested join example using manual code
            Console.WriteLine("Running example ============");
            QueryableEntity Author    = new QueryableEntity(mapping.EntityRelationshipModel.FindByName("Author"));
            QueryableEntity Book      = new QueryableEntity(mapping.EntityRelationshipModel.FindByName("Book"));
            QueryableEntity Publisher = new QueryableEntity(mapping.EntityRelationshipModel.FindByName("Publisher"));

            Relationship BookAndAuthor = (Relationship)mapping.EntityRelationshipModel.FindByName("BookAndAuthor");
            Relationship PublishedBy   = (Relationship)mapping.EntityRelationshipModel.FindByName("PublishedBy");

            ComputedEntity BookAndPublisher = new ComputedEntity("BookAndPublisher", Book,
                                                                 PublishedBy, new List <QueryableEntity>()
            {
                Publisher
            });

            RelationshipJoinOperator JoinOp = new RelationshipJoinOperator(Author, BookAndAuthor,
                                                                           new List <QueryableEntity>()
            {
                new QueryableEntity(BookAndPublisher)
            },
                                                                           mapping.ERMongoMapping);

            FromArgument fromArg = new FromArgument(Author, mapping.ERMongoMapping);

            List <AlgebraOperator> Operations = new List <AlgebraOperator>()
            {
                JoinOp
            };
            QueryGenerator queryGen    = new QueryGenerator(fromArg, Operations);
            string         queryString = queryGen.Run();

            QueryRunner queryRunner = new QueryRunner("mongodb://localhost:27017", "sampleAuthorBookPublisher");

            Console.WriteLine(queryRunner.GetJSON(queryString));
        }
Esempio n. 30
0
        public void ProjectComputedEntity()
        {
            // Asserts if the query result for a relationship join operation is equal
            // to a handcrafted query
            RequiredDataContainer ModelData = ProjectDataProvider.ComputedEntityData();

            // Load handcrafted query
            string HandcraftedQuery = Utils.ReadQueryFromFile("HandcraftedQueries/projectQuery.js");

            // Assert if the handcrafted query is not null
            Assert.IsNotNull(HandcraftedQuery);

            // Prepare query generator
            ComputedEntity CarRepairedByGarage = new ComputedEntity("CarManufacturedBy",
                                                                    new QueryableEntity((Entity)ModelData.EntityRelationshipModel.FindByName("Car"), "car"),
                                                                    (Relationship)ModelData.EntityRelationshipModel.FindByName("ManufacturedBy"),
                                                                    new List <QueryableEntity> {
                new QueryableEntity((Entity)ModelData.EntityRelationshipModel.FindByName("Manufacturer"), "manufacturer")
            });

            RelationshipJoinOperator RJoinOp = new RelationshipJoinOperator(
                new QueryableEntity((Entity)ModelData.EntityRelationshipModel.FindByName("Person"), "person"),
                (Relationship)ModelData.EntityRelationshipModel.FindByName("Owns"),
                new List <QueryableEntity> {
                new QueryableEntity(CarRepairedByGarage)
            },
                ModelData.ERMongoMapping);

            VirtualMap VMap = RJoinOp.ComputeVirtualMap();

            Dictionary <string, ProjectExpression> ProjectPersonAttrs = new Dictionary <string, ProjectExpression>();

            QueryableEntity Person       = new QueryableEntity(ModelData.EntityRelationshipModel.FindByName("Person"));
            QueryableEntity Car          = new QueryableEntity(ModelData.EntityRelationshipModel.FindByName("Car"));
            QueryableEntity Manufacturer = new QueryableEntity(ModelData.EntityRelationshipModel.FindByName("Manufacturer"));

            List <ProjectArgument> ProjectArguments = new List <ProjectArgument>();

            ProjectArguments.Add(new ProjectArgument(Person.GetAttribute("name"), Person, new BooleanExpr(true)));
            ProjectArguments.Add(new ProjectArgument(Car.GetAttribute("model"), Car, new BooleanExpr(true)));
            ProjectArguments.Add(new ProjectArgument(Car.GetAttribute("year"), Car, new BooleanExpr(true)));
            ProjectArguments.Add(new ProjectArgument(Manufacturer.GetAttribute("name"), Manufacturer, new BooleanExpr(true)));

            ProjectStage ProjectOp = new ProjectStage(ProjectArguments, VMap);

            List <AlgebraOperator> OpList = new List <AlgebraOperator> {
                RJoinOp, ProjectOp
            };
            FromArgument StartArg = new FromArgument(new QueryableEntity(ModelData.EntityRelationshipModel.FindByName("Person")),
                                                     ModelData.ERMongoMapping);

            QueryGenerator QueryGen = new QueryGenerator(StartArg, OpList);

            string GeneratedQuery = QueryGen.Run();

            // Assert if generated query is not null
            Assert.IsNotNull(GeneratedQuery);

            // Run Queries
            QueryRunner Runner = new QueryRunner("mongodb://localhost:27017", "ceManyToMany2");

            string HandcraftedResult = Runner.GetJSON(HandcraftedQuery);
            string GeneratedResult   = Runner.GetJSON(GeneratedQuery);

            // Check if either result is null
            Assert.IsNotNull(HandcraftedResult);
            Assert.IsNotNull(GeneratedResult);

            // Check if both results are equal
            Assert.IsTrue(JToken.DeepEquals(JToken.Parse(HandcraftedResult), JToken.Parse(GeneratedResult)));
        }