Example #1
0
        public void Requires_Permission(Type objectType){
            var application = Isolate.Fake.Instance<XafApplication>();
            var controller = new NavigationItemsController{Application = application};
            var args = new CustomShowNavigationItemEventArgs(null);
            Isolate.WhenCalled(() => args.FitToObjectType(application, objectType)).WithExactArguments().WillReturn(true);
            Isolate.WhenCalled(() => args.FitToObjectType(application, objectType)).WillReturn(false);
            Isolate.WhenCalled(() => SecuritySystem.IsGranted(null)).WillReturn(false);

            

            controller.ControllerOnCustomShowNavigationItem(null,args);


        }
 protected internal virtual void ControllerOnCustomShowNavigationItem(object sender, CustomShowNavigationItemEventArgs args) {
     if (args.FitToObjectType(Application, typeof(ModelDifferenceObject))&&SecuritySystem.Instance is ISecurityComplex) {
         SecuritySystem.ReloadPermissions();
         if (!SecuritySystemExtensions.IsGranted(new EditModelPermission(ModelAccessModifier.Allow), false)) {
             args.Handled = true;
             throw new SecurityException(ExceptionLocalizerTemplate<SystemExceptionResourceLocalizer, ExceptionId>.GetExceptionMessage(ExceptionId.PermissionIsDenied));
         }
     }
 }