예제 #1
0
 /// <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));
 }
예제 #2
0
 /// <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));
 }
예제 #3
0
 /// <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));
 }
예제 #4
0
 /// <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));
 }
예제 #5
0
 /// <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));
 }
예제 #6
0
 /// <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));
 }
예제 #7
0
        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());
        }
예제 #8
0
 /// <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));
 }
예제 #9
0
 /// <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));
 }
예제 #10
0
 /// <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
                ));
 }
예제 #11
0
 /// <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
                ));
 }
예제 #12
0
 /// <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
                ));
 }
예제 #13
0
 /// <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)
                            ));
 }
예제 #14
0
        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);
        }
예제 #15
0
파일: With.cs 프로젝트: fluffynuts/NExpect
 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}'"
             );
     }));
 }
예제 #16
0
        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);
        }
예제 #17
0
        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);
        }
예제 #18
0
 /// <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
             );
     }));
 }
예제 #19
0
 /// <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));
예제 #20
0
 /// <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));
예제 #21
0
 /// <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);
예제 #22
0
 /// <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));
예제 #23
0
 /// <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);
예제 #24
0
 /// <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));
예제 #25
0
 /// <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));
예제 #26
0
 /// <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);
예제 #27
0
 /// <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"));
예제 #28
0
 /// <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());
예제 #29
0
 /// <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));
예제 #30
0
 /// <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));