public void Create_should_create_method_name_from_name_and_type() { var a = FieldName.Create("Hello", TypeName.Create("System", "String")); var b = FieldName.Parse("Hello:System.String"); Assert.Equal(a, b); }
public void Create_should_create_event_name_from_name_and_type() { var a = EventName.Create("Hello", TypeName.Create("System", "EventHandler")); var b = EventName.Parse("Hello:System.EventHandler"); Assert.Equal(a, b); }
public void DelegatesToNativeLoader() { var typeName = TypeName.Create("System.String", "mscorlib"); var type = TypeLoader.Create(new string[0])(typeName); Assert.AreEqual(typeof(string), type.Value); }
private ITypeDescription CreateArrayType() { TypeName theName = TypeName.Create("System.Int32", "mscorelib", new TypeName[0], 0); var innerType = SimpleClassDescription.Create(theName, f => new SimpleFieldDescription[0]); return(ArrayDescription.Create(innerType, 1)); }
public void ReturnsEmptyResultOnUnknownType() { var typeName = TypeName.Create("DoesNotExist.ClassName", "DoesNotExist"); var type = TypeLoader.Create(new string[0])(typeName); Assert.IsFalse(type.HasValue); }
public List <InformationBase> GetItemWithAttachments(Guid itemId, IEnumerable <Type> types, bool includeItemValues = false) { var result = new List <InformationBase>(); var typeNames = new List <TypeName>(); foreach (var t in types) { typeNames.Add(TypeName.Create(t)); } var response = _elasticClient.Search <dynamic>(s => s .Type(Types.Type(typeNames)) //.ConcreteTypeSelector((h,t) => h.GetType()) .Size(1000) .Query(q => q .MultiMatch(m => m .Query(itemId.ToString()) .Fields(new[] { "ItemId^10", "Attachments" })))); foreach (var item in response.Documents) { item.IsNew = false; result.Add(item); if (item.ItemId == itemId && includeItemValues) { result.AddRange(_itemMetadataProvider.GetItemMetadataValues(item)); } } return(result); }
public void NestedClassName() { var complex = TypeName.Create("Type.Parent+Child", "Assembly.Name"); Assert.AreEqual("Type.Parent_Child", complex.NameWithGenerics); }
public void GenericNameWithTwoParams() { var complex = TestMetaData.CreateGenericType( TypeName.Create("System.Int32", "mscorelib"), TypeName.Create("System.Int64", "mscorelib")); Assert.AreEqual("TheType_2_Int32_Int64", complex.Name); }
public void ArrayType() { var theName = TypeName.Create("System.Int32", "mscorelib", new TypeName[0], 0); var innerType = SimpleClassDescription.Create(theName, f => new SimpleFieldDescription[0]); var arrayType = ArrayDescription.Create(innerType, 1); Assert.IsTrue(arrayType.IsArray); }
public void LoadMixedGenericType() { var genericArgument = TypeName.Create("DoesNotExist.ClassName", "DoesNotExist"); var listName = TypeName.Create("System.Collections.Generic.List", "mscorlib", new[] { genericArgument }); var found = TypeLoader.Create(new[] { @"..\..\Gamlor.Db4oPad.ExternalAssemblyForTests.dll" })(listName); Assert.IsFalse(found.HasValue); }
public void CanLoadGenericTypeDefinition() { var genericArgument = TypeName.Create("DoesNotExist.ClassName", "DoesNotExist"); var listName = TypeName.Create("System.Collections.Generic.List`1", "mscorlib", new[] { genericArgument }); var type = TypeLoader.Create(new string[0])(listName.GetGenericTypeDefinition()); Assert.AreEqual(typeof(List <>), type.Value); }
public void CascadedGenericsName() { var theType = TestMetaData.CreateGenericType(); var complex = TestMetaData.CreateGenericType( TypeName.Create("System.Int32", "mscorelib"), theType.TypeName); Assert.AreEqual("TheType_2_Int32_TheType_1_Int32", complex.Name); }
public void ArrayCanCreateItself() { TypeName theName = TypeName.Create("System.Int32", "mscorelib", new TypeName[0], 0); var innerType = SimpleClassDescription.Create(theName, f => new SimpleFieldDescription[0]); var arrayType = ArrayDescription.Create(innerType, 1); var intArray = arrayType.TryResolveType(t => typeof(int)); Assert.AreEqual(typeof(int[]), intArray.Value); }
public void Format_use_unbound_generic_parameter_positions_should_work_with_method_generics() { var pmType = TypeName.Create(null, "Func`1").MakeGenericType(MethodName.GenericParameter(1)); var format = new MetadataNameFormat { UseGenericParameterPositions = true, IncludeTypeParameters = true }; Assert.Equal("Func<``1>", pmType.ToString(format)); }
internal static IEnumerable <ITypeDescription> GenericType() { var stringList = KnownType.Create(typeof(List <string>)); var stringType = typeof(string); var genericArguments = GenericArg(stringType); var type = SimpleClassDescription.Create(TypeName.Create(TestMetaData.SingleFieldTypeName + "`1", TestMetaData.AssemblyName, genericArguments), f => TestMetaData.CreateField(stringList)); return(new[] { type, stringList }); }
private IEnumerable <ITypeDescription> SubClassType() { var baseClasses = TestMetaData.CreateSingleFieldClass(); var intType = KnownType.Create(typeof(int)); var baseClass = baseClasses.Single(b => !b.TryResolveType(TestUtils.FindNothingTypeResolver).HasValue); var subType = SimpleClassDescription.Create( TypeName.Create("ANamespace.SubClass", TestMetaData.AssemblyName), Maybe.From(baseClass), f => TestMetaData.CreateField("subField", intType)); return(baseClasses.Concat(new[] { intType, subType })); }
private static IEnumerable <ITypeDescription> TwoGenericInstances() { var stringList = KnownType.Create(typeof(List <string>)); var stringType = typeof(string); var stringGenericArgs = GenericArg(stringType); var stringInstance = SimpleClassDescription.Create(TypeName.Create(TestMetaData.SingleFieldTypeName, TestMetaData.AssemblyName, stringGenericArgs), f => TestMetaData.CreateField(stringList)); var intList = KnownType.Create(typeof(List <int>)); var intType = typeof(int); var intGenericArgs = GenericArg(intType); var intInstance = SimpleClassDescription.Create(TypeName.Create(TestMetaData.SingleFieldTypeName, TestMetaData.AssemblyName, intGenericArgs), f => TestMetaData.CreateField(intList)); return(new[] { stringInstance, intInstance, stringList, intList }); }
private void PrepareIndexes(IRootResolver resolver) { _elasticClient = resolver.Resolve <IElasticClient>(); var readModelTypes = GetLoadableTypes <ElasticsearchTypeAttribute>(typeof(ElasticsearchThingyReadModel).Assembly); foreach (var readModelType in readModelTypes) { var esType = readModelType.GetTypeInfo() .GetCustomAttribute <ElasticsearchTypeAttribute>(); var aliasResponse = _elasticClient.GetAlias(x => x.Name(esType.Name)); if (aliasResponse.ApiCall.Success) { if (aliasResponse.Indices != null) { foreach (var indice in aliasResponse?.Indices) { _elasticClient.DeleteAlias(indice.Key, esType.Name); _elasticClient.DeleteIndex(indice.Key, d => d.RequestConfiguration(c => c.AllowedStatusCodes((int)HttpStatusCode.NotFound))); } _elasticClient.DeleteIndex(esType.Name, d => d.RequestConfiguration(c => c.AllowedStatusCodes((int)HttpStatusCode.NotFound))); } } var indexName = GetIndexName(esType.Name); _indexes.Add(indexName); _elasticClient.CreateIndex(indexName, c => c .Settings(s => s .NumberOfShards(1) .NumberOfReplicas(0)) .Aliases(a => a.Alias(esType.Name)) .Mappings(m => m .Map(TypeName.Create(readModelType), d => d .AutoMap()))); } }
public int EsIndex(List <Post> lists) { Result result = new Result(); int n = 0; lists.ForEach(l => { result = this.ElasticLinqClient.Index(l, t => t.Index("mypost") .Type(TypeName.Create <Post>()) .Id(l.Id)).Result; if (result == Result.Created || result == Result.Updated) { n++; } }); return(n); }
private async Task <IGetResponse <T> > GetAsync <T>(T document, Id key) where T : class { GetDb <T>(); return(await _elasticClient.GetAsync <T>(document, id => new GetRequest(DefaultIndex, TypeName.Create(typeof(T)), key))); }
public void DontCrashOnNonExistingFile() { var found = TypeLoader.Create(new[] { Path.GetRandomFileName() })(TypeName.Create("DoesNotExist.ClassName", "DoesNotExist")); Assert.IsFalse(found.HasValue); }
public void DontCrashOnBogusAssemblies() { var found = TypeLoader.Create(new[] { Path.GetTempFileName() })(TypeName.Create("DoesNotExist.ClassName", "DoesNotExist")); Assert.IsFalse(found.HasValue); }
internal static IEnumerable <TypeName> GenericArg(Type intType) { return(new[] { TypeName.Create(intType.FullName, intType.Assembly.GetName().Name) }); }
//该方法为测试方法 public void Search2(string name) { bool eb = eSSever.ElasticLinqClient.IndexExists("mypost").Exists; if (eb) { var result2 = eSSever.ElasticLinqClient.Search <Post>(x => x.Index("mypost").Type(TypeName.Create <Post>()).Query(op => op.Term( ss => ss.Field(qq => qq.Title).Value("*ajax*")))); var result = eSSever.ElasticLinqClient.Search <Post>(x => x.Index("mypost").Type(TypeName.Create <Post>()) .Query(q => q.Match(m => m.Field( f => f.Title) .Query("英") ) ).From(0).Size(10)); var res = result.Documents.ToList(); var a = 1; } }
public void ThrowIfArrayType() { TypeName theName = TypeName.Create("System.Int32", "mscorelib", new TypeName[0], 1); Assert.Throws <ArgumentException>(() => SimpleClassDescription.Create(theName, f => new SimpleFieldDescription[0])); }
internal static SimpleClassDescription CreateGenericType() { TypeName genericArg = TypeName.Create("System.Int32", "mscorelib"); return(CreateGenericType(genericArg)); }
internal static SimpleClassDescription CreateGenericType(params TypeName[] genericArg) { TypeName theName = TypeName.Create("ANamespace.TheType`" + genericArg.Count(), "TheAssembly", genericArg); return(SimpleClassDescription.Create(theName, f => new SimpleFieldDescription[0])); }
private static SimpleClassDescription CreateEmptySimpleClass(string nameSpaceAndName, string assemblyName = AssemblyName) { return(SimpleClassDescription.Create(TypeName.Create(nameSpaceAndName, assemblyName), (f) => new SimpleFieldDescription[0])); }
internal static TypeName SingleFieldType() { return(TypeName.Create(SingleFieldTypeName, AssemblyName)); }
public List <Post> Search(string query) { bool eb = this.ElasticLinqClient.IndexExists("mypost").Exists; List <Post> result = new List <Post>(); if (eb) { var reSer = this.ElasticLinqClient.Search <Post>(x => x.Index("mypost").Type(TypeName.Create <Post>()) .Query(q => q.Match(m => m.Field( f => f.Title) .Query(query) ) ).From(0).Size(9)); result = reSer.Documents.ToList(); } return(result); }