test: Add QQ Music Lyric Downloader UnitTest Method.

This commit is contained in:
real-zony 2021-05-08 18:30:53 +08:00
parent abdb1dea23
commit 8f70e434f0
11 changed files with 49 additions and 27 deletions

View File

@ -10,10 +10,8 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric.NetEase.JsonModel
SongIds = $"%5B{songId}%5D"; SongIds = $"%5B{songId}%5D";
} }
[JsonProperty("id")] [JsonProperty("id")] public int SongId { get; }
public int SongId { get; }
[JsonProperty("ids")] [JsonProperty("ids")] public string SongIds { get; }
public string SongIds { get; }
} }
} }

View File

@ -48,7 +48,7 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric.QQMusic.JsonModel
[JsonProperty("needNewCode")] public int UnknownParameter11 { get; set; } [JsonProperty("needNewCode")] public int UnknownParameter11 { get; set; }
public SongSearchRequest() protected SongSearchRequest()
{ {
UnknownParameter1 = 24; UnknownParameter1 = 24;
ClientVersion = 1298; ClientVersion = 1298;

View File

@ -5,34 +5,28 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric.QQMusic.JsonModel
{ {
public class SongSearchResponse public class SongSearchResponse
{ {
[JsonProperty("code")] [JsonProperty("code")] public int StatusCode { get; set; }
public int StatusCode { get; set; }
[JsonProperty("data")] [JsonProperty("data")] public QQMusicInnerDataModel Data { get; set; }
public QQMusicInnerDataModel Data { get; set; }
} }
public class QQMusicInnerDataModel public class QQMusicInnerDataModel
{ {
[JsonProperty("song")] [JsonProperty("song")] public QQMusicInnerSongModel Song { get; set; }
public QQMusicInnerSongModel Song { get; set; }
} }
public class QQMusicInnerSongModel public class QQMusicInnerSongModel
{ {
[JsonProperty("list")] [JsonProperty("list")] public List<QQMusicInnerSongItem> SongItems { get; set; }
public List<QQMusicInnerSongItem> SongItems { get; set; }
} }
public class QQMusicInnerSongItem public class QQMusicInnerSongItem
{ {
[JsonProperty("mid")] [JsonProperty("mid")] public string SongId { get; set; }
public string SongId { get; set; }
} }
public class AlbumInfo public class AlbumInfo
{ {
[JsonProperty("id")] [JsonProperty("id")] public long Id { get; set; }
public long Id { get; set; }
} }
} }

View File

@ -1,4 +1,5 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using ZonyLrcTools.Cli.Infrastructure.Lyric.QQMusic.JsonModel;
using ZonyLrcTools.Cli.Infrastructure.Network; using ZonyLrcTools.Cli.Infrastructure.Network;
namespace ZonyLrcTools.Cli.Infrastructure.Lyric.QQMusic namespace ZonyLrcTools.Cli.Infrastructure.Lyric.QQMusic
@ -10,6 +11,8 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric.QQMusic
private readonly IWarpHttpClient _warpHttpClient; private readonly IWarpHttpClient _warpHttpClient;
private readonly ILyricItemCollectionFactory _lyricItemCollectionFactory; private readonly ILyricItemCollectionFactory _lyricItemCollectionFactory;
private const string QQSearchMusicUrl = @"https://c.y.qq.com/soso/fcgi-bin/client_search_cp";
public QQLyricDownloader(IWarpHttpClient warpHttpClient, public QQLyricDownloader(IWarpHttpClient warpHttpClient,
ILyricItemCollectionFactory lyricItemCollectionFactory) ILyricItemCollectionFactory lyricItemCollectionFactory)
{ {
@ -17,8 +20,11 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric.QQMusic
_lyricItemCollectionFactory = lyricItemCollectionFactory; _lyricItemCollectionFactory = lyricItemCollectionFactory;
} }
protected override ValueTask<byte[]> DownloadDataAsync(LyricDownloaderArgs args) protected override async ValueTask<byte[]> DownloadDataAsync(LyricDownloaderArgs args)
{ {
var searchResult = await _warpHttpClient.PostAsync<SongSearchResponse>(
QQSearchMusicUrl,
new SongSearchRequest(args.SongName, args.Artist));
throw new System.NotImplementedException(); throw new System.NotImplementedException();
} }

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 QQLyricDownloaderTests : TestBase
{
[Fact]
public async Task DownloadAsync_Test()
{
var downloaderList = ServiceProvider.GetRequiredService<IEnumerable<ILyricDownloader>>();
var qqDownloader = downloaderList.FirstOrDefault(t => t.DownloaderName == InternalLyricDownloaderNames.QQ);
qqDownloader.ShouldNotBeNull();
var lyric = await qqDownloader.DownloadAsync("Hollow", "Janet Leon");
lyric.ShouldNotBeNull();
lyric.IsPruneMusic.ShouldBe(false);
}
}
}

View File

@ -2,7 +2,6 @@ using System;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using ZonyLrcTools.Cli.Commands; using ZonyLrcTools.Cli.Commands;
using ZonyLrcTools.Cli.Infrastructure.DependencyInject; using ZonyLrcTools.Cli.Infrastructure.DependencyInject;
using ZonyLrcTools.Cli.Infrastructure.Extensions;
namespace ZonyLrcTools.Tests namespace ZonyLrcTools.Tests
{ {