Beispiel #1
0
        public static Invoker Throw <TException>(this IShould <Invoker> should)
        {
            var exceptionType = typeof(TException);

            return(should.Apply(
                       (t, a) =>
            {
                var result = t.Invoke();

                if (result.Error == null)
                {
                    a.Fail(AssertionMessages.NoDerivedExceptionMessage(exceptionType));
                }

                if (!(result.Error is TException))
                {
                    a.Fail(AssertionMessages.NoDerivedExceptionMessage(exceptionType, result.Error));
                }
            },
                       (t, a) =>
            {
                var result = t.Invoke();

                if (result.Error is TException)
                {
                    a.Fail(AssertionMessages.DerivedExceptionMessage(exceptionType));
                }

                if (result.Error != null)
                {
                    throw new UnexpectedExceptionException(AssertionMessages.UnexpectedExceptionMessage, result.Error);
                }
            }));
        }
Beispiel #2
0
        public static Invoker Throw(this IShould <Invoker> should, Exception error)
        {
            return(should.Apply(
                       (t, a) =>
            {
                var result = t.Invoke();

                if (result.Error == null)
                {
                    a.Fail(AssertionMessages.NoExceptionInstanceMessage(error));
                }

                if (!result.Error.Equals(error))
                {
                    a.Fail(AssertionMessages.NoExceptionInstanceMessage(error, result.Error));
                }
            },
                       (t, a) =>
            {
                var result = t.Invoke();

                if (error.Equals(result.Error))
                {
                    a.Fail(AssertionMessages.ExceptionInstanceMessage(error));
                }

                if (result.Error != null)
                {
                    throw new UnexpectedExceptionException(AssertionMessages.UnexpectedExceptionMessage, result.Error);
                }
            }));
        }
 public static DateTime Equal(this IShould <DateTime> should, DateTime expected, DatePrecision precision)
 {
     return(should.Apply(
                (t, a) => a.AreEqual(expected, t, precision),
                (t, a) => a.AreNotEqual(expected, t, precision)
                ));
 }
 public static double Equal(this IShould <double> should, double expected, double tolerance)
 {
     return(should.Apply(
                (t, a) => a.AreEqual(expected, t, tolerance),
                (t, a) => a.AreNotEqual(expected, t, tolerance)
                ));
 }
Beispiel #5
0
        public static Invoker Throw(this IShould <Invoker> should, Type exceptionType)
        {
            return(should.Apply(
                       (t, a) =>
            {
                var result = t.Invoke();

                if (result.Error == null)
                {
                    a.Fail(AssertionMessages.NoExactExceptionMessage(exceptionType));
                }

                if (result.Error.GetType() != exceptionType)
                {
                    a.Fail(AssertionMessages.NoExactExceptionMessage(exceptionType, result.Error));
                }
            },
                       (t, a) =>
            {
                var result = t.Invoke();

                if (exceptionType == result.Error.GetType())
                {
                    a.Fail(AssertionMessages.ExactExceptionMessage(exceptionType));
                }

                if (result.Error != null)
                {
                    throw new UnexpectedExceptionException(AssertionMessages.UnexpectedExceptionMessage, result.Error);
                }
            }));
        }
 public static DateTime Equal(this IShould <DateTime> should, DateTime expected, TimeSpan tolerance)
 {
     return(should.Apply(
                (t, a) => a.AreEqual(expected, t, tolerance),
                (t, a) => a.AreNotEqual(expected, t, tolerance)
                ));
 }
Beispiel #7
0
 public static string Contain(this IShould <string> should, string expectedSubstring)
 {
     return(should.Apply(
                (t, a) => a.IsSubstringOf(t, expectedSubstring),
                (t, a) =>
     {
         if (t.Contains(expectedSubstring))
         {
             a.Fail("Expected string '{0}' to not contain '{1}', but it did.", t, expectedSubstring);
         }
     }));
 }
Beispiel #8
0
        public static void HaveBodyOfType <T>(this IShould <HttpResponseMessage> response, string userMessage = null, params object[] userMessageArgs)
        {
            Assert.NotNull(response, userMessage, userMessageArgs);
            Assert.NotNull(response.Value, userMessage, userMessageArgs);
            Assert.NotNull(response.Value.Content, userMessage, userMessageArgs);

            var json = response.Value.Content.ReadAsStringAsync().ConfigureAwait(false).GetAwaiter().GetResult();

            Assert.NotEmpty(json);

            var body = JsonConvert.DeserializeObject <T>(json);

            Assert.NotNull(body);
        }
Beispiel #9
0
 public static string EndWith(this IShould <string> should, string expectedSubstring)
 {
     return(should.Apply(
                (t, a) =>
     {
         if (!t.EndsWith(expectedSubstring))
         {
             a.Fail("Expected string '{0}' to end with '{1}', but it did not.", t, expectedSubstring);
         }
     },
                (t, a) =>
     {
         if (t.EndsWith(expectedSubstring))
         {
             a.Fail("Expected string '{0}' to not end with '{1}', but it did.", t, expectedSubstring);
         }
     }));
 }
