Ejemplo n.º 1
0
 protected AsserterBase(TRequest request, [CanBeNull] string parameterName, LogAssertionDelegate log)
 {
     _log           = log;
     _request       = request;
     _parameterName = String.IsNullOrWhiteSpace(parameterName)
         ? null
         : String.Concat(" ", _parameterName);
 }
Ejemplo n.º 2
0
 /// <exception cref="Exception">Can't compile/invoke <paramref name="requestExpression"/>.</exception>
 protected AsserterBase(Expression <Func <TRequest> > requestExpression, LogAssertionDelegate log)
 {
     _log = log;
     try {
         _request       = requestExpression.Compile()();
         _parameterName = requestExpression.Path();
     }
     catch (Exception e) {
         log?.Invoke(TraceEventType.Error, $"Can't get object for assertion throuth expression {requestExpression}.\n\n{e}");
         throw;
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Returns an asserter that should be used like:
 /// string error;
 /// if (!Guard.AssertOn(someRequest)
 ///        .That(x => x.Document.Type.Id != Guid.Empty)
 ///        .That(x => !string.IsNullOrWhiteSpace(x.Kind.Name)
 ///        .IsValid(out error)) {
 ///     return error;
 /// }
 /// or like
 /// var assert = Guard.GetAsserter
 /// if (!assert.That(x => x.Document.Type.Id != Guid.Empty)
 ///       .That(x => !string.IsNullOrWhiteSpace(x.Kind.Name)
 ///       .IsValid() {
 ///     return assert.ErrorMessage;
 /// }
 /// </summary>
 /// <seealso cref="IAssert{TRequest}"/>
 /// <param name="requestExpression">Expression to get object from invoker context</param>
 /// <param name="logger">An logger session, to internally log all getted errors</param>
 /// <exception cref="Exception">Can't compile/invoke <paramref name="requestExpression" />.</exception>
 public static IAssert <TRequest> GetAsserter <TRequest>([NotNull] Expression <Func <TRequest> > requestExpression, LogAssertionDelegate log = null)
 {
     return(new QuietAsserter <TRequest>(requestExpression, log));
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Returns an asserter that should be used like:
 /// using (var assert = Guard.GetExceptionAsserter(someRequest) {
 ///     assert.That(x => x.Document.Type.Id != Guid.Empty)
 ///           .That(x => !string.IsNullOrWhiteSpace(x.Kind.Name)
 ///           .IsValid()
 /// }
 /// </summary>
 /// <seealso cref="IAssert{TRequest}"/>
 /// <param name="request">Object that being asserted</param>
 /// <param name="argument">Name of argument of invoker method, that being asserted.</param>
 /// <param name="variable">Name of local variable of invoker method, that being asserted.</param>
 /// <param name="logger">An logger session, to internally log all getted errors</param>
 public static IAssert <TRequest> GetExceptionAsserter <TRequest>(TRequest request, [InvokerParameterName] string argument = null, string variable = null, LogAssertionDelegate log = null)
 {
     return(new ExceptionAsserter <TRequest>(request, argument ?? variable, log));
 }
Ejemplo n.º 5
0
 public ExceptionAsserter(TRequest request, string parameterName, LogAssertionDelegate log) : base(request, parameterName, log)
 {
 }
Ejemplo n.º 6
0
 /// <exception cref="Exception">Can't compile/invoke <paramref name="requestExpression" />.</exception>
 public ExceptionAsserter(Expression <Func <TRequest> > requestExpression, LogAssertionDelegate log) : base(requestExpression, log)
 {
 }