public void ExtendsMappingBasedOnExistingDefinition() { _sut = DynamicQueryMapping.Create(new IndexQueryServerSide("FROM Users WHERE StartsWith(FirstName, 'a') ORDER BY Count AS long")); var existingDefinition = _sut.CreateAutoIndexDefinition(); _sut = DynamicQueryMapping.Create(new IndexQueryServerSide("FROM Users WHERE StartsWith(LastName, 'A') ORDER BY Age AS double")); _sut.ExtendMappingBasedOn(existingDefinition); var definition = _sut.CreateAutoIndexDefinition(); Assert.Equal(1, definition.Collections.Count); Assert.Equal("Users", definition.Collections.Single()); Assert.True(definition.ContainsField("FirstName")); Assert.True(definition.ContainsField("LastName")); Assert.True(definition.ContainsField("Age")); Assert.True(definition.ContainsField("Count")); Assert.Equal("Auto/Users/ByAgeAndCountAndFirstNameAndLastName", definition.Name); }
public void Extends_mapping_based_on_existing_definition_if_group_by_fields_match() { _sut = DynamicQueryMapping.Create( new IndexQueryServerSide("FROM Users GROUP BY Location WHERE StartsWith(Location, 'A') ORDER BY Count SELECT Location, count() ")); var existingDefinition = _sut.CreateAutoIndexDefinition(); _sut = DynamicQueryMapping.Create(new IndexQueryServerSide( "FROM Users GROUP BY Location WHERE StartsWith(Location, 'A') ORDER BY Age as long SELECT Location, count(), sum(Age) ")); _sut.ExtendMappingBasedOn(existingDefinition); var definition = (AutoMapReduceIndexDefinition)_sut.CreateAutoIndexDefinition(); Assert.Equal(1, definition.Collections.Count); Assert.Equal("Users", definition.Collections.Single()); Assert.True(definition.ContainsField("Count")); Assert.True(definition.ContainsField("Age")); Assert.True(definition.GroupByFields.ContainsKey("Location")); Assert.Equal("Auto/Users/ByAgeAndCountReducedByLocation", definition.Name); }
public void Extends_mapping_based_on_existing_definition_if_group_by_fields_match() { _sut = DynamicQueryMapping.Create("Users", new IndexQueryServerSide { Query = "Location:A*", DynamicMapReduceFields = new [] { new DynamicMapReduceField { Name = "Count", OperationType = FieldMapReduceOperation.Count }, new DynamicMapReduceField { Name = "Location", IsGroupBy = true } }, SortedFields = new[] { new SortedField("Count_Range"), } }); var existingDefinition = _sut.CreateAutoIndexDefinition(); _sut = DynamicQueryMapping.Create("Users", new IndexQueryServerSide { Query = "Location:A*", DynamicMapReduceFields = new[] { new DynamicMapReduceField { Name = "Count", OperationType = FieldMapReduceOperation.Count, }, new DynamicMapReduceField { Name = "Age", OperationType = FieldMapReduceOperation.Sum }, new DynamicMapReduceField { Name = "Location", IsGroupBy = true } }, SortedFields = new [] { new SortedField("Age_Range"), } }); _sut.ExtendMappingBasedOn(existingDefinition); var definition = (AutoMapReduceIndexDefinition)_sut.CreateAutoIndexDefinition(); Assert.Equal(1, definition.Collections.Length); Assert.Equal("Users", definition.Collections[0]); Assert.True(definition.ContainsField("Count")); Assert.True(definition.ContainsField("Age")); Assert.True(definition.GroupByFields.ContainsKey("Location")); Assert.Equal(SortOptions.NumericDefault, definition.GetField("Count").SortOption); Assert.Equal(SortOptions.NumericDefault, definition.GetField("Age").SortOption); Assert.Equal("Auto/Users/ByAgeAndCountSortByAgeCountReducedByLocation", definition.Name); }