forked from FubarDevelopment/FtpServer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIntegrationTests.cs
105 lines (92 loc) · 3.06 KB
/
IntegrationTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// <copyright file="IntegrationTests.cs" company="Fubar Development Junker">
// Copyright (c) Fubar Development Junker. All rights reserved.
// </copyright>
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using FluentFTP;
using Xunit;
using Xunit.Abstractions;
namespace FubarDev.FtpServer.Tests
{
public class IntegrationTests : FtpServerTestsBase
{
private IFtpClient? _client;
public IntegrationTests(ITestOutputHelper testOutputHelper)
: base(testOutputHelper)
{
}
public IFtpClient Client => _client ?? throw new InvalidOperationException();
/// <inheritdoc />
public override async Task InitializeAsync()
{
await base.InitializeAsync();
_client = new FtpClient("127.0.0.1", Server.Port, "anonymous", "test@test.net");
await _client.ConnectAsync();
}
/// <inheritdoc />
public override async Task DisposeAsync()
{
if (_client != null)
{
await _client.DisconnectAsync();
}
await base.DisposeAsync();
}
/// <summary>
/// Upload a test file.
/// </summary>
/// <param name="fileName">The name of the file to write.</param>
/// <returns>The task.</returns>
[Theory]
[InlineData("设备管理-摄像机管理-w.txt")]
public async Task TestUtf8FileNamesForUploadAsync(string fileName)
{
await Client.UploadAsync(
Encoding.UTF8.GetBytes("Hello, this is a test!"),
fileName);
var fileNames = await Client.GetNameListingAsync();
Assert.NotNull(fileNames);
Assert.Collection(
fileNames,
item =>
{
Debug.WriteLine(item.Length);
Debug.WriteLine(item);
Debug.WriteLine(char.ConvertToUtf32(item, 0));
Assert.Equal(".", item);
},
item => Assert.Equal(fileName, item));
}
/// <summary>
/// Upload a test file.
/// </summary>
/// <returns>The task.</returns>
[Fact]
public async Task TestUploadAsync()
{
await Client.UploadAsync(
Encoding.UTF8.GetBytes("Hello, this is a test!"),
"test.txt");
}
/// <summary>
/// Upload and download test file.
/// </summary>
/// <returns>The task.</returns>
[Fact]
public async Task TestUploadAndDownloadAsync()
{
await Client.UploadAsync(
Encoding.UTF8.GetBytes("Hello, this is a test!"),
"test.txt");
var temp = new MemoryStream();
await Client.DownloadAsync(
temp,
"test.txt");
var readData = Encoding.UTF8.GetString(temp.ToArray());
Assert.Equal("Hello, this is a test!", readData);
}
}
}