コード例 #1
0
 public void no_overridebles()
 {
      var action = new Mock<ICustomAttributeProvider>();
     action.Setup(d => d.GetCustomAttributes(true))
           .Returns(new IOverrideValidationFailedPolicy[0]);
     var facade = new SmartContextFacade();
     ValidModelOnlyAttribute.CheckOverridePolicy(action.Object, facade);
     facade.PolicyOverride.Should().BeNull();
 }
コード例 #2
0
 public void only_one_override_policy()
 {
     var action = new Mock<ICustomAttributeProvider>();
     action.Setup(d => d.GetCustomAttributes(true))
           .Returns(new IOverrideValidationFailedPolicy[] {new ReturnViewIfValidationFailsAttribute(), new TransferIfValidationFailsAttribute()});
     var facade = new SmartContextFacade();
     ValidModelOnlyAttribute.CheckOverridePolicy(action.Object,facade);
     facade.PolicyOverride.Should().BeOfType<ReturnViewIfValidationFailsAttribute>();
 }
コード例 #3
0
        //internal for testing 
        internal SmartActionWorker CreateWorker(Controller ctrl,Func<dynamic> modelId, ICustomAttributeProvider action,IDependencyResolver solver)
        {
            if (ctrl == null) throw new NotSupportedException("This attribute works only with Controller");

            var ipFactory = solver.GetService<IValidationFailedPolicyFactory>();
            if (ipFactory == null)
            {
                ipFactory=new ValidationFailedPolicyActivator(solver);
            }
            
            var facade = new SmartContextFacade(ctrl,modelId,ValidationFailedPolicy??DefaultPolicy, ipFactory);
            
            
            CheckOverridePolicy(action,facade);
            var worker = new SmartActionWorker(facade);
            return worker;
        }
コード例 #4
0
 //internal for testing 
 internal static void CheckOverridePolicy(ICustomAttributeProvider action, SmartContextFacade facade)
 {
     var changePolicy = action.GetCustomAttributes(true).FirstOrDefault(at=> at is IOverrideValidationFailedPolicy).Cast<IOverrideValidationFailedPolicy>();
     if (changePolicy != null)
     {
         facade.PolicyOverride = changePolicy;
     }
 }