Esempio n. 1
0
        public void CreateMapReduceIndex()
        {
            var mapping = new Database.Data.DynamicQueryMapping
            {
                AggregationOperation = AggregationOperation.Count,
                Items = new[]
                {
                    new DynamicQueryMappingItem
                    {
                        From = "User.Name",
                        To   = "UserName"
                    }
                }
            };


            IndexDefinition definition = mapping.CreateIndexDefinition();

            Assert.Equal(@"from doc in docs
select new { UserName = doc.User.Name, Count = 1 }", definition.Map);

            Assert.Equal(@"from result in results
group result by result.UserName
into g
select new
{
	UserName = g.Key,
	Count = g.Sum(x=>x.Count)
}
", definition.Reduce);
        }
Esempio n. 2
0
        public void CreateDefinitionSupportsNestedProperties()
        {
            var mapping = new Database.Data.DynamicQueryMapping
            {
                Items = new[]
                {
                    new DynamicQueryMappingItem
                    {
                        From = "User.Name",
                        To   = "UserName"
                    }
                }
            };

            IndexDefinition definition = mapping.CreateIndexDefinition();

            Assert.Equal("from doc in docs\nselect new {\n\tUserName = doc.User.Name\n}", definition.Map);
        }
Esempio n. 3
0
        public void CreateDefinitionSupportsArrayProperties()
        {
            var mapping = new Database.Data.DynamicQueryMapping

            {
                Items = new[]
                {
                    new DynamicQueryMappingItem
                    {
                        From = "Tags,Name",
                        To   = "docTagsName"
                    }
                }
            };

            IndexDefinition definition = mapping.CreateIndexDefinition();

            const string map = "from doc in docs\nselect new {\n\tdocTagsName = (\n\t\tfrom docTagsItem in ((IEnumerable<dynamic>)doc.Tags).DefaultIfEmpty()\n\t\tselect docTagsItem.Name).ToArray()\n}";

            Assert.Equal(map, definition.Map);
        }
Esempio n. 4
0
        public void CreateDefinitionSupportsArrayProperties()
        {
            var mapping = new Database.Data.DynamicQueryMapping

            {
                Items = new[]
                {
                    new DynamicQueryMappingItem
                    {
                        From = "Tags,Name",
                        To   = "docTagsName"
                    }
                }
            };


            IndexDefinition definition = mapping.CreateIndexDefinition();

            Assert.Equal(
                "from doc in docs\r\nfrom docTagsItem in ((IEnumerable<dynamic>)doc.Tags).DefaultIfEmpty()\r\nselect new { docTagsName = docTagsItem.Name }",
                definition.Map);
        }
		public void CreateDefinitionSupportsSimpleProperties()
		{
			var mapping = new Database.Data.DynamicQueryMapping

			{
				Items = new[]
				{
					new DynamicQueryMappingItem
					{
						From = "Name",
						To = "Name"
					}
				}
			};


			IndexDefinition definition = mapping.CreateIndexDefinition();

			Assert.Equal("from doc in docs\r\nselect new { Name = doc.Name }", definition.Map);
		}
		public void CreateDefinitionSupportsArrayProperties()
		{
			var mapping = new Database.Data.DynamicQueryMapping

			{
				Items = new[]
				{
					new DynamicQueryMappingItem
					{
						From = "Tags,Name",
						To = "docTagsName"
					}
				}
			};

			IndexDefinition definition = mapping.CreateIndexDefinition();

            Assert.Equal(@"from doc in docs
select new
{
	docTagsName = (from docTagsItem in ((IEnumerable<dynamic>)doc.Tags).DefaultIfEmpty() select docTagsItem.Name).ToArray()
}",
				definition.Map);
		}
Esempio n. 7
0
		public void CreateMapReduceIndex()
		{
			var mapping = new Database.Data.DynamicQueryMapping
			{
				AggregationOperation = AggregationOperation.Count,
				Items = new[]
				{
					new DynamicQueryMappingItem
					{
						From = "User.Name",
						To = "UserName"
					}
				}
			};


			IndexDefinition definition = mapping.CreateIndexDefinition();

			Assert.Equal(@"from doc in docs
select new { UserName = doc.User.Name, Count = 1 }", definition.Map);

			Assert.Equal(@"from result in results
group result by result.UserName
into g
select new
{
	UserName = g.Key,
	Count = g.Sum(x=>x.Count)
}
", definition.Reduce);
		}