Ejemplo n.º 1
0
        private static TypeDescription GetTypeDescription(Type sourceClass)
        {
            var propertySource  = new ClassSource(sourceClass);
            var typeDesctiption = new TypeDescription(sourceClass.FullName, propertySource.GetProperties());

            return(typeDesctiption);
        }
Ejemplo n.º 2
0
        private string GetOrCreateDexFilename(ClassSource source, string hash)
        {
            string jarFileName = GetJarFileName(source, hash);

            if (!source.IsDiskFile && !File.Exists(jarFileName))
            {
                Directory.CreateDirectory(_temporaryDirectory);
                File.WriteAllBytes(jarFileName, source.JarData);
            }

            string baseName = Path.GetFileNameWithoutExtension(jarFileName);

            if (!baseName.Contains(hash))
            {
                baseName += "." + hash;
            }
            var dexFileName = Path.Combine(_temporaryDirectory, baseName + ".dex");

            if (!File.Exists(dexFileName))
            {
                Directory.CreateDirectory(_temporaryDirectory);
                DxInvoker.CompileToDex(jarFileName, dexFileName, _generateDebugSymbols);
            }

            return(dexFileName);
        }
Ejemplo n.º 3
0
        public void GetProperties_should_return_property_with_only_set_method()
        {
            ClassSource classSource = new ClassSource(typeof(IOnlySet));

            var result = classSource.GetProperties();

            Assert.AreEqual(1, result.Count());
            result.ShouldContainsKeyAndValue("Text", typeof(string));
        }
Ejemplo n.º 4
0
        public void GetProperties_should_return_all_properties_from_simple_class()
        {
            ClassSource classSource = new ClassSource(typeof(SimpleClass));

            var result = classSource.GetProperties();

            Assert.AreEqual(2, result.Count());
            result.ShouldContainsKeyAndValue("Number", typeof(int));
            result.ShouldContainsKeyAndValue("Text", typeof(string));
        }
Ejemplo n.º 5
0
        private string GetJarFileName(ClassSource source, string hash)
        {
            if (source.IsDiskFile)
            {
                return(source.FileName);
            }

            string baseName = Path.GetFileName(source.FileName);

            return(Path.Combine(_temporaryDirectory, baseName + "-" + hash + ".jar"));
        }
Ejemplo n.º 6
0
        private string GetHash(ClassSource source)
        {
            if (source.JarStreamHash != null)
            {
                return(source.JarStreamHash);
            }

            if (source.JarData != null)
            {
                return(JarReferenceHash.ComputeJarReferenceHash(source.JarData));
            }

            return(JarReferenceHash.ComputeJarReferenceHash(source.FileName));
        }
Ejemplo n.º 7
0
        public void Map_Success()
        {
            ClassDest   actual   = null;
            ClassSource expected = Builder <ClassSource> .CreateNew().Build();

            Init(null);
            Mapper.Initialize();
            actual = Mapper <ClassDest> .Map(expected);

            Assert.IsNotNull(actual);
            Assert.AreEqual(actual.PropInt1, expected.PropInt1);
            Assert.AreEqual(actual.PropString2, expected.PropString1);
            Clean();
        }
Ejemplo n.º 8
0
        public void Map_ReturnDestinationObject_Success()
        {
            Mapper.Initialize();

            ClassDest   actual   = null;
            ClassSource expected = new ClassSource()
            {
                PropInt1 = 1, PropSourceInt1 = 1, PropString1 = "test"
            };

            actual = Mapper.Map <ClassSource, ClassDest>(expected);

            Assert.AreEqual(actual.PropInt1, expected.PropInt1);
            Assert.AreEqual(actual.PropString2, expected.PropString1);
            Assert.AreEqual(actual.PropInt2, 0);
        }
Ejemplo n.º 9
0
        public void Map_ReturnDestinationObject_Success()
        {
            ExpressionMapper.Initialize();

            ClassSource expected = new ClassSource()
            {
                PropInt1       = 1,
                PropSourceInt1 = 1,
                PropString1    = "test"
            };

            var actual = expected.Map <ClassSource, ClassDest>();

            Assert.Equal(actual.PropInt1, expected.PropInt1);
            Assert.Equal(actual.PropString2, expected.PropString1);
            Assert.Equal(0, actual.PropInt2);
        }
Ejemplo n.º 10
0
        static void Main(string[] args)
        {
            List <Register> students = ClassSource.GetStudents();

            // Bu örnek, 1.yazılı sınav notu 55 ve daha büyük olan öğrencileri
            //1.sınav notlarına göre artan sırada(küçükten büyüğe) seçer.
            var query = from student in students
                        where student.Notes[0] >= 55
                        orderby student.Notes[0]
                        select student;

            foreach (var student in query)
            {
                Console.WriteLine(student.Name);
            }

            Console.ReadKey();

            /*
             * // LINQ Yöntem Sözdizimi ile sorgu :
             * var query = students.Where(std => std.Notes[0] >= 55)
             *                    .OrderBy(std => std.Notes[0]);
             */
            Console.WriteLine("---------------");

            //Eğer tersine bir sıralama isteniyorsa descending ifadesi
            //cümleciğin sonuna eklenir.
            var query2 = from student in students
                         where student.Notes[0] >= 55
                         orderby student.Notes[0] descending
                         select student;

            foreach (var student in query2)
            {
                Console.WriteLine(student.Name);
            }

            Console.ReadKey();

            /*
             * // LINQ Yöntem Sözdizimi ile sorgu :
             * var query = students.Where(std => std.Notes[0] >= 55)
             *                    .OrderByDescending(std => std.Notes[0]);
             */
        }
