Example #1
0
        public void Instance_Generic()
        {
            // Arrange
            var Cache = ReflectionCache <DummyEnum> .CreateFromEnum <DummyEnum>();

            // Act
            var inst1 = Cache.CreateInstance <Byte>(DummyEnum.t_byte);
            var inst2 = Cache.CreateInstance <Int32>(DummyEnum.t_int32);
            var inst3 = Cache.CreateInstance <Int64>(DummyEnum.t_int64);

            //Assert
            Assert.AreEqual(typeof(System.Byte), inst1.GetType());
            Assert.AreEqual(typeof(System.Int32), inst2.GetType());
            Assert.AreEqual(typeof(System.Int64), inst3.GetType());
        }
Example #2
0
        public void Create_from_Enum_Attr()
        {
            // Arrange
            var enumValues = Enum.GetValues(typeof(DummyEnum));
            var enumType   = typeof(DummyEnum);

            // Act
            var Cache = ReflectionCache <DummyEnum, ReflectionCacheAttribute> .CreateFromEnum();

            // Assert
            CollectionAssert.AreEqual(enumValues, Cache.Keys);
            foreach (var t in enumValues)
            {
                var memInfo   = enumType.GetMember(t.ToString());
                var attribute = memInfo[0].GetCustomAttributes(typeof(ReflectionCacheAttribute), false)
                                .Cast <ReflectionCacheAttribute>()
                                .FirstOrDefault();

                Cache.TryGetValue((DummyEnum)t, out var tValue);
                Assert.AreEqual(attribute.Type, tValue.Type);
            }
        }
Example #3
0
        public void TestCreateFromEmptyEnum()
        {
            reflectionCache = ReflectionCache <byte> .CreateFromEnum <MyEmptyEnum>();

            reflectionCache.Count.Should().Be(0);
        }
Example #4
0
        public void TestCreateFromObjectNotEnum()
        {
            Action action = () => ReflectionCache <byte> .CreateFromEnum <int>();

            action.ShouldThrow <ArgumentException>();
        }
Example #5
0
 public void SetUp()
 {
     reflectionCache = ReflectionCache <byte> .CreateFromEnum <MyTestEnum>();
 }