Example #1
0
        public void GetTypeWithAdditionalDataViewTypeAttributes()
        {
            var a = new DataViewAlienBodyType(7788);
            var b = new AlienTypeAttributeAttribute(8877);
            var c = new ColumnNameAttribute("foo");
            var d = new AlienTypeAttributeAttribute(8876);


            DataViewTypeManager.Register(a, typeof(AlienBody), b);
            Assert.True(DataViewTypeManager.Knows(a));
            Assert.True(DataViewTypeManager.Knows(typeof(AlienBody), new Attribute[] { b, c }));
            // "a" is associated with typeof(AlienBody) with "b," so the call below should return true.
            Assert.Equal(a, DataViewTypeManager.GetDataViewType(typeof(AlienBody), new Attribute[] { b, c }));
            Assert.Throws <ArgumentOutOfRangeException>(() => DataViewTypeManager.Knows(typeof(AlienBody), new Attribute[] { b, d }));
        }
Example #2
0
        public void TestTypeManager()
        {
            // Semantically identical DataViewTypes should produce the same hash code.
            var a     = new DataViewAlienBodyType(9527);
            var aCode = a.GetHashCode();
            var b     = new DataViewAlienBodyType(9527);
            var bCode = b.GetHashCode();

            Assert.Equal(aCode, bCode);

            // Semantically identical attributes should produce the same hash code.
            var c     = new AlienTypeAttributeAttribute(1228);
            var cCode = c.GetHashCode();
            var d     = new AlienTypeAttributeAttribute(1228);
            var dCode = d.GetHashCode();

            Assert.Equal(cCode, dCode);

            // Check registering the same type pair is OK.
            // Note that "a" and "b" should be identical.
            DataViewTypeManager.Register(a, typeof(AlienBody));
            DataViewTypeManager.Register(a, typeof(AlienBody));
            DataViewTypeManager.Register(b, typeof(AlienBody));
            DataViewTypeManager.Register(b, typeof(AlienBody));

            // Check if register of (a, typeof(AlienBody)) successes.
            Assert.True(DataViewTypeManager.Knows(a));
            Assert.True(DataViewTypeManager.Knows(b));
            Assert.True(DataViewTypeManager.Knows(typeof(AlienBody)));
            Assert.Equal(a, DataViewTypeManager.GetDataViewType(typeof(AlienBody)));
            Assert.Equal(b, DataViewTypeManager.GetDataViewType(typeof(AlienBody)));

            // Make sure registering the same type twice throws.
            bool isWrong = false;

            try
            {
                // "a" has been registered with AlienBody without any attribute, so the user can't
                // register "a" again with AlienBody plus the attribute "c."
                DataViewTypeManager.Register(a, typeof(AlienBody), c);
            }
            catch
            {
                isWrong = true;
            }
            Assert.True(isWrong);

            // Make sure registering the same type twice throws.
            isWrong = false;
            try
            {
                // AlienBody has been registered with "a," so user can't register it with
                // "new DataViewAlienBodyType(5566)" again.
                DataViewTypeManager.Register(new DataViewAlienBodyType(5566), typeof(AlienBody));
            }
            catch
            {
                isWrong = true;
            }
            Assert.True(isWrong);

            // Register a type with attribute.
            var e = new DataViewAlienBodyType(7788);
            var f = new AlienTypeAttributeAttribute(8877);

            DataViewTypeManager.Register(e, typeof(AlienBody), f);
            Assert.True(DataViewTypeManager.Knows(e));
            Assert.True(DataViewTypeManager.Knows(typeof(AlienBody), new[] { f }));
            // "e" is associated with typeof(AlienBody) with "f," so the call below should return true.
            Assert.Equal(e, DataViewTypeManager.GetDataViewType(typeof(AlienBody), new[] { f }));
            // "a" is associated with typeof(AlienBody) without any attribute, so the call below should return false.
            Assert.NotEqual(a, DataViewTypeManager.GetDataViewType(typeof(AlienBody), new[] { f }));
        }