Пример #1
0
        public void RefAndOutParameter()
        {
            int x = 5;
            int y;

            ClassWithStaticMethods.RefAndOutParameter(ref x, out y);
            QUnit.AreEqual(x, 6);
            QUnit.AreEqual(y, 10);
        }
Пример #2
0
        public void CanSeeChangesToClosedVariable()
        {
            var    i      = 0;
            Action action = () => i = i + 1;

            i = 1;
            action();
            QUnit.AreEqual(i, 2);
        }
Пример #3
0
        public void ArrayCopy()
        {
            var array    = new[] { "1", "2", "3" };
            var newArray = new string[2];

            array.CopyTo(newArray, 1);
            QUnit.AreEqual(newArray[0], "2");
            QUnit.AreEqual(newArray[1], "3");
        }
Пример #4
0
        public void TwoOutParameters()
        {
            string x;
            string y;

            ClassWithStaticMethods.TwoOutParameters(out x, out y);
            QUnit.AreEqual(x, "foo1");
            QUnit.AreEqual(y, "foo2");
        }
Пример #5
0
        public void MethodDelegate()
        {
            var           methodClass    = new MethodClass("foo");
            Func <string> methodDelegate = methodClass.M;
            var           s = methodDelegate();

            QUnit.AreEqual(s, "foo");
            QUnit.AreEqual(methodDelegate.Target, methodClass);
        }
Пример #6
0
        public void TwoRefParameters()
        {
            int x = 5;
            int y = 6;

            ClassWithStaticMethods.TwoRefParameters(ref x, ref y);
            QUnit.AreEqual(x, 6);
            QUnit.AreEqual(y, 12);
        }
Пример #7
0
        public void TryFinally()
        {
            var ints = YieldClass.TryFinally().ToArray();

            QUnit.AreEqual(ints.Length, 3);
            QUnit.AreEqual(ints[0], 1);
            QUnit.AreEqual(ints[1], 2);
            QUnit.AreEqual(ints[2], 3);
        }
Пример #8
0
        public void LastIndexOf()
        {
            var s = "12341234";

            QUnit.AreEqual(s.LastIndexOf("2"), 5);
            QUnit.AreEqual(s.LastIndexOf("2", 4), 1);
            QUnit.AreEqual(s.LastIndexOf('2'), 5);
            QUnit.AreEqual(s.LastIndexOf('2', 4), 1);
        }
Пример #9
0
        public void LabeledStatementGotoSecond()
        {
            var ints = YieldClass.LabeledStatementGotoSecond().ToArray();

            QUnit.AreEqual(ints.Length, 3);
            QUnit.AreEqual(ints[0], 1);
            QUnit.AreEqual(ints[1], 2);
            QUnit.AreEqual(ints[2], 3);
        }
Пример #10
0
        public void Foreach()
        {
            var strings = YieldClass.Foreach().ToArray();

            QUnit.AreEqual(strings.Length, 3);
            QUnit.AreEqual(strings[0], "one");
            QUnit.AreEqual(strings[1], "two");
            QUnit.AreEqual(strings[2], "three");
        }
Пример #11
0
        public void SwitchThree()
        {
            var ints = YieldClass.Switch("three").ToArray();

            QUnit.AreEqual(ints.Length, 3);
            QUnit.AreEqual(ints[0], 1);
            QUnit.AreEqual(ints[1], 2);
            QUnit.AreEqual(ints[2], 3);
        }
Пример #12
0
        public void ForLoopTwoVariablesTwoIncrementors()
        {
            var ints = YieldClass.ForLoopTwoVariablesTwoIncrementors().ToArray();

            QUnit.AreEqual(ints.Length, 3);
            QUnit.AreEqual(ints[0], 1);
            QUnit.AreEqual(ints[1], 3);
            QUnit.AreEqual(ints[2], 5);
        }
Пример #13
0
        public void ForLoopNoVariableNoInitializerNoIncrementor()
        {
            var ints = YieldClass.ForLoopNoVariableNoInitializerNoIncrementor().ToArray();

            QUnit.AreEqual(ints.Length, 3);
            QUnit.AreEqual(ints[0], 0);
            QUnit.AreEqual(ints[1], 1);
            QUnit.AreEqual(ints[2], 2);
        }
Пример #14
0
        public void ForLoop()
        {
            var ints = YieldClass.ForLoop().ToArray();

            QUnit.AreEqual(ints.Length, 3);
            QUnit.AreEqual(ints[0], 0);
            QUnit.AreEqual(ints[1], 1);
            QUnit.AreEqual(ints[2], 2);
        }
Пример #15
0
        public void GetFields()
        {
            var fields = typeof(FieldsClass).GetFields();

            QUnit.AreEqual(fields.Length, 1);
            var field = fields[0];

            QUnit.AreEqual(field.Name, "MyString");
        }
Пример #16
0
        public void Nested()
        {
            var o = new OnePropertyClass {
                NestedProperty = new OnePropertyClass {
                    MyProperty = "foo"
                }
            };

            QUnit.AreEqual(o.NestedProperty.MyProperty, "foo");
        }
Пример #17
0
        public void CollidingFor()
        {
            var ints = YieldClass.CollidingForeach().ToArray();

            QUnit.AreEqual(ints.Length, 4);
            QUnit.AreEqual(ints[0], 1);
            QUnit.AreEqual(ints[1], 2);
            QUnit.AreEqual(ints[2], 3);
            QUnit.AreEqual(ints[3], 4);
        }
