diff --git a/src/BirdMessenger.Test/HttpClientExtensionTest.cs b/src/BirdMessenger.Test/HttpClientExtensionTest.cs index f88e251..75617f6 100644 --- a/src/BirdMessenger.Test/HttpClientExtensionTest.cs +++ b/src/BirdMessenger.Test/HttpClientExtensionTest.cs @@ -19,67 +19,12 @@ public HttpClientExtensionTest(ITestOutputHelper testOutputHelper) { _testOutputHelper = testOutputHelper; } - - [Fact] - public async Task TestTusCreateAndDelAsync() - { - bool isInovkeOnPreSendRequestAsync = false; - using var httpClient = new HttpClient(); - - MetadataCollection dir = new MetadataCollection(); - dir["filename"] = "fileNameTest"; - TusCreateRequestOption tusCreateRequestOption = new TusCreateRequestOption() - { - Endpoint = TusEndpoint, - UploadLength = 1000, - Metadata = dir, - OnPreSendRequestAsync = x => - { - _testOutputHelper.WriteLine("OnPreSendRequestAsync is invoked"); - isInovkeOnPreSendRequestAsync = true; - return Task.CompletedTask; - } - }; - var resp = await httpClient.TusCreateAsync(tusCreateRequestOption, CancellationToken.None); - Assert.Equal(TusVersion.V1_0_0, resp.TusResumableVersion); - Assert.True(isInovkeOnPreSendRequestAsync); - - TusDeleteRequestOption tusDeleteRequestOption = new TusDeleteRequestOption() - { - FileLocation = resp.FileLocation - }; - - var delResp = await httpClient.TusDeleteAsync(tusDeleteRequestOption, CancellationToken.None); - Assert.Equal(TusVersion.V1_0_0, delResp.TusResumableVersion); - } - - [Fact] - public async Task TestTusCreateArgumentExceptionAsync() - { - bool isArgumentException = false; - try - { - using var httpClient = new HttpClient(); - TusCreateRequestOption tusCreateRequestOption = new TusCreateRequestOption() - { - Endpoint = TusEndpoint, - UploadLength = 1000, - IsUploadDeferLength = true - }; - var resp = await httpClient.TusCreateAsync(tusCreateRequestOption, CancellationToken.None); - } - catch (ArgumentException) - { - isArgumentException = true; - } - - Assert.True(isArgumentException); - } + [Theory] [InlineData(1000)] [InlineData(50)] - [InlineData(-1)] + [InlineData(1)] [InlineData(0)] public async Task TestTusHeadAsync(long uploadLength) { diff --git a/src/BirdMessenger.Test/TusCreateTest.cs b/src/BirdMessenger.Test/TusCreateTest.cs new file mode 100644 index 0000000..314f4fb --- /dev/null +++ b/src/BirdMessenger.Test/TusCreateTest.cs @@ -0,0 +1,128 @@ +using System; +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; +using BirdMessenger.Collections; +using Xunit; +using Xunit.Abstractions; + +namespace BirdMessenger.Test; + +public class TusCreateTest +{ + private readonly ITestOutputHelper _testOutputHelper; + public static Uri TusEndpoint = new Uri("http://localhost:5094/files"); + + public TusCreateTest(ITestOutputHelper testOutputHelper) + { + _testOutputHelper = testOutputHelper; + } + + [Fact] + public async Task CreateZoreSizeFile() + { + bool isInovkeOnPreSendRequestAsync = false; + + using var httpClient = new HttpClient(); + + MetadataCollection dir = new MetadataCollection(); + dir["filename"] = "fileNameTest"; + TusCreateRequestOption tusCreateRequestOption = new TusCreateRequestOption() + { + Endpoint = TusEndpoint, + UploadLength = 0, + Metadata = dir, + OnPreSendRequestAsync = x => + { + _testOutputHelper.WriteLine("OnPreSendRequestAsync is invoked"); + isInovkeOnPreSendRequestAsync = true; + return Task.CompletedTask; + } + }; + var resp = await httpClient.TusCreateAsync(tusCreateRequestOption, CancellationToken.None); + Assert.Equal(TusVersion.V1_0_0, resp.TusResumableVersion); + Assert.True(isInovkeOnPreSendRequestAsync); + } + [Fact] + public async Task CreateWithIsUploadDeferLength() + { + bool isInovkeOnPreSendRequestAsync = false; + + using var httpClient = new HttpClient(); + + MetadataCollection dir = new MetadataCollection(); + dir["filename"] = "fileNameTest"; + TusCreateRequestOption tusCreateRequestOption = new TusCreateRequestOption() + { + Endpoint = TusEndpoint, + UploadLength = 0, + IsUploadDeferLength = true, + Metadata = dir, + OnPreSendRequestAsync = x => + { + _testOutputHelper.WriteLine("OnPreSendRequestAsync is invoked"); + isInovkeOnPreSendRequestAsync = true; + return Task.CompletedTask; + } + }; + var resp = await httpClient.TusCreateAsync(tusCreateRequestOption, CancellationToken.None); + Assert.Equal(TusVersion.V1_0_0, resp.TusResumableVersion); + Assert.True(isInovkeOnPreSendRequestAsync); + } + [Fact] + public async Task TestTusCreateAndDelAsync() + { + bool isInovkeOnPreSendRequestAsync = false; + using var httpClient = new HttpClient(); + + MetadataCollection dir = new MetadataCollection(); + dir["filename"] = "fileNameTest"; + TusCreateRequestOption tusCreateRequestOption = new TusCreateRequestOption() + { + Endpoint = TusEndpoint, + UploadLength = 1000, + Metadata = dir, + OnPreSendRequestAsync = x => + { + _testOutputHelper.WriteLine("OnPreSendRequestAsync is invoked"); + isInovkeOnPreSendRequestAsync = true; + return Task.CompletedTask; + } + }; + var resp = await httpClient.TusCreateAsync(tusCreateRequestOption, CancellationToken.None); + Assert.Equal(TusVersion.V1_0_0, resp.TusResumableVersion); + Assert.True(isInovkeOnPreSendRequestAsync); + + TusDeleteRequestOption tusDeleteRequestOption = new TusDeleteRequestOption() + { + FileLocation = resp.FileLocation + }; + + var delResp = await httpClient.TusDeleteAsync(tusDeleteRequestOption, CancellationToken.None); + Assert.Equal(TusVersion.V1_0_0, delResp.TusResumableVersion); + } + + [Fact] + public async Task TestTusCreateArgumentExceptionAsync() + { + bool isArgumentException = false; + try + { + using var httpClient = new HttpClient(); + TusCreateRequestOption tusCreateRequestOption = new TusCreateRequestOption() + { + Endpoint = TusEndpoint, + UploadLength = 1000, + IsUploadDeferLength = true + }; + var resp = await httpClient.TusCreateAsync(tusCreateRequestOption, CancellationToken.None); + } + catch (ArgumentException) + { + isArgumentException = true; + } + + Assert.True(isArgumentException); + } + +} \ No newline at end of file