Exemple #1
0
        public void GetAllProductsFromStore()
        {
            RequiredDataContainer DataMap                   = MarketingCMSDataProvider.MapEntitiesToCollections();
            RequiredDataContainer DataMapDuplicates         = MarketingCMSDataProvider.MapEntitiesToCollectionDuplicates();
            RequiredDataContainer DataMapCategoryDuplicated = MarketingCMSDataProvider.MapEntitiesToCollectionCategoryDuplicated();
            RequiredDataContainer DataMapStoreDuplicated    = MarketingCMSDataProvider.MapEntitiesToCollectionsStoreDuplicated();
            RequiredDataContainer DataMapUserDuplicated     = MarketingCMSDataProvider.MapEntitiesToCollectionsUserDuplicated();

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

            RelationshipJoinOperator JoinOpMap1 = new RelationshipJoinOperator(Store,
                                                                               (Relationship)DataMap.EntityRelationshipModel.FindByName("StoreHasManyProducts"),
                                                                               new List <QueryableEntity>()
            {
                Product
            },
                                                                               DataMap.ERMongoMapping);

            RelationshipJoinOperator JoinOpMap2 = new RelationshipJoinOperator(Store,
                                                                               (Relationship)DataMapDuplicates.EntityRelationshipModel.FindByName("StoreHasManyProducts"),
                                                                               new List <QueryableEntity>()
            {
                Product
            },
                                                                               DataMapDuplicates.ERMongoMapping);

            RelationshipJoinOperator JoinOpMap3 = new RelationshipJoinOperator(Store,
                                                                               (Relationship)DataMapCategoryDuplicated.EntityRelationshipModel.FindByName("StoreHasManyProducts"),
                                                                               new List <QueryableEntity>()
            {
                Product
            },
                                                                               DataMapCategoryDuplicated.ERMongoMapping);

            RelationshipJoinOperator JoinOpMap4 = new RelationshipJoinOperator(Store,
                                                                               (Relationship)DataMapStoreDuplicated.EntityRelationshipModel.FindByName("StoreHasManyProducts"),
                                                                               new List <QueryableEntity>()
            {
                Product
            },
                                                                               DataMapStoreDuplicated.ERMongoMapping);

            RelationshipJoinOperator JoinOpMap5 = new RelationshipJoinOperator(Store,
                                                                               (Relationship)DataMapUserDuplicated.EntityRelationshipModel.FindByName("StoreHasManyProducts"),
                                                                               new List <QueryableEntity>()
            {
                Product
            },
                                                                               DataMapUserDuplicated.ERMongoMapping);

            SortArgument SortArg = new SortArgument(Store, Store.GetAttribute("store_id"), MongoDBSort.Ascending);

            SortStage SortOpMap1 = new SortStage(new List <SortArgument>()
            {
                SortArg
            }, DataMap.ERMongoMapping);
            SortStage SortOpMap2 = new SortStage(new List <SortArgument>()
            {
                SortArg
            }, DataMapDuplicates.ERMongoMapping);
            SortStage SortOpMap3 = new SortStage(new List <SortArgument>()
            {
                SortArg
            }, DataMapCategoryDuplicated.ERMongoMapping);
            SortStage SortOpMap4 = new SortStage(new List <SortArgument>()
            {
                SortArg
            }, DataMapStoreDuplicated.ERMongoMapping);
            SortStage SortOpMap5 = new SortStage(new List <SortArgument>()
            {
                SortArg
            }, DataMapUserDuplicated.ERMongoMapping);

            List <AlgebraOperator> OperatorsToExecuteMap1 = new List <AlgebraOperator>()
            {
                JoinOpMap1, SortOpMap1
            };
            List <AlgebraOperator> OperatorsToExecuteMap2 = new List <AlgebraOperator>()
            {
                JoinOpMap2, SortOpMap2
            };
            List <AlgebraOperator> OperatorsToExecuteMap3 = new List <AlgebraOperator>()
            {
                JoinOpMap3, SortOpMap3
            };
            List <AlgebraOperator> OperatorsToExecuteMap4 = new List <AlgebraOperator>()
            {
                JoinOpMap4, SortOpMap4
            };
            List <AlgebraOperator> OperatorsToExecuteMap5 = new List <AlgebraOperator>()
            {
                JoinOpMap5, SortOpMap5
            };

            FromArgument StartArgMap1 = new FromArgument(Store, DataMap.ERMongoMapping);
            FromArgument StartArgMap2 = new FromArgument(Store, DataMapDuplicates.ERMongoMapping);
            FromArgument StartArgMap3 = new FromArgument(Store, DataMapCategoryDuplicated.ERMongoMapping);
            FromArgument StartArgMap4 = new FromArgument(Store, DataMapStoreDuplicated.ERMongoMapping);
            FromArgument StartArgMap5 = new FromArgument(Store, DataMapUserDuplicated.ERMongoMapping);

            QueryGenerator GeneratorMap1 = new QueryGenerator(StartArgMap1, OperatorsToExecuteMap1);
            QueryGenerator GeneratorMap2 = new QueryGenerator(StartArgMap2, OperatorsToExecuteMap2);
            QueryGenerator GeneratorMap3 = new QueryGenerator(StartArgMap3, OperatorsToExecuteMap3);
            QueryGenerator GeneratorMap4 = new QueryGenerator(StartArgMap4, OperatorsToExecuteMap4);
            QueryGenerator GeneratorMap5 = new QueryGenerator(StartArgMap5, OperatorsToExecuteMap5);

            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");

            Assert.IsTrue(JToken.DeepEquals(JToken.Parse(ResultMap1), JToken.Parse(ResultMap2)));
            Assert.IsTrue(JToken.DeepEquals(JToken.Parse(ResultMap1), JToken.Parse(ResultMap3)));
            Assert.IsTrue(JToken.DeepEquals(JToken.Parse(ResultMap1), JToken.Parse(ResultMap4)));
            Assert.IsTrue(JToken.DeepEquals(JToken.Parse(ResultMap1), JToken.Parse(ResultMap5)));
        }