Пример #18
0
        public void TopLevelGenericClasses()
        {
            var stringClass = new TopLevelGenericClass <string>();
            var intClass    = new TopLevelGenericClass <int>();
            var simpleClass = new TopLevelGenericClass <SimpleClass>();

            QUnit.AreEqual(stringClass.GetName(), "String");
            QUnit.AreEqual(intClass.GetName(), "Int32");
            QUnit.AreEqual(simpleClass.GetName(), "SimpleClass");
        }
Пример #19
0
        public void ConstructorsWithOverloads()
        {
            var test1 = new TestClass();
            var test2 = new TestClass("foo");
            var test3 = new TestClass(5);

            QUnit.AreEqual(test1.Arg1, "none");
            QUnit.AreEqual(test2.Arg1, "string");
            QUnit.AreEqual(test3.Arg1, "int");
        }
Пример #20
0
        public void IndexOf()
        {
            var    s   = "12341234";
            String two = "2";

            QUnit.AreEqual(s.IndexOf(two), 1);
            QUnit.AreEqual(s.IndexOf("2", 4), 5);
            QUnit.AreEqual(s.IndexOf('2'), 1);
            QUnit.AreEqual(s.IndexOf('2', 4), 5);
        }
Пример #21
0
        public void SplitCharArrayWithCount()
        {
            var s     = "12a34b56c78";
            var parts = s.Split(new[] { 'a', 'b', 'c' }, 3);

            QUnit.AreEqual(parts.Length, 3);
            QUnit.AreEqual(parts[0], "12");
            QUnit.AreEqual(parts[1], "34");
            QUnit.AreEqual(parts[2], "56");
        }
Пример #22
0
        public void Foreach()
        {
            var s     = "1234";
            var chars = s.ToArray();

            QUnit.AreEqual(chars[0], '1');
            QUnit.AreEqual(chars[1], '2');
            QUnit.AreEqual(chars[2], '3');
            QUnit.AreEqual(chars[3], '4');
        }
Пример #23
0
        public void Override()
        {
            var       baseClass           = new BaseClass();
            var       subClass            = new SubClass();
            BaseClass subClassAsBaseClass = subClass;

            QUnit.AreEqual(baseClass.Foo(), "base");
            QUnit.AreEqual(subClass.Foo(), "sub");
            QUnit.AreEqual(subClassAsBaseClass.Foo(), "sub");
        }
Пример #24
0
        public void SimpleLambda()
        {
            var myClass = new MyClass {
                Name = "foo"
            };
            var lambda = myClass.CreateLambda();
            var name   = lambda();

            QUnit.AreEqual(name, "foo");
        }
Пример #25
0
        public void ReturnAfterIfTrue()
        {
            var strings = YieldClass.ReturnAfterIf(true).ToArray();

            QUnit.AreEqual(strings.Length, 5);
            QUnit.AreEqual(strings[0], "zero");
            QUnit.AreEqual(strings[1], "one");
            QUnit.AreEqual(strings[2], "two");
            QUnit.AreEqual(strings[3], "five");
            QUnit.AreEqual(strings[4], "six");
        }
Пример #26
0
        public void SplitCharArray()
        {
            var s     = "12a34b56c78";
            var parts = s.Split('a', 'b', 'c');

            QUnit.AreEqual(parts.Length, 4);
            QUnit.AreEqual(parts[0], "12");
            QUnit.AreEqual(parts[1], "34");
            QUnit.AreEqual(parts[2], "56");
            QUnit.AreEqual(parts[3], "78");
        }
Пример #27
0
        public void CollisionImplementationOneExplicit()
        {
            var             o     = new CollisionImplementationOneExplicit();
            ITestInterface  test  = o;
            ITestInterface2 test2 = o;
            var             s     = test.Method();
            var             s2    = test2.Method();

            QUnit.AreEqual(s, "ITestInterface");
            QUnit.AreEqual(s2, "ITestInterface2");
        }
Пример #28
0
        public void ReturnAfterIfFalse()
        {
            var strings = YieldClass.ReturnAfterIf(false).ToArray();

            QUnit.AreEqual(strings.Length, 5);
            QUnit.AreEqual(strings[0], "zero");
            QUnit.AreEqual(strings[1], "three");
            QUnit.AreEqual(strings[2], "four");
            QUnit.AreEqual(strings[3], "five");
            QUnit.AreEqual(strings[4], "six");
        }
Пример #29
0
        public void CreateDate()
        {
            var date = new DateTime(2014, 1, 2, 15, 3, 5, 30);

            QUnit.AreEqual(date.Year, 2014);
            QUnit.AreEqual(date.Month, 1);
            QUnit.AreEqual(date.Day, 2);
            QUnit.AreEqual(date.Hour, 15);
            QUnit.AreEqual(date.Minute, 3);
            QUnit.AreEqual(date.Second, 5);
            QUnit.AreEqual(date.Millisecond, 30);
        }
Пример #30
0
        public void MethodTargets()
        {
            var           methodClass1 = new MethodClass("foo1");
            var           methodClass2 = new MethodClass("foo2");
            Func <string> delegate1    = methodClass1.M;
            Func <string> delegate2    = methodClass2.M;

            QUnit.AreEqual(delegate1(), "foo1");
            QUnit.AreEqual(delegate2(), "foo2");
            QUnit.AreEqual(delegate1.Target, methodClass1);
            QUnit.AreEqual(delegate2.Target, methodClass2);
        }