Ejemplo n.º 11
0
        public ITurnamentorBuilder <Contestant, Score, ScoreBoard> SetGameEngine(ClassSource source, string directoryWithFile)
        {
            ITypeLoader loader = GetTypeLoader(source);
            var         types  = loader.LoadTypes <IGameEngine <Contestant, Score> >(new string[] { directoryWithFile });

            if (types.Count == 0)
            {
                throw new NoInstanceOfGameEngineFoundException();
            }

            if (types.Count > 1)
            {
                throw new AmbiguousGameEngine();
            }

            turnamentor.EngineProvider = () => Activator.CreateInstance(types[0]);
            return(this);
        }
Ejemplo n.º 12
0
        public void Map_Return_null()
        {
            ClassDest   actual   = null;
            ClassSource expected = new ClassSource()
            {
                PropInt1 = 1, PropSourceInt1 = 1, PropString1 = "test"
            };

            using (ShimsContext.Create())
            {
                MapperExpression.Core.Fakes.ShimMapperConfiguration <ClassSource, ClassDest> .AllInstances.GetFuncDelegate = (s) => { return(null); };

                actual = Mapper.Map <ClassSource, ClassDest>(expected);
            }


            Assert.IsNull(actual);
        }
Ejemplo n.º 13
0
        public ITurnamentorBuilder <Contestant, Score, ScoreBoard> AddContestants(ClassSource source, params string[] directories)
        {
            ITypeLoader loader = GetTypeLoader(source);

            if (directories.Length == 0)
            {
                directories = new string[] { "" }
            }
            ;                                      //add at least work directory

            var loadedTypes = loader.LoadTypes <Contestant>(directories);

            roundSelectorConfig.Contestants.AddRange(
                loadedTypes.Where(type => !roundSelectorConfig.Contestants.Contains(type))
                );

            return(this);
        }
Ejemplo n.º 14
0
        public void Map_MapperNotInitialise_Exception()
        {
            Mapper.CreateMap <ClassSource, ClassDest>()
            .ForMember(s => s.PropString1, d => d.PropString2);
            ClassDest   actual   = null;
            ClassSource expected = new ClassSource()
            {
                PropInt1 = 1, PropSourceInt1 = 1, PropString1 = "test"
            };

            using (ShimsContext.Create())
            {
                MapperExpression.Core.Fakes.ShimMapperConfiguration <ClassSource, ClassDest> .AllInstances.GetFuncDelegate = (s) =>
                {
                    throw new MapperNotInitializedException(typeof(ClassSource), typeof(ClassDest));
                };

                actual = Mapper.Map <ClassSource, ClassDest>(expected);
            }
        }
Ejemplo n.º 15
0
        static void Main(string[] args)
        {
            List <Register> students = ClassSource.GetStudents();

            //(1. yazılı sınav notu 55 ve daha büyük olan öğrencilerin soyadlarını seç.)
            var query = from student in students
                        where student.Notes[0] >= 55
                        select student.Surname;

            foreach (var s in query)
            {
                Console.WriteLine(s);
            }
            Console.ReadKey();

            /*  //LINQ Yöntem Sözdizimi ile sorgu :
             * var query = students.Where(std => std.Notes[0] >= 55)
             *                     .Select(ogr => ogr.Surname);
             */

            Console.WriteLine("---------------");

            var query2 = from student in students
                         where student.Notes[0] >= 55 && student.Success == false
                         select student;

            foreach (var s in query2)
            {
                Console.WriteLine(s.Surname);
            }
            Console.ReadKey();

            /*
             * // LINQ Yöntem Sözdizimi ile sorgu :
             * var query = students.Where(std => std.Notes[0] >= 55 && ogr.Success == false);
             */
        }
Ejemplo n.º 16
0
        private DexLookup GetOrCreateDex(ClassSource source, bool waitForResult)
        {
            string hash = GetHash(source);

            var jarFileName = GetJarFileName(source, hash);

            Task <DexLookup> dex;

            lock (_dexes)
            {
                if (_dexes.TryGetValue(jarFileName, out dex))
                {
                    if (!waitForResult)
                    {
                        return(null);
                    }
                    return(dex.Result);
                }

                dex = new Task <DexLookup>(() =>
                {
                    var dexFileName = GetOrCreateDexFilename(source, hash);
                    return(new DexLookup(DexLib.Dex.Read(dexFileName)));
                }, TaskCreationOptions.LongRunning);

                _dexes[jarFileName] = dex;
            }

            dex.Start();

            if (waitForResult)
            {
                return(dex.Result);
            }
            return(null);
        }
Ejemplo n.º 17
0
 private ITypeLoader GetTypeLoader(ClassSource source)
 => source switch
 {
Ejemplo n.º 18
0
 public void PreloadJar(ClassSource source)
 {
     GetOrCreateDex(source, waitForResult: false);
 }
Ejemplo n.º 19
0
 public void Ctor_should_throw_exception_when_value_is_null()
 {
     ClassSource classSource = new ClassSource(null);
 }