public void GetListingsAsyncWithQueryRequestShouldThrowPoeTradeApiCommunicationExceptionIfAnyExceptionOccurs() { AsyncTestDelegate asyncTestDelegate = async() => await this.poeTradeApiClient.GetListingsAsync(new SearchQueryRequest()); this.GetListingsAsyncShouldThrowPoeTradeApiCommunicationExceptionIfAnyExceptionOccurs(asyncTestDelegate); }
/// <summary> /// Verifies that an async delegate throws a particular exception when called. /// </summary> /// <typeparam name="TActual">Type of the expected exception</typeparam> /// <param name="code">A TestDelegate</param> /// <param name="message">The message that will be displayed on failure</param> /// <param name="args">Arguments to be used in formatting the message</param> public static TActual ThrowsAsync <TActual>(AsyncTestDelegate code, string message, params object[] args) where TActual : Exception { return((TActual)ThrowsAsync(typeof(TActual), code, message, args)); }
/// <summary> /// Verifies that an async delegate throws an exception when called /// and returns it. /// </summary> /// <param name="code">A TestDelegate</param> /// <param name="message">The message that will be displayed on failure</param> /// <param name="args">Arguments to be used in formatting the message</param> public static Exception CatchAsync(AsyncTestDelegate code, string message, params object[] args) { return(ThrowsAsync(new InstanceOfTypeConstraint(typeof(Exception)), code, message, args)); }
public static async Task <TActual?> ThrowsAsync <TActual>(AsyncTestDelegate code) where TActual : Exception { return(await ThrowsAsync <TActual>(code, string.Empty, null)); }
public TaskReturningTearDownFixture(AsyncTestDelegate asyncUserCode) { _asyncUserCode = asyncUserCode; }
public static async Task <Exception?> ThrowsAsync(IResolveConstraint expression, AsyncTestDelegate code) { return(await ThrowsAsync(expression, code, string.Empty, null)); }
public static async Task <Exception?> ThrowsAsync(Type expectedExceptionType, AsyncTestDelegate code) { return(await ThrowsAsync(new ExceptionTypeConstraint(expectedExceptionType), code, string.Empty, null)); }
private void GetListingsAsyncShouldThrowPoeTradeApiCommunicationExceptionIfAnyExceptionOccurs(AsyncTestDelegate asyncTestDelegate) { Exception expectedInnerException = new Exception(); this.poeTradeApiJsonSerializerMock.Setup(x => x.Deserialize <SearchQueryResult>(It.IsAny <string>())) .Throws(expectedInnerException); PoeTradeApiCommunicationException exception = Assert.CatchAsync <PoeTradeApiCommunicationException>(asyncTestDelegate); Assert.That(exception.InnerException, Is.EqualTo(expectedInnerException)); }
private void AssertThrowsPoeTradeApiCommunicationExceptionIfHttpResponseDoesNotReturnSuccessStatusCode(AsyncTestDelegate asyncTestDelegate, string endpoint, string jsonContent = "") { HttpStatusCode httpStatusCode = HttpStatusCode.BadRequest; HttpResponseMessage httpResponse = new HttpResponseMessage { Content = new StringContent(""), StatusCode = httpStatusCode }; this.poeTradeApiJsonSerializerMock.Setup(x => x.Serialize(It.IsAny <SearchQueryRequest>())) .Returns(jsonContent); this.httpClientWrapperMock.Setup(x => x.GetAsync(It.Is <string>(s => s.Contains(endpoint)), It.IsAny <CancellationToken>())) .ReturnsAsync(httpResponse); this.httpClientWrapperMock.Setup(x => x.PostAsync(It.Is <string>(s => s.Contains(endpoint)), It.IsAny <HttpContent>(), It.IsAny <CancellationToken>())) .ReturnsAsync(httpResponse); PoeTradeApiCommunicationException exception = Assert.CatchAsync <PoeTradeApiCommunicationException>(asyncTestDelegate); Assert.That(exception.Message, Contains.Substring(httpStatusCode.ToString())); Assert.That(exception.Message, Contains.Substring(endpoint)); if (!string.IsNullOrEmpty(jsonContent)) { Assert.That(exception.Message, Contains.Substring(jsonContent)); } }
private void GetListingsAsyncShouldThrowExceptionIfFetchResponseStatusCodeDoesNotIndicateSuccess(AsyncTestDelegate asyncTestDelegate) { this.poeTradeApiJsonSerializerMock.Setup(x => x.Deserialize <SearchQueryResult>(It.IsAny <string>())) .Returns(new SearchQueryResult { Result = new List <string> { "123" }, Total = 1 }); this.AssertThrowsPoeTradeApiCommunicationExceptionIfHttpResponseDoesNotReturnSuccessStatusCode(asyncTestDelegate, Resources.PoeTradeApiFetchEndpoint); }
private void GetListingsAsyncShouldThrowExceptionIfSearchRequestStatusCodeDoesNotIndicateSuccess(AsyncTestDelegate asyncTestDelegate) { this.poeTradeApiJsonSerializerMock.Setup(x => x.Deserialize <SearchQueryResult>(It.IsAny <string>())) .Returns(new SearchQueryResult()); this.AssertThrowsPoeTradeApiCommunicationExceptionIfHttpResponseDoesNotReturnSuccessStatusCode(asyncTestDelegate, Resources.PoeTradeApiSearchEndpoint, "posted json content"); }
private async Task GetListingsAsyncShouldDeserializeFetchResponseAsItemListingQueryResult(AsyncTestDelegate asyncTestDelegate) { string expected = "serialized item listings"; this.poeTradeApiJsonSerializerMock.Setup(x => x.Deserialize <SearchQueryResult>(It.IsAny <string>())) .Returns(new SearchQueryResult { Result = new List <string> { "123" }, Total = 1 }); this.poeTradeApiJsonSerializerMock.Setup(x => x.Deserialize <ItemListingsQueryResult>(It.IsAny <string>())) .Returns(new ItemListingsQueryResult()); this.httpClientWrapperMock.Setup(x => x.GetAsync(It.Is <string>(s => s.StartsWith(Resources.PoeTradeApiFetchEndpoint)), It.IsAny <CancellationToken>())) .ReturnsAsync(new HttpResponseMessage { Content = new StringContent(expected) }); await asyncTestDelegate(); this.poeTradeApiJsonSerializerMock.Verify(x => x.Deserialize <QueryResult <ListingResult> >(expected)); }
private async Task GetListingsAsyncShouldNotFetchItemsIfSearchQueryResultIsEmpty(AsyncTestDelegate asyncTestDelegate) { var searchQueryResult = new SearchQueryResult(); this.poeTradeApiJsonSerializerMock.Setup(x => x.Deserialize <SearchQueryResult>(It.IsAny <string>())) .Returns(searchQueryResult); await asyncTestDelegate(); this.httpClientWrapperMock.Verify(x => x.GetAsync(It.Is <string>(s => s.Contains(Resources.PoeTradeApiFetchEndpoint)), It.IsAny <CancellationToken>()), Times.Never); }
private async Task GetListingsAsyncShouldDeserializeSearchResponseAsSearchQueryResult(AsyncTestDelegate asyncTestDelegate) { string expected = "serialized search query response"; HttpResponseMessage httpResponse = new HttpResponseMessage { Content = new StringContent(expected) }; this.poeTradeApiJsonSerializerMock.Setup(x => x.Deserialize <SearchQueryResult>(It.IsAny <string>())) .Returns(new SearchQueryResult()); this.poeTradeApiJsonSerializerMock.Setup(x => x.Deserialize <ItemListingsQueryResult>(It.IsAny <string>())) .Returns(new ItemListingsQueryResult()); this.httpClientWrapperMock.Setup(x => x.PostAsync(It.Is <string>(s => s.StartsWith(Resources.PoeTradeApiSearchEndpoint)), It.IsAny <HttpContent>(), It.IsAny <CancellationToken>())) .ReturnsAsync(httpResponse); await asyncTestDelegate(); this.poeTradeApiJsonSerializerMock.Verify(x => x.Deserialize <SearchQueryResult>(expected)); }
/// <summary> /// Verifies that an async delegate throws a particular exception when called. /// </summary> /// <param name="expectedExceptionType">The exception Type expected</param> /// <param name="code">A TestDelegate</param> /// <param name="message">The message that will be displayed on failure</param> /// <param name="args">Arguments to be used in formatting the message</param> public static Exception ThrowsAsync(Type expectedExceptionType, AsyncTestDelegate code, string message, params object[] args) { return(ThrowsAsync(new ExceptionTypeConstraint(expectedExceptionType), code, message, args)); }
public void GetListingsAsyncShouldThrowArgumentNullExceptionIfQueryRequestIsNull() { AsyncTestDelegate testDelegate = async() => await this.poeTradeApiClient.GetListingsAsync(null); Assert.ThrowsAsync <ArgumentNullException>(testDelegate); }
public static async Task <Exception?> ThrowsAsync(IResolveConstraint expression, AsyncTestDelegate code, string message, params object?[]?args) { Exception?caughtException = null; try { await code(); } catch (Exception e) { caughtException = e; } Assert.That(caughtException, expression, message, args); return(caughtException); }
public static void DoesNotThrowAsync(AsyncTestDelegate action) { action.Invoke().Wait(); }
public static async Task <Exception?> ThrowsAsync(Type expectedExceptionType, AsyncTestDelegate code, string message, params object?[]?args) { return(await ThrowsAsync(new ExceptionTypeConstraint(expectedExceptionType), code, message, args)); }
/// <summary> /// Verifies that an async delegate throws an exception of a certain Type /// or one derived from it when called and returns it. /// </summary> /// <param name="expectedExceptionType">The expected Exception Type</param> /// <param name="code">A TestDelegate</param> public static Exception CatchAsync(Type expectedExceptionType, AsyncTestDelegate code) { return(ThrowsAsync(new InstanceOfTypeConstraint(expectedExceptionType), code)); }
public static async Task <TActual?> ThrowsAsync <TActual>(AsyncTestDelegate code, string message, params object?[]?args) where TActual : Exception { return((TActual?)(await ThrowsAsync(typeof(TActual), code, message, args))); }
/// <summary> /// Verifies that an async delegate throws an exception of a certain Type /// or one derived from it when called and returns it. /// </summary> /// <param name="code">A TestDelegate</param> /// <param name="message">The message that will be displayed on failure</param> /// <param name="args">Arguments to be used in formatting the message</param> public static TActual CatchAsync <TActual>(AsyncTestDelegate code, string message, params object[] args) where TActual : Exception { return((TActual)ThrowsAsync(new InstanceOfTypeConstraint(typeof(TActual)), code, message, args)); }
public TaskReturningTestMethodFixture(AsyncTestDelegate asyncUserCode) { _asyncUserCode = asyncUserCode; }
/// <summary> /// Verifies that an async delegate throws an exception of a certain Type /// or one derived from it when called and returns it. /// </summary> /// <param name="code">A TestDelegate</param> public static TActual CatchAsync <TActual>(AsyncTestDelegate code) where TActual : Exception { return((TActual)ThrowsAsync(new InstanceOfTypeConstraint(typeof(TActual)), code)); }
public TaskReturningOneTimeSetUpFixture(AsyncTestDelegate asyncUserCode) { _asyncUserCode = asyncUserCode; }
/// <summary> /// Verifies that an async delegate does not throw an exception /// </summary> /// <param name="code">A TestDelegate</param> /// <param name="message">The message that will be displayed on failure</param> /// <param name="args">Arguments to be used in formatting the message</param> public static void DoesNotThrowAsync(AsyncTestDelegate code, string message, params object[] args) { Assert.That(code, new ThrowsNothingConstraint(), message, args); }
/// <summary> /// Verifies that an async delegate throws a particular exception when called. /// </summary> /// <typeparam name="TActual">Type of the expected exception</typeparam> /// <param name="code">A TestDelegate</param> public static TActual ThrowsAsync <TActual>(AsyncTestDelegate code) where TActual : Exception { return(ThrowsAsync <TActual>(code, string.Empty, null)); }
/// <summary> /// Verifies that an async delegate does not throw an exception. /// </summary> /// <param name="code">A TestDelegate</param> public static void DoesNotThrowAsync(AsyncTestDelegate code) { DoesNotThrowAsync(code, string.Empty, null); }
/// <summary> /// Verifies that an async delegate throws an exception when called /// and returns it. /// </summary> /// <param name="code">A TestDelegate</param> public static Exception CatchAsync(AsyncTestDelegate code) { return(ThrowsAsync(new InstanceOfTypeConstraint(typeof(Exception)), code)); }
public void MockFile_WriteAllLinesAsyncGeneric_ShouldThrowAnArgumentNullExceptionIfContentsIsNull(AsyncTestDelegate action) { // Arrange // is done in the test case source // Act // is done in the test case sourceForContentsIsNull // Assert var exception = Assert.ThrowsAsync <ArgumentNullException>(action); Assert.That(exception.Message, Does.StartWith("Value cannot be null.")); Assert.That(exception.ParamName, Is.EqualTo("contents")); }