feat: Reinitialize the Repository.

重新初始化仓库。
This commit is contained in:
Zony
2021-05-07 10:26:26 +08:00
parent a754f419b2
commit 8e1e61764c
78 changed files with 3329 additions and 22 deletions

View File

@@ -0,0 +1,31 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Shouldly;
using Xunit;
using ZonyLrcTools.Cli.Infrastructure.IO;
namespace ZonyLrcTools.Tests
{
public class FileScannerTests : TestBase
{
[Fact]
public async Task ScanAsync_Test()
{
var tempMusicFilePath = Path.Combine(Directory.GetCurrentDirectory(), "Temp.mp3");
File.Create(tempMusicFilePath);
var fileScanner = ServiceProvider.GetRequiredService<IFileScanner>();
var result = await fileScanner.ScanAsync(
Path.GetDirectoryName(tempMusicFilePath),
new[] {"*.mp3", "*.flac"});
result.Count.ShouldBe(2);
result.First(e => e.ExtensionName == ".mp3").FilePaths.Count.ShouldNotBe(0);
File.Delete(tempMusicFilePath);
}
}
}

View File

@@ -0,0 +1,34 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Shouldly;
using Xunit;
using ZonyLrcTools.Cli.Infrastructure.Album;
namespace ZonyLrcTools.Tests.Infrastructure.Album
{
public class NetEaseAlbumDownloaderTests : TestBase
{
[Fact]
public async Task DownloadDataAsync_Test()
{
var downloader = ServiceProvider.GetRequiredService<IEnumerable<IAlbumDownloader>>()
.FirstOrDefault(x => x.DownloaderName == InternalAlbumDownloaderNames.NetEase);
downloader.ShouldNotBeNull();
var albumBytes = await downloader.DownloadAsync("东方红", null);
albumBytes.Length.ShouldBeGreaterThan(0);
// 显示具体的图像。
var tempAlbumPath = Path.Combine(Directory.GetCurrentDirectory(), "tempAlbum.png");
File.Delete(tempAlbumPath);
await using var file = File.Create(tempAlbumPath);
await using var ws = new BinaryWriter(file);
ws.Write(albumBytes);
ws.Flush();
}
}
}

View File

@@ -0,0 +1,26 @@
using Shouldly;
using Xunit;
using ZonyLrcTools.Cli.Infrastructure.Exceptions;
namespace ZonyLrcTools.Tests.Infrastructure.Exceptions
{
public class ErrorCodeHelperTests : TestBase
{
[Fact]
public void LoadMessage_Test()
{
ErrorCodeHelper.LoadErrorMessage();
ErrorCodeHelper.ErrorMessages.ShouldNotBeNull();
ErrorCodeHelper.ErrorMessages.Count.ShouldBe(11);
}
[Fact]
public void GetMessage_Test()
{
ErrorCodeHelper.LoadErrorMessage();
ErrorCodeHelper.GetMessage(ErrorCodes.DirectoryNotExist).ShouldBe("需要扫描的目录不存在,请确认路径是否正确。");
}
}
}

View File

@@ -0,0 +1,25 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Shouldly;
using Xunit;
using ZonyLrcTools.Cli.Infrastructure.Lyric;
namespace ZonyLrcTools.Tests.Infrastructure.Lyric
{
public class NetEaseLyricDownloaderTests : TestBase
{
[Fact]
public async Task DownloadAsync_Test()
{
var downloaderList = ServiceProvider.GetRequiredService<IEnumerable<ILyricDownloader>>();
var netEaseDownloader = downloaderList.FirstOrDefault(t => t.DownloaderName == InternalLyricDownloaderNames.NetEase);
netEaseDownloader.ShouldNotBeNull();
var lyric = await netEaseDownloader.DownloadAsync("Hollow", "Janet Leon");
lyric.ShouldNotBeNull();
lyric.IsPruneMusic.ShouldBe(false);
}
}
}

View File

@@ -0,0 +1,48 @@
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Shouldly;
using Xunit;
using ZonyLrcTools.Cli.Config;
using ZonyLrcTools.Cli.Infrastructure.Network;
namespace ZonyLrcTools.Tests.Infrastructure.Network
{
public class WarpClientTests : TestBase
{
[Fact]
public async Task PostAsync_Test()
{
var client = ServiceProvider.GetRequiredService<IWarpHttpClient>();
var response = await client.PostAsync(@"https://www.baidu.com");
response.ShouldNotBeNull();
response.ShouldContain("百度");
}
[Fact]
public async Task GetAsync_Test()
{
var client = ServiceProvider.GetRequiredService<IWarpHttpClient>();
var response = await client.GetAsync(@"https://www.baidu.com");
response.ShouldNotBeNull();
response.ShouldContain("百度");
}
[Fact]
public async Task GetAsyncWithProxy_Test()
{
var option = ServiceProvider.GetRequiredService<IOptions<ToolOptions>>();
option.Value.NetworkOptions.ProxyIp = "127.0.0.1";
option.Value.NetworkOptions.ProxyPort = 4780;
var client = ServiceProvider.GetRequiredService<IWarpHttpClient>();
var response = await client.GetAsync(@"https://www.baidu.com");
response.ShouldNotBeNull();
response.ShouldContain("百度");
}
}
}