Exemple #2
0
        public void GetAllProducts()
        {
            RequiredDataContainer DataMap                   = MarketingCMSDataProvider.MapEntitiesToCollections();
            RequiredDataContainer DataMapDuplicates         = MarketingCMSDataProvider.MapEntitiesToCollectionDuplicates();
            RequiredDataContainer DataMapCategoryDuplicated = MarketingCMSDataProvider.MapEntitiesToCollectionCategoryDuplicated();
            RequiredDataContainer DataMapStoreDuplicated    = MarketingCMSDataProvider.MapEntitiesToCollectionsStoreDuplicated();
            RequiredDataContainer DataMapUserDuplicated     = 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"));

            RelationshipJoinOperator RJoinStoreMap1 = new RelationshipJoinOperator(Product,
                                                                                   (Relationship)DataMap.EntityRelationshipModel.FindByName("StoreHasManyProducts"),
                                                                                   new List <QueryableEntity>()
            {
                Store
            },
                                                                                   DataMap.ERMongoMapping);

            RelationshipJoinOperator RJoinCategoryMap1 = new RelationshipJoinOperator(Product,
                                                                                      (Relationship)DataMap.EntityRelationshipModel.FindByName("CategoryHasManyProducts"),
                                                                                      new List <QueryableEntity>()
            {
                Category
            },
                                                                                      DataMap.ERMongoMapping);

            RelationshipJoinOperator RJoinUserMap1 = new RelationshipJoinOperator(Product,
                                                                                  (Relationship)DataMap.EntityRelationshipModel.FindByName("HasManyProducts"),
                                                                                  new List <QueryableEntity>()
            {
                User
            },
                                                                                  DataMap.ERMongoMapping);

            // DEBUG
            //LimitStage LimitOp = new LimitStage( 150000 );
            SortArgument SortArg = new SortArgument(Product, Product.GetAttribute("product_id"), MongoDBSort.Ascending);
            SortStage    SortOp  = new SortStage(new List <SortArgument>()
            {
                SortArg
            }, DataMap.ERMongoMapping);
            SortStage SortOp2 = new SortStage(new List <SortArgument>()
            {
                SortArg
            }, DataMapDuplicates.ERMongoMapping);
            SortStage SortOp3 = new SortStage(new List <SortArgument>()
            {
                SortArg
            }, DataMapCategoryDuplicated.ERMongoMapping);
            SortStage SortOp4 = new SortStage(new List <SortArgument>()
            {
                SortArg
            }, DataMapStoreDuplicated.ERMongoMapping);
            SortStage SortOp5 = new SortStage(new List <SortArgument>()
            {
                SortArg
            }, DataMapUserDuplicated.ERMongoMapping);
            // =====

            // Build and execute Map1 query
            List <AlgebraOperator> Map1OperatorsList = new List <AlgebraOperator>()
            {
                RJoinStoreMap1, RJoinCategoryMap1, RJoinUserMap1, SortOp
            };

            FromArgument   StartArgMap1 = new FromArgument(Product, DataMap.ERMongoMapping);
            QueryGenerator Generator    = new QueryGenerator(StartArgMap1, Map1OperatorsList);

            string Map1Query = Generator.Run();

            Assert.IsNotNull(Map1Query, "Generated query [Map1Query] cannot be null");

            RelationshipJoinOperator RJoinStoreMap2 = new RelationshipJoinOperator(Product,
                                                                                   (Relationship)DataMapDuplicates.EntityRelationshipModel.FindByName("StoreHasManyProducts"),
                                                                                   new List <QueryableEntity>()
            {
                Store
            },
                                                                                   DataMapDuplicates.ERMongoMapping);

            RelationshipJoinOperator RJoinCategoryMap2 = new RelationshipJoinOperator(Product,
                                                                                      (Relationship)DataMapDuplicates.EntityRelationshipModel.FindByName("CategoryHasManyProducts"),
                                                                                      new List <QueryableEntity>()
            {
                Category
            },
                                                                                      DataMapDuplicates.ERMongoMapping);

            RelationshipJoinOperator RJoinUserMap2 = new RelationshipJoinOperator(Product,
                                                                                  (Relationship)DataMapDuplicates.EntityRelationshipModel.FindByName("HasManyProducts"),
                                                                                  new List <QueryableEntity>()
            {
                User
            },
                                                                                  DataMapDuplicates.ERMongoMapping);

            List <AlgebraOperator> MapDuplicatesOpList = new List <AlgebraOperator>()
            {
                RJoinStoreMap2, RJoinCategoryMap2, RJoinUserMap2, SortOp2
            };

            FromArgument   StartArgMap2        = new FromArgument(Product, DataMapDuplicates.ERMongoMapping);
            QueryGenerator GeneratorDuplicates = new QueryGenerator(StartArgMap2, MapDuplicatesOpList);

            string MapDuplicatesQuery = GeneratorDuplicates.Run();

            Assert.IsNotNull(MapDuplicatesQuery, "Generated query [MapDuplicatesQuery] cannot be null");

            RelationshipJoinOperator RJoinStoreMap3 = new RelationshipJoinOperator(Product,
                                                                                   (Relationship)DataMapCategoryDuplicated.EntityRelationshipModel.FindByName("StoreHasManyProducts"),
                                                                                   new List <QueryableEntity>()
            {
                Store
            },
                                                                                   DataMapCategoryDuplicated.ERMongoMapping);

            RelationshipJoinOperator RJoinCategoryMap3 = new RelationshipJoinOperator(Product,
                                                                                      (Relationship)DataMapCategoryDuplicated.EntityRelationshipModel.FindByName("CategoryHasManyProducts"),
                                                                                      new List <QueryableEntity>()
            {
                Category
            },
                                                                                      DataMapCategoryDuplicated.ERMongoMapping);

            RelationshipJoinOperator RJoinUserMap3 = new RelationshipJoinOperator(Product,
                                                                                  (Relationship)DataMapCategoryDuplicated.EntityRelationshipModel.FindByName("HasManyProducts"),
                                                                                  new List <QueryableEntity>()
            {
                User
            },
                                                                                  DataMapCategoryDuplicated.ERMongoMapping);

            List <AlgebraOperator> MapCategoryDuplicatedOpList = new List <AlgebraOperator>()
            {
                RJoinStoreMap3, RJoinCategoryMap3, RJoinUserMap3, SortOp3
            };

            FromArgument   StartArgCategoryDuplicated  = new FromArgument(Product, DataMapCategoryDuplicated.ERMongoMapping);
            QueryGenerator GeneratorCategoryDuplicated = new QueryGenerator(StartArgCategoryDuplicated, MapCategoryDuplicatedOpList);

            string MapCategoryDuplicatedQuery = GeneratorCategoryDuplicated.Run();

            Assert.IsNotNull(MapCategoryDuplicatedQuery, "Generated query [MapCategoryDuplicatedQuery] cannot be null");

            RelationshipJoinOperator RJoinStoreMap4 = new RelationshipJoinOperator(Product,
                                                                                   (Relationship)DataMapStoreDuplicated.EntityRelationshipModel.FindByName("StoreHasManyProducts"),
                                                                                   new List <QueryableEntity>()
            {
                Store
            },
                                                                                   DataMapStoreDuplicated.ERMongoMapping);

            RelationshipJoinOperator RJoinCategoryMap4 = new RelationshipJoinOperator(Product,
                                                                                      (Relationship)DataMapStoreDuplicated.EntityRelationshipModel.FindByName("CategoryHasManyProducts"),
                                                                                      new List <QueryableEntity>()
            {
                Category
            },
                                                                                      DataMapStoreDuplicated.ERMongoMapping);

            RelationshipJoinOperator RJoinUserMap4 = new RelationshipJoinOperator(Product,
                                                                                  (Relationship)DataMapStoreDuplicated.EntityRelationshipModel.FindByName("HasManyProducts"),
                                                                                  new List <QueryableEntity>()
            {
                User
            },
                                                                                  DataMapStoreDuplicated.ERMongoMapping);

            List <AlgebraOperator> MapStoreDuplicatedOpList = new List <AlgebraOperator>()
            {
                RJoinStoreMap4, RJoinCategoryMap4, RJoinUserMap4, SortOp4
            };

            FromArgument   StartArgStoreDuplicated  = new FromArgument(Product, DataMapStoreDuplicated.ERMongoMapping);
            QueryGenerator GeneratorStoreDuplicated = new QueryGenerator(StartArgStoreDuplicated, MapStoreDuplicatedOpList);

            string MapStoreDuplicatedQuery = GeneratorStoreDuplicated.Run();

            Assert.IsNotNull(MapStoreDuplicatedQuery, "Generated query [MapStoreDuplicatedQuery] cannot be null");

            RelationshipJoinOperator RJoinStoreMap5 = new RelationshipJoinOperator(Product,
                                                                                   (Relationship)DataMapUserDuplicated.EntityRelationshipModel.FindByName("StoreHasManyProducts"),
                                                                                   new List <QueryableEntity>()
            {
                Store
            },
                                                                                   DataMapUserDuplicated.ERMongoMapping);

            RelationshipJoinOperator RJoinCategoryMap5 = new RelationshipJoinOperator(Product,
                                                                                      (Relationship)DataMapUserDuplicated.EntityRelationshipModel.FindByName("CategoryHasManyProducts"),
                                                                                      new List <QueryableEntity>()
            {
                Category
            },
                                                                                      DataMapUserDuplicated.ERMongoMapping);

            RelationshipJoinOperator RJoinUserMap5 = new RelationshipJoinOperator(Product,
                                                                                  (Relationship)DataMapUserDuplicated.EntityRelationshipModel.FindByName("HasManyProducts"),
                                                                                  new List <QueryableEntity>()
            {
                User
            },
                                                                                  DataMapUserDuplicated.ERMongoMapping);

            List <AlgebraOperator> MapUserDuplicatedOpList = new List <AlgebraOperator>()
            {
                RJoinStoreMap5, RJoinCategoryMap5, RJoinUserMap5, SortOp5
            };

            FromArgument   StartArgUserDuplicated  = new FromArgument(Product, DataMapUserDuplicated.ERMongoMapping);
            QueryGenerator GeneratorUserDuplicated = new QueryGenerator(StartArgUserDuplicated, MapUserDuplicatedOpList);

            string MapUserDuplicatedQuery = GeneratorUserDuplicated.Run();

            Assert.IsNotNull(MapUserDuplicatedQuery, "Generated query [MapUserDuplicatedQuery] 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(Map1Query);
            string ResultMap2 = RunnerMap2.GetJSON(MapDuplicatesQuery);
            string ResultMap3 = RunnerMap3.GetJSON(MapCategoryDuplicatedQuery);
            string ResultMap4 = RunnerMap4.GetJSON(MapStoreDuplicatedQuery);
            string ResultMap5 = RunnerMap5.GetJSON(MapUserDuplicatedQuery);

            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(JToken.DeepEquals(JToken.Parse(ResultMap1), JToken.Parse(ResultMap2)));
            Assert.IsTrue(JToken.DeepEquals(JToken.Parse(ResultMap1), JToken.Parse(ResultMap3)));
            Assert.IsTrue(JToken.DeepEquals(JToken.Parse(ResultMap1), JToken.Parse(ResultMap4)));
            Assert.IsTrue(JToken.DeepEquals(JToken.Parse(ResultMap1), JToken.Parse(ResultMap5)));
        }