Beispiel #10
0
 public static void HaveBody(this IShould <HttpResponseMessage> response, string userMessage = null, params object[] userMessageArgs)
 {
     Assert.NotNull(response, userMessage, userMessageArgs);
     Assert.NotNull(response.Value, userMessage, userMessageArgs);
     Assert.True(response.Value.Content != null, userMessage, userMessageArgs);
 }
Beispiel #11
0
 public static void NotHaveHeader(this IShould <HttpResponseMessage> response, string header, string userMessage = null, params object[] userMessageArgs)
 {
     Assert.NotNull(response, userMessage, userMessageArgs);
     Assert.NotNull(response.Value, userMessage, userMessageArgs);
     Assert.False(response.Value.Headers.Contains(header), userMessage, userMessageArgs);
 }
Beispiel #12
0
 public static void HaveStatus(this IShould <HttpResponseMessage> response, HttpStatusCode statusCode, string userMessage = null, params object[] userMessageArgs)
 {
     Assert.NotNull(response, userMessage, userMessageArgs);
     Assert.NotNull(response.Value, userMessage, userMessageArgs);
     Assert.True(response.Value.StatusCode == statusCode, userMessage, userMessageArgs);
 }
Beispiel #13
0
 public static void BeUnauthorized(this IShould <HttpResponseMessage> response, string userMessage = null, params object[] userMessageArgs)
 {
     Assert.NotNull(response, userMessage, userMessageArgs);
     Assert.NotNull(response.Value, userMessage, userMessageArgs);
     Assert.True(response.Value.StatusCode == HttpStatusCode.Unauthorized, userMessage ?? $"Response status code was {response.Value.StatusCode}", userMessageArgs);
 }
Beispiel #14
0
 public BeBase(IShould <TTarget> should)
 {
     this.should = should;
 }
Beispiel #15
0
 public static void HaveStatus(this IShould <HttpResponseMessage> response, HttpStatusCode statusCode)
 {
     Assert.NotNull(response);
     Assert.NotNull(response.Value);
     Assert.True(response.Value.StatusCode == statusCode);
 }
Beispiel #16
0
 public static void Be <T>(this IShould <T> @this, T other, string userMessage = null, params object[] userMessageArgs)
 {
     Assert.Equal(@this.Value, other, userMessage, userMessageArgs);
 }
Beispiel #17
0
 public static TTarget LessThanOrEqual <TTarget>(IShould <TTarget> should, TTarget value, IComparer <TTarget> comparer)
 {
     return(should.Apply(
                (t, a) => a.LessThanOrEqual(t, value, comparer),
                (t, a) => a.GreaterThan(t, value, comparer)));
 }
 public BeFoo(IShould <Foo> should) : base(should)
 {
 }
Beispiel #19
0
 public static TTarget LessThan <TTarget>(IShould <TTarget> should, TTarget value)
 {
     return(should.Apply(
                (t, a) => a.LessThan(t, value),
                (t, a) => a.GreaterThanOrEqual(t, value)));
 }
Beispiel #20
0
 public Count(IShould <IEnumerable <T> > should)
 {
     this.should = should;
 }
Beispiel #21
0
 public Be(IShould <T> should) : base(should)
 {
 }
Beispiel #22
0
 public ExtendedContain(IShould <IEnumerable <T> > should) : base(should)
 {
     _should = should;
 }
Beispiel #23
0
 public static void NotBeNull <T>(this IShould <T> @this, string userMessage = null, params object[] userMessageArgs)
 {
     Assert.NotNull(@this.Value, userMessage, userMessageArgs);
 }
Beispiel #24
0
 public static void HaveBody(this IShould <HttpResponseMessage> response)
 {
     Assert.NotNull(response);
     Assert.NotNull(response.Value);
     Assert.True(response.Value.Content != null);
 }
Beispiel #25
0
 public static void BeOk(this IShould <HttpResponseMessage> response, string userMessage = null, params object[] userMessageArgs)
 {
     Assert.NotNull(response, userMessage, userMessageArgs);
     Assert.NotNull(response.Value, userMessage, userMessageArgs);
     Assert.True(response.Value.IsSuccessStatusCode, userMessage ?? $"Response status code was {response.Value.StatusCode}", userMessageArgs);
 }
Beispiel #26
0
 public static TTarget IsNull <TTarget>(IShould <TTarget> should)
 {
     return(should.Apply(
                (t, a) => a.IsNull(t),
                (t, a) => a.IsNotNull(t)));
 }
Beispiel #27
0
 public static ExtendedContain <T> Contain <T>(this IShould <IEnumerable <T> > should)
 {
     return(new ExtendedContain <T>(should));
 }
Beispiel #28
0
 public Contain(IShould <IEnumerable <T> > should)
 {
     this.should = should;
 }
Beispiel #29
0
 public static void BeOk(this IShould <HttpResponseMessage> response)
 {
     Assert.NotNull(response);
     Assert.NotNull(response.Value);
     Assert.True(response.Value.IsSuccessStatusCode);
 }