/// <summary> /// Continues testing a named property for an expected value /// </summary> /// <param name="with"></param> /// <param name="expected"></param> /// <typeparam name="T"></typeparam> public static IMore <T> Value <T>( this IWith <T> with, object expected ) { return(with.Value <T>(expected, NULL_STRING)); }
/// <summary> /// Tests that a cookie has the expected value /// </summary> /// <param name="with"></param> /// <param name="value"></param> /// <returns></returns> public static IMore <Cookie> Value( this IWith <Cookie> with, string value ) { return(with.Value(value, NULL_STRING)); }
/// <summary> /// Asserts against an expected attribute, with a matcher for the attribute /// </summary> /// <param name="with"></param> /// <param name="customMessage"></param> /// <typeparam name="TAttribute"></typeparam> /// <returns></returns> public static IMore <MethodInfo> Attribute <TAttribute>( this IWith <MethodInfo> with, string customMessage ) where TAttribute : Attribute { return(with.Attribute <TAttribute>(() => customMessage)); }
/// <summary> /// Tests the type on a property With continuation /// </summary> /// <param name="with"></param> /// <param name="expected"></param> /// <typeparam name="T"></typeparam> /// <returns></returns> public static IMore <T> Type <T>( this IWith <T> with, Type expected ) { return(with.Type(expected, NULL_STRING)); }
/// <summary> /// Tests that a cookie has the expected value /// </summary> /// <param name="with"></param> /// <param name="value"></param> /// <param name="customMessage"></param> /// <returns></returns> public static IMore <Cookie> Value( this IWith <Cookie> with, string value, string customMessage ) { return(with.Value(value, () => customMessage)); }
/// <summary> /// Continues testing a named property for an expected value /// </summary> /// <param name="with"></param> /// <param name="expected"></param> /// <param name="customMessage"></param> /// <typeparam name="T"></typeparam> public static IMore <T> Value <T>( this IWith <T> with, object expected, string customMessage ) { return(with.Value(expected, () => customMessage)); }
public void With_ToString() { IAlias person = sql.Alias("person"); ICte cte = sql.Cte("cte1").As(sql.Query.Select(person["Id"], person["Name"]).From(person)); IWith with = sql.With.Add(cte); Assert.Equal("WITH cte1 AS (SELECT person.Id, person.Name FROM person)", with.ToString()); }
/// <summary> /// Tests the type on a property With continuation /// </summary> /// <param name="with"></param> /// <param name="expected"></param> /// <param name="customMessageGenerator"></param> /// <typeparam name="T"></typeparam> /// <returns></returns> public static IMore <T> Type <T>( this IWith <T> with, Type expected, Func <string> customMessageGenerator ) { return((with as ICanAddMatcher <T>).Type(expected, customMessageGenerator)); }
/// <summary> /// Tests the type on a property With continuation /// </summary> /// <param name="with"></param> /// <param name="expected"></param> /// <param name="customMessage"></param> /// <typeparam name="T"></typeparam> /// <returns></returns> public static IMore <T> Type <T>( this IWith <T> with, Type expected, string customMessage ) { return(with.Type(expected, () => customMessage)); }
/// <summary> /// Asserts against an expected attribute, with a matcher for the attribute /// </summary> /// <param name="with"></param> /// <param name="matcher"></param> /// <param name="customMessage"></param> /// <typeparam name="TAttribute"></typeparam> /// <returns></returns> public static IMore <MethodInfo> Attribute <TAttribute>( this IWith <MethodInfo> with, Func <TAttribute, bool> matcher, string customMessage ) where TAttribute : Attribute { return(with.Attribute( matcher, () => customMessage )); }
/// <summary> /// Asserts against an expected attribute, with a matcher for the attribute /// </summary> /// <param name="with"></param> /// <param name="matcher"></param> /// <typeparam name="TAttribute"></typeparam> /// <returns></returns> public static IMore <MethodInfo> Attribute <TAttribute>( this IWith <MethodInfo> with, Func <TAttribute, bool> matcher ) where TAttribute : Attribute { return(with.Attribute( matcher, NULL_STRING )); }
/// <summary> /// Asserts against an expected attribute, with a matcher for the attribute /// </summary> /// <param name="with"></param> /// <param name="customMessageGenerator"></param> /// <typeparam name="TAttribute"></typeparam> /// <returns></returns> public static IMore <MethodInfo> Attribute <TAttribute>( this IWith <MethodInfo> with, Func <string> customMessageGenerator ) where TAttribute : Attribute { return(with.Attribute( null as Func <TAttribute, bool>, customMessageGenerator )); }
/// <summary> /// Asserts against an expected attribute, with a matcher for the attribute /// </summary> /// <param name="with"></param> /// <param name="matcher"></param> /// <param name="customMessageGenerator"></param> /// <typeparam name="TAttribute"></typeparam> /// <returns></returns> public static IMore <MethodInfo> Attribute <TAttribute>( this IWith <MethodInfo> with, Func <TAttribute, bool> matcher, Func <string> customMessageGenerator ) where TAttribute : Attribute { matcher ??= _ => true; return(with.AddMatcher(actual => TryMatchAnyParameterAttribute(actual, matcher, customMessageGenerator) ?? TryMatchParameterAttribute(actual, matcher, customMessageGenerator) ?? MatchMethodAttribute(actual, matcher, customMessageGenerator) )); }
public void Add_Params() { IAlias person = sql.Alias("person"); IAlias dept = sql.Alias("dept"); ICte cte1 = sql.Cte("cte1").As(sql.Query.Select(person.All).From(person)); ICte cte2 = sql.Cte("cte2").As(sql.Query.Select(dept.All).From(dept)); IWith with = sql.With.Add(cte1, cte2); QueryResult result = engine.Compile(with); Assert.Equal("WITH \"cte1\" AS (SELECT \"person\".* FROM \"person\"), " + "\"cte2\" AS (SELECT \"dept\".* FROM \"dept\")", result.Sql); }
public static IMore <Dog> Name( this IWith <Dog> with, string expected) { return(with.AddMatcher(actual => { var name = actual.Name; // ?.GetOrDefault(nameof(Animal.Name), null as string); var passed = name == expected; return new MatcherResult( passed, () => $"Expected {actual} to have name '{expected}'" ); })); }
public void With_Recursive() { engine.Options.WithRecursive = true; IAlias person = sql.Alias("person"); IAlias dept = sql.Alias("dept"); ICte cte1 = sql.Cte("cte1").As(sql.Query.Select(person.All).From(person)); ICte cte2 = sql.Cte("cte2").As(sql.Query.Select(dept.All).From(dept)); IWith with = sql.With.Add(cte1).Add(cte2); QueryResult result = engine.Compile(with); Assert.Equal("WITH RECURSIVE \"cte1\" AS (SELECT \"person\".* FROM \"person\"), " + "\"cte2\" AS (SELECT \"dept\".* FROM \"dept\")", result.Sql); }
private Task <Result <TData> > With <TData>(IWith <TData> with) { var pipelineType = with.GetType(); var withMultipleType = typeof(WithMultiple <, ,>).MakeGenericType(pipelineType.GenericTypeArguments); var withMultipleHandlerType = typeof(WithMultipleHandler <, ,>).MakeGenericType(pipelineType.GenericTypeArguments); var withMultipleHandler = _serviceProvider.GetService(withMultipleHandlerType); var methodInfo = withMultipleHandlerType .GetMethods(BindingFlags.Instance | BindingFlags.Public) .Single(m => m.Name == nameof(IPipelineItemHandler <IPipeline> .ExecuteAsync)); var withMultipleObj = Convert.ChangeType(with, withMultipleType); var invokeResult = methodInfo.Invoke(withMultipleHandler, new [] { withMultipleObj }); return((Task <Result <TData> >)invokeResult); }
/// <summary> /// Tests that a cookie has the expected value /// </summary> /// <param name="with"></param> /// <param name="value"></param> /// <param name="customMessageGenerator"></param> /// <returns></returns> public static IMore <Cookie> Value( this IWith <Cookie> with, string value, Func <string> customMessageGenerator ) { return(with.AddMatcher(actual => { var passed = actual is not null && actual.Value.Equals(value); return new MatcherResult( passed, () => actual is null ? $"Expected {passed.AsNot()}to find cookie with value '{value}'" : $"Expected {passed.AsNot()}to find value '{value}' for cookie '{actual.Name}' (found value: '{actual.Value}')", customMessageGenerator ); })); }
/// <summary> /// Sets the content of the request to the specified content. /// </summary> /// <param name="content">The HTTP content.</param> /// <param name="encoding">The encoding to use for the content.</param> /// <param name="mediaType">The media type to use for the content.</param> /// <returns>An <see cref="IRequest"/> object that represents the request.</returns> public static IRequest String(this IWith @this, string content, Encoding encoding, string mediaType) => @this.String(new StringContent(content, encoding, mediaType));
/// <summary> /// Sets the content of the request to the specified content. /// </summary> /// <param name="content">The HTTP content.</param> /// <returns>An <see cref="IRequest"/> object that represents the request.</returns> public static IRequest String(this IWith @this, string content) => @this.String(new StringContent(content));
/// <summary> /// Sets the content of the request to the specified content. /// </summary> /// <param name="content">The HTTP content.</param> /// <returns>An <see cref="IRequest"/> object that represents the request.</returns> public static IRequest String(this IWith @this, StringContent content) => @this.Content(content);
/// <summary> /// Sets the content of the request to the specified content. /// </summary> /// <param name="nameValueCollection">A collection of name/value pairs.</param> /// <returns>An <see cref="IRequest"/> object that represents the request.</returns> public static IRequest FormUrlEncoded(this IWith @this, IEnumerable <KeyValuePair <string, string> > nameValueCollection) => @this.FormUrlEncoded(new FormUrlEncodedContent(nameValueCollection));
/// <summary> /// Sets the content of the request to the specified content. /// </summary> /// <param name="content">The HTTP content.</param> /// <returns>An <see cref="IRequest"/> object that represents the request.</returns> public static IRequest FormUrlEncoded(this IWith @this, FormUrlEncodedContent content) => @this.Content(content);
/// <summary> /// Sets the content of the request to the specified content. /// </summary> /// <param name="content">The HTTP content.</param> /// <param name="offset">The offset, in bytes, in the <paramref name="content"/> parameter.</param> /// <param name="count">The number of bytes in the <paramref name="content"/> starting from the <paramref name="offset"/> parameter.</param> /// <returns>An <see cref="IRequest"/> object that represents the request.</returns> public static IRequest ByteArray(this IWith @this, byte[] content, int offset, int count) => @this.ByteArray(new ByteArrayContent(content, offset, count));
/// <summary> /// Sets the content of the request to the specified content. /// </summary> /// <param name="content">The HTTP content.</param> /// <returns>An <see cref="IRequest"/> object that represents the request.</returns> public static IRequest ByteArray(this IWith @this, byte[] content) => @this.ByteArray(new ByteArrayContent(content));
/// <summary> /// Sets the content of the request to the specified content. /// </summary> /// <param name="content">The HTTP content.</param> /// <returns>An <see cref="IRequest"/> object that represents the request.</returns> public static IRequest ByteArray(this IWith @this, ByteArrayContent content) => @this.Content(content);
/// <summary> /// Sets the content of the request to the specified content. /// </summary> /// <param name="content">The HTTP content.</param> /// <returns>An <see cref="IRequest"/> object that represents the request.</returns> public static IRequest Xml(this IWith @this, string content) => @this.Content(new StringContent(content, Encoding.UTF8, "application/xml"));
/// <summary> /// Sets the content of the request to the specified content. /// </summary> /// <param name="content">The HTTP content.</param> /// <returns>An <see cref="IRequest"/> object that represents the request.</returns> public static IRequest Xml(this IWith @this, XDocument content) => @this.Xml(content.ToString());
/// <summary> /// Sets the content of the request to the specified content. /// </summary> /// <param name="content">The HTTP content.</param> /// <returns>An <see cref="IRequest"/> object that represents the request.</returns> public static IRequest Json(this IWith @this, object content) => @this.Json(JsonConvert.SerializeObject(content));
/// <summary> /// Sets the content of the request to the specified content with buffer size. /// </summary> /// <param name="content">The HTTP content.</param> /// <param name="bufferSize">The size, in bytes, of the buffer for the <paramref name="content"/>.</param> /// <returns>An <see cref="IRequest"/> object that represents the request.</returns> public static IRequest Stream(this IWith @this, Stream content, int bufferSize) => @this.Content(new StreamContent(content, bufferSize));