public void MatchFailure_Calls_Action_For_Failure() { var ex = new ExceptionWithContext(); var sut = Result.Failure<int>(ex); object actual = null; sut.MatchFailure(o => actual = o); actual.ShouldBeSameAs(ex); }
public string Evaluate(TagModel model) { string encodingName = GetAsString(Value, model); Encoding encoding = Encoding.GetEncoding(encodingName); try { model.Encoding = encoding; } catch (TagException Te) { throw ExceptionWithContext.MakePartial(Te).Decorate(Context); } return(String.Empty); }
public override object Evaluate(IModel model) { var parameters = new List <object>(); for (int i = 0; i < _function.Arguments.Length; i++) { var arg = _function.Arguments[i]; if (!arg.Params) { var node = _nested.Nodes[i]; object value = node.Evaluate(model); parameters.Add(TypeConverter.To(value, _function.Arguments[i].Type)); } else { for (int pi = i; pi < _nested.Nodes.Count; pi++) { var node = _nested.Nodes[pi]; object value = node.Evaluate(model); parameters.Add(TypeConverter.To(value, _function.Arguments[i].Type)); } } } try { return(_function.Evaluate(parameters.ToArray())); } catch (ExceptionWithContext EWC) { if (EWC.Context == null) { throw ExceptionWithContext.MakePartial(EWC).Decorate(Token); } else { throw EWC; } } catch (Exception e) { throw FunctionEvaluationException.EvaluationError(e).Decorate(Token); } }
public object Evaluate(TagModel model) { try { return(_tag.Evaluate(model)); } catch (ExceptionWithContext ewc) { if (ewc.Context == null) { throw ExceptionWithContext.MakePartial(ewc).Decorate(_tag.Context); } throw; } catch (Exception e) { throw TagException.EvaluationError(e).Decorate(_tag.Context); } }
public virtual void Validate(ITag tag) { if (tag == null) { return; } var type = tag.GetType(); foreach (var propertyInfo in type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy)) { try { ValidateProperty(tag, propertyInfo); } catch (TagException e) { throw ExceptionWithContext.MakePartial(e).Decorate(tag.Context); } } }
public static TileExceptionWithContext ErrorInTile(string path, ExceptionWithContext exception) { String msg = String.Format("Error in tile {0}:{1}", path, exception.Message); return MakePartial(new TileExceptionWithContext(msg)).Decorate(exception.Context).KeepHttpErrorCode(exception); }
public static TileExceptionWithContext ErrorInTile(string path, ExceptionWithContext exception) { String msg = String.Format("Error in tile {0}:{1}", path, exception.Message); return(MakePartial(new TileExceptionWithContext(msg)).Decorate(exception.Context).KeepHttpErrorCode(exception)); }
public void Match_Executes_On_Failure_Value_If_Instance_Is_a_Failure() { var ex = new ExceptionWithContext(); var sut = Result.Failure<string>(ex); sut.Match( _ => Assert.Fail("Function called on either"), o => o.ShouldBeSameAs(ex)); }
public void Two_Results_Are_Equal_If_Their_Failure_Values_Are_Equal() { var ex = new ExceptionWithContext(); var value = Result.Failure<int>(ex); var otherValue = Result.Failure<int>(ex); value.ShouldSatisfyAllConditions( () => value.ShouldBeStructuralEqual(otherValue), () => (value == otherValue).ShouldBe(true, "value == otherValue"), () => (value != otherValue).ShouldBe(false, "value != otherValue")); }