Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        public void DelegatesToNativeLoader()
        {
            var typeName = TypeName.Create("System.String", "mscorlib");
            var type     = TypeLoader.Create(new string[0])(typeName);

            Assert.AreEqual(typeof(string), type.Value);
        }
Exemplo n.º 4
0
        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));
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 7
0
        public void NestedClassName()
        {
            var complex = TypeName.Create("Type.Parent+Child", "Assembly.Name");

            Assert.AreEqual("Type.Parent_Child",
                            complex.NameWithGenerics);
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
0
        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);
        }
Exemplo n.º 11
0
        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);
        }
Exemplo n.º 12
0
        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);
        }
Exemplo n.º 13
0
        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);
        }
Exemplo n.º 14
0
        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));
        }
Exemplo n.º 15
0
        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 });
        }
Exemplo n.º 16
0
        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 }));
        }
Exemplo n.º 17
0
        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 });
        }
Exemplo n.º 18
0
        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())));
            }
        }
Exemplo n.º 19
0
        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);
        }
Exemplo n.º 20
0
 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)));
 }
Exemplo n.º 21
0
        public void DontCrashOnNonExistingFile()
        {
            var found = TypeLoader.Create(new[] { Path.GetRandomFileName() })(TypeName.Create("DoesNotExist.ClassName", "DoesNotExist"));

            Assert.IsFalse(found.HasValue);
        }
Exemplo n.º 22
0
        public void DontCrashOnBogusAssemblies()
        {
            var found = TypeLoader.Create(new[] { Path.GetTempFileName() })(TypeName.Create("DoesNotExist.ClassName", "DoesNotExist"));

            Assert.IsFalse(found.HasValue);
        }
Exemplo n.º 23
0
 internal static IEnumerable <TypeName> GenericArg(Type intType)
 {
     return(new[] { TypeName.Create(intType.FullName, intType.Assembly.GetName().Name) });
 }
Exemplo n.º 24
0
        //该方法为测试方法
        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;
            }
        }
Exemplo n.º 25
0
        public void ThrowIfArrayType()
        {
            TypeName theName = TypeName.Create("System.Int32", "mscorelib", new TypeName[0], 1);

            Assert.Throws <ArgumentException>(() => SimpleClassDescription.Create(theName, f => new SimpleFieldDescription[0]));
        }
Exemplo n.º 26
0
        internal static SimpleClassDescription CreateGenericType()
        {
            TypeName genericArg = TypeName.Create("System.Int32", "mscorelib");

            return(CreateGenericType(genericArg));
        }
Exemplo n.º 27
0
        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]));
        }
Exemplo n.º 28
0
 private static SimpleClassDescription CreateEmptySimpleClass(string nameSpaceAndName, string assemblyName = AssemblyName)
 {
     return(SimpleClassDescription.Create(TypeName.Create(nameSpaceAndName, assemblyName),
                                          (f) => new SimpleFieldDescription[0]));
 }
Exemplo n.º 29
0
 internal static TypeName SingleFieldType()
 {
     return(TypeName.Create(SingleFieldTypeName, AssemblyName));
 }
Exemplo n.º 30
0
        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);
        }