Пример #1
0
        /// <summary>
        ///   Makes the behavior execute only if the condition against a service
        ///   in the underlying IoC container is true
        /// </summary>
        /// <typeparam name = "T"></typeparam>
        /// <param name = "condition"></param>
        public void ConditionByService <T>(Func <T, bool> condition)
        {
            var description = "By Service:  Func<{0}, bool>".ToFormat(typeof(T).Name);

            Trace(new ConditionAdded(description));
            _conditionalDef = ConditionalObjectDef.ForService(condition);
        }
 public void for_conditional_with_the_wrong_kind_of_type()
 {
     Exception <ArgumentOutOfRangeException> .ShouldBeThrownBy(() =>
     {
         ConditionalObjectDef.For(typeof(Model));
     });
 }
Пример #3
0
        /// <summary>
        ///   Makes the behavior execute only if the condition against a model
        ///   object pulled from IFubuRequest is true
        /// </summary>
        public void ConditionByModel <T>(Func <T, bool> filter) where T : class
        {
            var description = "By Model:  Func<{0}, bool>".ToFormat(typeof(T).Name);

            Trace(new ConditionAdded(description));
            _conditionalDef = ConditionalObjectDef.ForModel(filter);
        }
        public void for_service_negative()
        {
            var theService = new Service()
            {
                IsTrue = false
            };

            theContainer.Inject(theService);

            var def = ConditionalObjectDef.ForService <Service>(x => x.IsTrue);

            build(def).ShouldExecute().ShouldBeFalse();
        }
        public void for_model_positive()
        {
            var model = new Model {
                Name = "Jeremy"
            };

            theRequest.Set(model);

            var def         = ConditionalObjectDef.ForModel <Model>(x => x.Name == "Jeremy");
            var conditional = build(def);

            conditional.ShouldExecute().ShouldBeTrue();

            // Change the name on the model should now make the test false
            model.Name = "Jessica";
            conditional.ShouldExecute().ShouldBeFalse();
        }
        public void for_filter_negative()
        {
            var def = ConditionalObjectDef.For(() => false);

            build(def).ShouldBeOfType <LambdaConditional>().ShouldExecute().ShouldBeFalse();
        }
        public void for_filter_positive()
        {
            var def = ConditionalObjectDef.For(() => true);

            build(def).ShouldBeOfType <LambdaConditional>().ShouldExecute().ShouldBeTrue();
        }
        public void for_conditional_type()
        {
            var def = ConditionalObjectDef.For <AlwaysTrue>();

            build(def).ShouldBeOfType <AlwaysTrue>();
        }
        public void for_conditional_type_positive()
        {
            var def = ConditionalObjectDef.For(typeof(AlwaysTrue));

            def.Type.ShouldEqual(typeof(AlwaysTrue));
        }
Пример #10
0
 /// <summary>
 ///   Make the behavior *only* execute if the condition is met
 /// </summary>
 /// <param name = "condition"></param>
 /// <param name="description"></param>
 public void Condition(Func <bool> condition, string description = "Anonymous")
 {
     Trace(new ConditionAdded(description));
     _conditionalDef = ConditionalObjectDef.For(condition);
 }
Пример #11
0
 /// <summary>
 ///   Makes the behavior execute only if the custom IConditional evaluates
 ///   true
 /// </summary>
 public void Condition <T>() where T : IConditional
 {
     Trace(new ConditionAdded(typeof(T)));
     _conditionalDef = ConditionalObjectDef.For <T>();
 }
Пример #12
0
 public void Condition(Type type)
 {
     Trace(new ConditionAdded(type));
     _conditionalDef = ConditionalObjectDef.For(type);
 }
Пример #13
0
 /// <summary>
 /// Makes the behavior execute only if the custom IConditional evaluates
 /// true
 /// </summary>
 public void Condition <T>() where T : IConditional
 {
     _conditionalDef = ConditionalObjectDef.For <T>();
 }
Пример #14
0
 /// <summary>
 /// Makes the behavior execute only if the condition against a model
 /// object pulled from IFubuRequest is true
 /// </summary>
 public void ConditionByModel <T>(Func <T, bool> filter) where T : class
 {
     _conditionalDef = ConditionalObjectDef.ForModel(filter);
 }
Пример #15
0
 /// <summary>
 /// Makes the behavior execute only if the condition against a service
 /// in the underlying IoC container is true
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="condition"></param>
 public void ConditionByService <T>(Func <T, bool> condition)
 {
     _conditionalDef = ConditionalObjectDef.ForService(condition);
 }
Пример #16
0
 /// <summary>
 /// Make the behavior *only* execute if the condition is met
 /// </summary>
 /// <param name="condition"></param>
 public void Condition(Func <bool> condition)
 {
     _conditionalDef = ConditionalObjectDef.For(condition);
 }