Esempio n. 1
0
        private void ParseWithReflection(MyCircularQueue circularQueue, string[] methods, string paramethersJson, string resultsJson)
        {
            var paramethers = JsonConvert.DeserializeObject <List <int[]> >(paramethersJson);
            var results     = JsonConvert.DeserializeObject <List <object> >(resultsJson);

            circularQueue = new MyCircularQueue(paramethers[0][0]);
            var thisType = circularQueue.GetType();
            int index    = 0;

            foreach (var method in methods)
            {
                if (index == 0)
                {
                    index++;
                    continue;
                }

                char[] arr = method.ToCharArray();
                arr[0] = char.ToUpper(arr[0]);
                var theMethod = thisType.GetMethod(new string(arr));
                var obj       = new object?[0] {
                };
                if (paramethers[index].Length == 1)
                {
                    object firstParam = paramethers[index][0];
                    obj = new object?[1] {
                        firstParam
                    };
                }

                var result = theMethod.Invoke(circularQueue, obj);
                if (results[index] != null)
                {
                    if (results[index].GetType() == typeof(int))
                    {
                        int res = (int)results[index];
                        Assert.AreEqual(res, (int)result);
                        if (res != (int)result)
                        {
                            throw new NullReferenceException("Failed");
                        }
                    }

                    if (results[index].GetType() == typeof(long))
                    {
                        long res = (long)results[index];
                        Assert.AreEqual(res, (int)result);
                        if (res != (int)result)
                        {
                            throw new NullReferenceException("Failed");
                        }
                    }

                    if (results[index].GetType() == typeof(bool))
                    {
                        bool res = (bool)results[index];
                        Assert.AreEqual(res, (bool)result);
                        if (res != (bool)result)
                        {
                            throw new NullReferenceException("Failed");
                        }
                    }
                }

                index++;
            }
        }