public void MediumTrustAllowsCopyingBetweenTypesFromSameModule()
        {
            SampleBaseClass i1 = new SampleDerivedClass("1st config val");
            SampleBaseClass i2 = new SampleFurtherDerivedClass("2nd config val");

            SecurityTemplate.MediumTrustInvoke(new ThreadStart(new CopyCommand(i2, i1).Execute));
            Assert.AreEqual(i1, i2);
        }
        public void MediumTrustThrowsSecurityExceptionWhenCopyingBetweenTypesFromDifferentModules()
        {
            Exception     e1 = new Exception("my name is e1");
            HttpException e2 = new HttpException("my name is e2");

            // I know, I am a bit paranoid about that basic assumption
            Assert.AreNotEqual(e1.GetType().Assembly, e2.GetType().Assembly);

            SecurityTemplate.MediumTrustInvoke(new ThreadStart(new CopyCommand(e2, e1).Execute));
            Assert.AreEqual(e1.Message, e2.Message);
        }
        public void CannotReadPrivateReadOnlyFieldIfNoReflectionPermission()
        {
            FieldInfo fieldInfo = typeof(MyStaticClass).GetField("myPrivateReadonlyField", BindingFlags.Static | BindingFlags.NonPublic);

            try
            {
                SecurityTemplate.MediumTrustInvoke(delegate
                {
                    IDynamicField myPrivateReadonlyField2 = Create(fieldInfo);
                });
                Assert.Fail("private field must not be accessible in medium trust: " + fieldInfo);
            }
            catch (SecurityException sex)
            {
                Assert.IsTrue(sex.Message.IndexOf("ReflectionPermission") > -1);
            }
        }
 public void CanCreateWithRestrictedPermissions()
 {
     SecurityTemplate.MediumTrustInvoke(new ThreadStart(CanCreateWithRestrictedPermissionsImpl));
 }
 public void CanCreatePrivateMethodButThrowsOnInvoke()
 {
     SecurityTemplate.MediumTrustInvoke(new ThreadStart(CanCreatePrivateMethodButThrowsOnInvokeImpl));
 }