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); } })); }
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) )); }
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) )); }
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); } })); }
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); }
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); } })); }
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); }
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); }
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); }
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); }
public BeBase(IShould <TTarget> should) { this.should = should; }
public static void HaveStatus(this IShould <HttpResponseMessage> response, HttpStatusCode statusCode) { Assert.NotNull(response); Assert.NotNull(response.Value); Assert.True(response.Value.StatusCode == statusCode); }
public static void Be <T>(this IShould <T> @this, T other, string userMessage = null, params object[] userMessageArgs) { Assert.Equal(@this.Value, other, userMessage, userMessageArgs); }
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) { }
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))); }
public Count(IShould <IEnumerable <T> > should) { this.should = should; }
public Be(IShould <T> should) : base(should) { }
public ExtendedContain(IShould <IEnumerable <T> > should) : base(should) { _should = should; }
public static void NotBeNull <T>(this IShould <T> @this, string userMessage = null, params object[] userMessageArgs) { Assert.NotNull(@this.Value, userMessage, userMessageArgs); }
public static void HaveBody(this IShould <HttpResponseMessage> response) { Assert.NotNull(response); Assert.NotNull(response.Value); Assert.True(response.Value.Content != null); }
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); }
public static TTarget IsNull <TTarget>(IShould <TTarget> should) { return(should.Apply( (t, a) => a.IsNull(t), (t, a) => a.IsNotNull(t))); }
public static ExtendedContain <T> Contain <T>(this IShould <IEnumerable <T> > should) { return(new ExtendedContain <T>(should)); }
public Contain(IShould <IEnumerable <T> > should) { this.should = should; }
public static void BeOk(this IShould <HttpResponseMessage> response) { Assert.NotNull(response); Assert.NotNull(response.Value); Assert.True(response.Value.IsSuccessStatusCode); }