Inheritance: INotifyPropertyChanged
        public void E_ClassesCanHaveIndexers()
        {
            // An indexer allows a class to act as an array.
            ClassWithIndexer obj = new ClassWithIndexer();

            obj[0] = 5;
            obj[1] = 7;
            Assert.AreEqual(FILL_ME_IN, obj[0]);
            Assert.AreEqual(FILL_ME_IN, obj[1]);
        }
        public void E_ClassesCanHaveIndexers()
        {
            // An indexer allows a class to act as an array.
            ClassWithIndexer obj = new ClassWithIndexer();

            obj[0] = 5;
            obj[1] = 7;
            Assert.Equal(FILL_ME_IN, obj[0]);
            Assert.Equal(FILL_ME_IN, obj[1]);
        }
        public static void TestIndexerInClass()
        {
            var c1 = new ClassWithIndexer();

            Assert("GetAtIndexTest1", c1["Test1"]);

            c1["Test2"] = "TheValue";

            Assert("SetAtIndexTest2IsTheValue", c1.Set);
        }
        public void SetValueByIndexerInManagedObject()
        {
            var classWithIndexer = new ClassWithIndexer();
            _context.SetParameter("myObject", classWithIndexer);

            _context.Run("myObject[20] = 'The value is now set'");

            Assert.That(classWithIndexer.Value, Is.EqualTo("The value is now set"));
            Assert.That(classWithIndexer.Index, Is.EqualTo(20));
        }
Beispiel #5
0
        public void ClassesCanHaveIndexers()
        {
            // An indexer allows a class to act as an array.
            ClassWithIndexer obj = new ClassWithIndexer();

            obj[0] = 5;
            obj[1] = 7;
            Assert.Equal(5, obj[0]);
            Assert.Equal(7, obj[1]);
        }
        public void GetHashCode_should_return_value_for_class_with_indexer()
        {
            var first = new ClassWithIndexer();

            first.X = 1;
            first.Y = 2;

            var result = first.GetHashCode();

            Assert.NotEqual(0, result);
        }
        public void SetValueByIndexerInManagedObject()
        {
            var classWithIndexer = new ClassWithIndexer();

            _context.SetParameter("myObject", classWithIndexer);

            _context.Run("myObject[20] = 'The value is now set'");

            classWithIndexer.Value.Should().Be("The value is now set");
            classWithIndexer.Index.Should().Be(20);
        }
        public void SetValueByIndexerInManagedObject()
        {
            var classWithIndexer = new ClassWithIndexer();

            _context.SetParameter("myObject", classWithIndexer);

            _context.Run("myObject[20] = 'The value is now set'");

            Assert.That(classWithIndexer.Value, Is.EqualTo("The value is now set"));
            Assert.That(classWithIndexer.Index, Is.EqualTo(20));
        }
Beispiel #9
0
        public void WhenSerializingItIgnoresIndexer()
        {
            // Arrange
            object o = new ClassWithIndexer {
                A = "XYZ"
            };

            // Act
            string result = Serialize(o);

            // Assert
            Assert.AreEqual("|A=XYZ", result);
        }
Beispiel #10
0
        public void GenericProxyWithIndexer()
        {
            object proxy = generator.CreateClassProxy <ClassWithIndexer <string, int> >(logger);

            Assert.IsNotNull(proxy);

            ClassWithIndexer <string, int> type = (ClassWithIndexer <string, int>)proxy;

            type["name"] = 10;
            Assert.AreEqual(10, type["name"]);

            Assert.AreEqual("set_Item get_Item ", logger.LogContents);
        }
Beispiel #11
0
        public void When_a_property_is_an_indexer_it_should_be_ignored()
        {
            // Arrange
            var expected = new ClassWithIndexer {
                Foo = "test"
            };
            var result = new ClassWithIndexer {
                Foo = "test"
            };

            // Act
            Action act = () => result.Should().BeEquivalentTo(expected);

            // Assert
            act.Should().NotThrow();
        }
        public void Equals_should_return_true_for_class_with_indexer()
        {
            var first = new ClassWithIndexer();

            first.X = 1;
            first.Y = 2;

            var second = new ClassWithIndexer();

            second.X = 1;
            second.Y = 2;

            var result = first.Equals(second);

            Assert.True(result);
        }
Beispiel #13
0
        public void PropertyComparerFailsWithTargetParameterCountException()
        {
            //This is the comparison class
            CompareLogic compareLogic = new CompareLogic();

            compareLogic.Config.SkipInvalidIndexers = true;

            var class1 = new ClassWithIndexer();
            var class2 = new ClassWithIndexer();

            //These will be different, write out the differences
            ComparisonResult result = compareLogic.Compare(class1, class2);

            if (!result.AreEqual)
            {
                Console.WriteLine(result.DifferencesString);
            }
        }
        public void String_representation_of_expressions_are_as_expected()
        {
            var a         = 1;
            var b         = 2;
            var array     = new int[10];
            var myClass   = new MyClass();
            int?nullableA = 1;
            var list      = new List <int>();
            var indexer   = new ClassWithIndexer();

            Same(() => a + b, "a + b");
            Same(() => !(a + b == 0), "!(a + b == 0)");
            Same(() => CallFunction(a + b), "CallFunction(a + b)");
            Same(() => (long)a + b, "(long)a + (long)b");
            Same(() => (int?)a + b, "a + b");
            Same(() => nullableA == 1, "nullableA == 1");
            Same(() => nullableA == a, "nullableA == a");
            Same(() => (long)nullableA == a, "(long)nullableA == (long)a");
            Same(() => int.Parse("123"), @"int.Parse(""123"")");
            Same(() => array.Length, "array.Length");
            Same(() => array[2], "array[2]");
            Same(() => list[2], "list[2]");
            Same(() => indexer[2, 5], "indexer[2, 5]");
            Same(() => myClass[5], "myClass[5]");
            Same(() => a + b > 3 ? 10 : 12, "a + b > 3 ? 10 : 12");
            Same(() => _instanceField == 11, "_instanceField == 11");
            Same(() => _staticField == 110, "_staticField == 110");
            Same(() => MyClass.Value == 10, "MyClass.Value == 10");
            Same(() => MyProperty == 10, "MyProperty == 10");
            Same(() => PrivateProperty == 10, "PrivateProperty == 10");
            Same(() => PublicPropertyPrivateSetter == 10, "PublicPropertyPrivateSetter == 10");
            Same(() => new GenericClass <string>() == null, "new GenericClass<string>() == null");
            Same(() => new GenericClass <GenericClass <string> >() == null, "new GenericClass<GenericClass<string>>() == null");
            Same(() => new List <int> {
                10, 11, 12
            }.SequenceEqual(array), "new List<int>() { 10, 11, 12 }.SequenceEqual(array)");
            Same(() => new int[10] != null, "new int[10] != null");
            Same(() => new int?[10] != null, "new int?[10] != null");
            Same(() => new int[10][] != null, "new int[10][] != null");
            Same(() => new int[10][][] != null, "new int[10][][] != null");
        }