コード例 #1
0
        public async Task ArgumentException()
        {
            // prepare
            var invalid = new InvalidStream();
            var md      = new MimeDetector();

            // act && verify
            await Assert.ThrowsAsync <ArgumentException>(() => md.DetectAsync(invalid));
        }
コード例 #2
0
        public async Task IgnoreResponse_Test()
        {
            using var bodyStream = new InvalidStream();
            using var response   = new HttpResponseMessage();

            // IgnoreResponse() によってレスポンスの Stream が読まれずに破棄されることをテストするため、
            // 読み込みが行われると IOException が発生する InvalidStream クラスを bodyStream に使用している
            response.Content = new StreamContent(bodyStream);

            using var lazyJson = new LazyJson <string>(response);

            // レスポンスボディを読まずに破棄
            await Task.FromResult(lazyJson)
            .IgnoreResponse()
            .ConfigureAwait(false);

            Assert.True(bodyStream.IsDisposed);
        }
コード例 #3
0
ファイル: LazyJsonTest.cs プロジェクト: opentween/OpenTween
        public async Task IgnoreResponse_Test()
        {
            using (var bodyStream = new InvalidStream())
            using (var response = new HttpResponseMessage())
            {
                // IgnoreResponse() によってレスポンスの Stream が読まれずに破棄されることをテストするため、
                // 読み込みが行われると IOException が発生する InvalidStream クラスを bodyStream に使用している
                response.Content = new StreamContent(bodyStream);

                using (var lazyJson = new LazyJson<string>(response))
                {
                    // レスポンスボディを読まずに破棄
                    await Task.FromResult(lazyJson)
                        .IgnoreResponse()
                        .ConfigureAwait(false);

                    Assert.True(bodyStream.IsDisposed);
                }
            }
        }