Example #1
0
        public void Invoke_WithInvalidGenericMethodCall_ThrowsArgumentException()
        {
            EngineConfigurationTypeBuilder <SimpleMethodClass> configuration = new EngineConfigurationTypeBuilder <SimpleMethodClass>();

            Assert.Throws <ArgumentException>(() =>
            {
                configuration.Invoke(x => x.SetSomething(TestGenericClass.Something <string>()));
            });
        }
Example #2
0
        public void Test_GenericClass()
        {
            TestGenericClass <int> intGeneric = new TestGenericClass <int>(3);

            for (int i = 0; i < 3; i++)
            {
                intGeneric.setItem(i, i);
                Assert.AreEqual(intGeneric.getItem(i), i);
            }
        }
Example #3
0
        public void RunProtobufLearningTestGenericsSerialization()
        {
            var ms   = new MemoryStream();
            var data = new TestGenericClass <string>();

            Serializer.Serialize <ITestGenericClass <string> >(ms, data);
            ms.Position = 0;
            var nextData = Serializer.Deserialize <ITestGenericClass <string> >(ms); // doesn't work with vague object

            Console.WriteLine(nextData.GetType());
            Console.WriteLine(nextData);
        }
Example #4
0
    public void TestFancyGenericPass()
    {
        var engine         = new Engine();
        var testGenericObj = new TestGenericClass();

        engine.SetValue("testGenericObj", testGenericObj);

        engine.Execute(@"
                testGenericObj.Fancy('test', 42, 'foo');
            ");

        Assert.Equal(true, testGenericObj.FancyInvoked);
    }
Example #5
0
    public void TestGeneric2()
    {
        var engine         = new Engine();
        var testGenericObj = new TestGenericClass();

        engine.SetValue("testGenericObj", testGenericObj);

        engine.Execute(@"
                testGenericObj.Bar('testing testing 1 2 3');
                testGenericObj.Foo('hello world');
                testGenericObj.Add('blah');
            ");

        Assert.Equal(1, testGenericObj.Count);
    }
Example #6
0
    public void TestFancyGenericFail()
    {
        var engine         = new Engine();
        var testGenericObj = new TestGenericClass();

        engine.SetValue("testGenericObj", testGenericObj);

        var argException = Assert.Throws <Jint.Runtime.JavaScriptException>(() =>
        {
            engine.Execute(@"
                    testGenericObj.Fancy('test', 'foo', 42);
                ");
        });

        Assert.Equal("No public methods with the specified arguments were found.", argException.Message);
    }
Example #7
0
        public void Test_GenericTypeWithGenericMethodWithGenericArguments()
        {
            var list = new List <bool> {
                true, false, false
            };
            var generic = new TestGenericClass <int>();
            var value   = generic.GenericMethod(list);
            var output  = GetOutput();


            var ilgeneric = WeaverHelper.CreateInstance <Yalf.TestAssembly.TestGenericClass <int> >(assembly);
            var ilvalue   = ilgeneric.GenericMethod(list);
            var iloutput  = GetOutput();

            Console.WriteLine(iloutput);

            Assert.That(iloutput, Is.EqualTo(output));
            Assert.That(ilvalue, Is.EqualTo(value));
            Assert.IsTrue(iloutput.Contains("(List<Boolean>)"), "expected (List<Boolean>) in output");
        }
Example #8
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Start");
            NestedFilters("NestedFilters");
            NestedFilters("NestedFilters3");

            CatchAndSilence();
            RunWithExceptionFilter();
            MultipleTypedCatches();
            ThrowInsideBrokenFilter();

            var c = new C();

            c.NestedFiltersInOneFunction("value");
            c.LopsidedWithFinally();
            c.TestReturnValueWithFinallyAndDefault();
            int   x = 5;
            float y = 7;

            c.TestRefParam(ref x, ref y);
            Console.WriteLine($"x = {x}, y = {y}");

            var tempv = new TestGenericClass <int>();
            var ret   = tempv.GenericInstanceMethodWithFilterAndIndirectReference(default(int), "test");

            Console.WriteLine("ret=" + ret);

            Console.WriteLine("test_0_filter_caller_area={0}", MiniTests.test_0_filter_caller_area());
            Console.WriteLine("test_1234_complicated_filter_catch={0}", MiniTests.test_1234_complicated_filter_catch());
            Console.WriteLine("test_1_basic_filter_catch={0}", MiniTests.test_1_basic_filter_catch());

            Console.WriteLine("Done executing");
            if (Debugger.IsAttached)
            {
                Console.ReadLine();
            }
        }
Example #9
0
        static void Main()
        {
            #region Создание коллекции и вывод ее на экран циклом Foreach с указанием моего пользовательского типа
            Console.WriteLine("Добавляю в мою коллекцию элементы");
            var collection = new MyCollection <IMyClass>
            {
                new SumTwoNumber(23, 56),
                new SumTwoNumber(55, 90),
                new SumTwoNumber(155, 190),
                new PositiveDiffirentTwoNumber(45, 190),
                new PositiveDiffirentTwoNumber(555, 678)
            };

            // При указании типа в Foreach в итераторе обращаюсь к методу T Current и возвращ. свой тип данных
            foreach (IMyClass item in collection)
            {
                Console.WriteLine($"В коллекции элемент со значениями: {item.Field1} и {item.Field2}.  {item}");
            }
            #endregion

            DeleteItemFromCollection(null);

            #region Добавление в ранее созданную коллекцию 1 дополнительного элемента и вывод ее на экран циклом Foreach с применением распаковки
            var testElement = new PositiveDiffirentTwoNumber(-200, 80);
            Console.WriteLine();
            Console.WriteLine($"Добавляю еще один элемент в коллекцию со значениями: {testElement.Field1} и {testElement.Field2}");
            collection.Add(testElement);

            // При указании var в Foreach в итераторе обращаюсь к методу Object Current и здесь делаю Unboxing.
            foreach (var item in collection)
            {
                Console.WriteLine($"В коллекции элементы со значениями: { ((IMyClass)item).Field1 } и {((IMyClass)item).Field2}. {(IMyClass)item}");
            }
            #endregion

            #region Удаление элемента и вывод на экран с помощью переопределенного метода ToString
            Console.WriteLine();
            Console.WriteLine("Удаляю только что добавленный элемент из коллекции");
            DeleteItemFromCollection(testElement);

            Console.WriteLine();
            // При указании var в Foreach в итераторе обращаюсь к методу Object Current и здесь надо Unboxing делать. В данном примере я переопределил ToString
            foreach (var item in collection)
            {
                Console.WriteLine($"{item}");
            }
            #endregion

            #region Задание 2. Работа с Generic

            Console.WriteLine();
            Console.WriteLine("Пример работы с Generic");
            var testGeneric = new TestGenericClass <int, IMyClass>(testElement)
            {
                FieldT = 5555
            };
            Console.WriteLine($"Generic: {testGeneric} ");
            Console.WriteLine($"MyClass: {testGeneric.GetMyClass()}");
            #endregion

            Console.ReadKey();

            void DeleteItemFromCollection(IMyClass elem)
            {
                //Попытка удаления элемента из коллекции
                try
                {
                    Console.WriteLine();
                    Console.WriteLine($"Сейчас в коллекции {collection.Count()} элементов. Пробую удалить");
                    collection.Delete(elem);
                }
                catch (Exception e)
                {
                    Console.WriteLine($"Ошибка: {e.GetBaseException().Message}");
                }
            }
        }
Example #10
0
        public void Test_GenericTypeWithGenericMethodWithGenericArguments()
        {
            var list = new List<bool> {true, false, false};
            var generic = new TestGenericClass<int>();
            var value = generic.GenericMethod(list);
            var output = GetOutput();

            var ilgeneric = WeaverHelper.CreateInstance<Yalf.TestAssembly.TestGenericClass<int>>(assembly);
            var ilvalue = ilgeneric.GenericMethod(list);
            var iloutput = GetOutput();

            Console.WriteLine(iloutput);

            Assert.That(iloutput, Is.EqualTo(output));
            Assert.That(ilvalue, Is.EqualTo(value));
            Assert.IsTrue(iloutput.Contains("(List<Boolean>)"), "expected (List<Boolean>) in output");
        }