Example #1
0
        public void CanBeAssignedToTest()
        {
            // |     Fruit : IFruit (abstract)
            // |->   Apple : Fruit, IFruit, IRedSkinned
            // |->  Banana : Fruit, IFruit

            var reference = "Insert initialization of parameter ´reference´ here";
            object targetType = new Apple();
            Guard.CanBeAssignedTo<Apple>(() => reference, targetType);

            targetType = new Apple();
            Guard.CanBeAssignedTo<Fruit>(() => reference,  targetType);

            targetType = new Apple();
            Guard.CanBeAssignedTo<IRedSkinned>(() => reference, targetType);

            targetType = new Banana();
            Assert.Throws<ArgumentException>(() => Guard.CanBeAssignedTo<IRedSkinned>(() => reference, targetType));

            targetType = new AndNowToSomethingCompletelyDifferent();
            Assert.Throws<ArgumentException>(() => Guard.CanBeAssignedTo<IFruit>(() => reference,  targetType));
        }
Example #2
0
        public void IsAssignableFromTest()
        {
            // |     Fruit : IFruit (abstract)
            // |->   Apple : Fruit, IFruit, IRedSkinned -> GrannySmith
            // |->  Banana : Fruit, IFruit

            var reference = "Insert initialization of parameter ´reference´ here";
            object targetOfAssignment = new Apple();
            Guard.IsAssignableFrom<Apple>(() => reference, targetOfAssignment);

            targetOfAssignment = new Apple();
            Guard.IsAssignableFrom<GrannySmith>(() => reference, targetOfAssignment);

            targetOfAssignment = new Banana();
            Assert.Throws<ArgumentException>(() => Guard.IsAssignableFrom<IFruit>(() => reference, targetOfAssignment));

            targetOfAssignment = new AndNowToSomethingCompletelyDifferent();
            Assert.Throws<ArgumentException>(() => Guard.IsAssignableFrom<Fruit>(() => reference, targetOfAssignment));
        }