View File

@@ -0,0 +1,28 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Shouldly;
using Xunit;
using ZonyLrcTools.Cli.Infrastructure.Tag;
namespace ZonyLrcTools.Tests.Infrastructure.Tag
{
public class FileNameTagInfoProviderTests : TestBase
{
[Fact]
public async Task LoadAsync_Test()
{
var provider = ServiceProvider.GetRequiredService<IEnumerable<ITagInfoProvider>>()
.FirstOrDefault(p => p.Name == FileNameTagInfoProvider.ConstantName);
provider.ShouldNotBeNull();
var info = await provider.LoadAsync(Path.Combine(Directory.GetCurrentDirectory(), "MusicFiles", "曾经艺也 - 荀彧(纯音乐版).mp3"));
info.ShouldNotBeNull();
info.Name.ShouldBe("荀彧(纯音乐版)");
info.Artist.ShouldBe("曾经艺也");
}
}
}

View File

@@ -0,0 +1,24 @@
using System.IO;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Shouldly;
using Xunit;
using ZonyLrcTools.Cli.Infrastructure.Tag;
namespace ZonyLrcTools.Tests.Infrastructure.Tag
{
public class TagLoaderTests : TestBase
{
[Fact]
public async Task LoadTagAsync_Test()
{
var tagLoader = ServiceProvider.GetRequiredService<ITagLoader>();
tagLoader.ShouldNotBeNull();
var info = await tagLoader.LoadTagAsync(Path.Combine(Directory.GetCurrentDirectory(), "MusicFiles", "曾经艺也 - 荀彧(纯音乐版).mp3"));
info.ShouldNotBeNull();
info.Name.ShouldBe("荀彧(纯音乐版)");
info.Artist.ShouldBe("曾经艺也");
}
}
}

View File

@@ -0,0 +1,28 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Shouldly;
using Xunit;
using ZonyLrcTools.Cli.Infrastructure.Tag;
namespace ZonyLrcTools.Tests.Infrastructure.Tag
{
public class TaglibTagInfoProviderTests : TestBase
{
[Fact]
public async Task LoadAsync_Test()
{
var provider = ServiceProvider.GetRequiredService<IEnumerable<ITagInfoProvider>>()
.FirstOrDefault(p => p.Name == TaglibTagInfoProvider.ConstantName);
provider.ShouldNotBeNull();
var info = await provider.LoadAsync(Path.Combine(Directory.GetCurrentDirectory(), "MusicFiles", "曾经艺也 - 荀彧(纯音乐版).mp3"));
info.ShouldNotBeNull();
info.Name.ShouldBe("荀彧(纯音乐版)");
info.Artist.ShouldBe("曾经艺也");
}
}
}

View File

@@ -0,0 +1,33 @@
using System;
using Microsoft.Extensions.DependencyInjection;
using ZonyLrcTools.Cli.Commands;
using ZonyLrcTools.Cli.Infrastructure.DependencyInject;
using ZonyLrcTools.Cli.Infrastructure.Extensions;
namespace ZonyLrcTools.Tests
{
public class TestBase
{
protected IServiceProvider ServiceProvider { get; private set; }
protected IServiceCollection ServiceCollection { get; private set; }
public TestBase()
{
ServiceCollection = BuildService();
BuildServiceProvider();
}
protected virtual IServiceCollection BuildService()
{
var service = new ServiceCollection();
service.BeginAutoDependencyInject<ToolCommand>();
service.ConfigureToolService();
service.ConfigureConfiguration();
return service;
}
protected virtual void BuildServiceProvider() => ServiceProvider = ServiceCollection.BuildServiceProvider();
}
}

View File

@@ -0,0 +1,34 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
<PackageReference Include="Shouldly" Version="4.0.3" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="1.3.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\ZonyLrcTools.Cli\ZonyLrcTools.Cli.csproj" />
</ItemGroup>
<ItemGroup>
<None Remove="MusicFiles\曾经艺也 - 荀彧(纯音乐版).mp3" />
<Content Include="MusicFiles\曾经艺也 - 荀彧(纯音乐版).mp3">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>