/// <summary>
 /// Extends <paramref name="mock"/> to simplify the return of a mocked <see cref="HttpAgentResult{T}"/> with a result.
 /// </summary>
 /// <typeparam name="TMock">The mock object <see cref="Type"/>.</typeparam>
 /// <typeparam name="T">The resultant entity <see cref="Type"/>.</typeparam>
 /// <param name="mock">The mock object.</param>
 /// <param name="value">The entity value.</param>
 /// <param name="statusCode">The <see cref="HttpStatusCode"/>.</param>
 /// <param name="sendArgs">Optional <see cref="HttpSendArgs"/>; defaults to <see cref="HttpMethod.Post"/>.</param>
 /// <returns>The <see cref="HttpAgentResult{T}"/> with an entity result.</returns>
 public static IReturnsResult <TMock> ReturnsHttpAgentResultAsync <TMock, T>(this IReturns <TMock, Task <HttpAgentResult <T> > > mock, T value, HttpStatusCode statusCode = HttpStatusCode.OK, HttpSendArgs?sendArgs = null) where TMock : class =>
 mock.ReturnsAsync(() => new HttpAgentResult <T>(sendArgs ?? new HttpSendArgs(HttpMethod.Post, null), new HttpResponseMessage(statusCode), value));
Beispiel #2
0
 /// <summary>
 /// Extends <paramref name="mock"/> to simplify the return of a mocked <see cref="WebApiAgentResult{TEntity}"/> with an entity result.
 /// </summary>
 /// <typeparam name="TMock">The mock object <see cref="Type"/>.</typeparam>
 /// <typeparam name="TEntity">The resultant entity <see cref="Type"/>.</typeparam>
 /// <param name="mock">The mock object.</param>
 /// <param name="entity">The entity value.</param>
 /// <param name="statusCode">The <see cref="HttpStatusCode"/>.</param>
 /// <returns>The <see cref="WebApiAgentResult{TEntity}"/> with an entity result.</returns>
 public static IReturnsResult <TMock> ReturnsWebApiAgentResultAsync <TMock, TEntity>(this IReturns <TMock, Task <WebApiAgentResult <TEntity> > > mock, TEntity entity, HttpStatusCode statusCode = HttpStatusCode.OK) where TMock : class =>
 mock.ReturnsAsync(() => new WebApiAgentResult <TEntity>(new HttpResponseMessage(statusCode), entity));
Beispiel #3
0
 /// <summary>
 /// Specifies the value to return from an asynchronous method.
 /// </summary>
 /// <typeparam name="TMock">Mocked type.</typeparam>
 /// <typeparam name="TResult">Type of the return value.</typeparam>
 /// <param name="mock">Returns verb which represents the mocked type and the task of return type</param>
 /// <param name="value">The value to return, or <see longword="null"/>.</param>
 public static IReturnsResult <TMock> ReturnsAsync <TMock, TResult>(this IReturns <TMock, ValueTask <TResult> > mock, TResult value) where TMock : class
 {
     return(mock.ReturnsAsync(() => value));
 }
 public static IReturnsResult <TMock> ReturnsJsonStream <TMock, TResult>(this IReturns <TMock, Task <TResult> > mock, string json)
     where TMock : class
     where TResult : Stream
 =>
 mock.ReturnsAsync((TResult)(Stream) new MemoryStream(Encoding.UTF8.GetBytes(json)));