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";
}
[JsonProperty("id")]
public int SongId { get; }
[JsonProperty("id")] public int SongId { get; }
[JsonProperty("ids")]
public string SongIds { get; }
[JsonProperty("ids")] public string SongIds { get; }
}
}

View File

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

View File

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

View File

@ -1,4 +1,5 @@
using System.Threading.Tasks;
using ZonyLrcTools.Cli.Infrastructure.Lyric.QQMusic.JsonModel;
using ZonyLrcTools.Cli.Infrastructure.Network;
namespace ZonyLrcTools.Cli.Infrastructure.Lyric.QQMusic
@ -10,6 +11,8 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric.QQMusic
private readonly IWarpHttpClient _warpHttpClient;
private readonly ILyricItemCollectionFactory _lyricItemCollectionFactory;
private const string QQSearchMusicUrl = @"https://c.y.qq.com/soso/fcgi-bin/client_search_cp";
public QQLyricDownloader(IWarpHttpClient warpHttpClient,
ILyricItemCollectionFactory lyricItemCollectionFactory)
{
@ -17,8 +20,11 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric.QQMusic
_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();
}

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 ZonyLrcTools.Cli.Commands;
using ZonyLrcTools.Cli.Infrastructure.DependencyInject;
using ZonyLrcTools.Cli.Infrastructure.Extensions;
namespace ZonyLrcTools.Tests
{