public async Task AnalyzeAsyncErrorTest() { IEnumerable <Task> testTasks = ChineseTests.OtherCharacters.Select(async item => { EtymologyController controller = CreateController(); try { controller.ControllerContext.HttpContext.Request.Headers.Add(nameof(Chinese), new StringValues(char.ConvertToUtf32(item, 0).ToString("D"))); } catch (Exception exception) { Trace.WriteLine(exception); } Trace.WriteLine(item); #if DEBUG BadRequestObjectResult badRequest = await controller.AnalyzeAsync(item) as BadRequestObjectResult; #else BadRequestResult badRequest = await controller.AnalyzeAsync(item) as BadRequestResult; #endif Assert.IsNotNull(badRequest); #if DEBUG Assert.IsInstanceOfType(badRequest.Value, typeof(ArgumentException)); #endif Assert.AreEqual((int)HttpStatusCode.BadRequest, badRequest.StatusCode); }); await Task.WhenAll(testTasks); }
public async Task AnalyzeAsyncTest() { IEnumerable <Task> testTasks = ChineseTests.ChineseCharacters.Select(async item => { EtymologyController controller = CreateController(); controller.ControllerContext.HttpContext.Request.Headers.Add(nameof(Chinese), new StringValues(char.ConvertToUtf32(item.Text, 0).ToString("D"))); ViewResult view; try { view = await controller.AnalyzeAsync(item.Text) as ViewResult; } catch (Exception exception) { Trace.WriteLine(exception); throw; } Assert.IsNotNull(view); Assert.IsInstanceOfType(view.Model, typeof((string, TimeSpan, AnalyzeResult[]))); var(chinese, duration, results) = ((string, TimeSpan, AnalyzeResult[]))view.Model; Assert.AreEqual(item.Text, chinese); Assert.IsTrue(duration > TimeSpan.Zero); Assert.IsNotNull(results); }); await Task.WhenAll(testTasks); }