mirror of
https://github.com/mxpv/podsync.git
synced 2024-05-11 05:55:04 +00:00
Implement create feed backend API
This commit is contained in:
55
test/Podsync.Tests/Controllers/FeedControllerTests.cs
Normal file
55
test/Podsync.Tests/Controllers/FeedControllerTests.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Podsync.Services;
|
||||
using Podsync.Services.Resolver;
|
||||
using Xunit;
|
||||
|
||||
namespace Podsync.Tests.Controllers
|
||||
{
|
||||
public class FeedControllerTests : TestServer<Startup>
|
||||
{
|
||||
[Fact]
|
||||
public async Task ValidateCreateNullTest()
|
||||
{
|
||||
var response = await Client.PostAsync("/feed/create", new StringContent("", Encoding.UTF8, "application/json"));
|
||||
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(null, null, null)]
|
||||
[InlineData("a", null, null)]
|
||||
[InlineData("http://youtube.com", null, 0)]
|
||||
[InlineData("http://youtube.com", null, 25)]
|
||||
[InlineData("http://youtube.com", null, 151)]
|
||||
public async Task ValidateCreateTest(string url, ResolveType? quality, int? pageSize)
|
||||
{
|
||||
var feed = new CreateFeedRequest
|
||||
{
|
||||
Url = url,
|
||||
Quality = quality,
|
||||
PageSize = pageSize
|
||||
};
|
||||
|
||||
var response = await Client.PostAsync("/feed/create", MakeHttpContent(feed));
|
||||
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CreateFeedTest()
|
||||
{
|
||||
var feed = new CreateFeedRequest
|
||||
{
|
||||
Url = "https://www.youtube.com/channel/UCKy1dAqELo0zrOtPkf0eTMw",
|
||||
Quality = ResolveType.AudioLow,
|
||||
};
|
||||
|
||||
var response = await Client.PostAsync("/feed/create", MakeHttpContent(feed));
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
|
||||
var id = await response.Content.ReadAsStringAsync();
|
||||
Assert.NotNull(id);
|
||||
}
|
||||
}
|
||||
}
|
17
test/Podsync.Tests/Controllers/StatusControllerTests.cs
Normal file
17
test/Podsync.Tests/Controllers/StatusControllerTests.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
namespace Podsync.Tests.Controllers
|
||||
{
|
||||
public class StatusControllerTests : TestServer<Startup>
|
||||
{
|
||||
[Fact]
|
||||
public async Task StatusTest()
|
||||
{
|
||||
var response = await Client.GetAsync("/status");
|
||||
var content = await response.Content.ReadAsStringAsync();
|
||||
|
||||
Assert.Contains("Path: /status", content);
|
||||
}
|
||||
}
|
||||
}
|
37
test/Podsync.Tests/Controllers/TestServer.cs
Normal file
37
test/Podsync.Tests/Controllers/TestServer.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.TestHost;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Podsync.Tests.Controllers
|
||||
{
|
||||
public abstract class TestServer<TStartup> : TestBase, IDisposable where TStartup : class
|
||||
{
|
||||
private readonly TestServer _server;
|
||||
|
||||
protected TestServer()
|
||||
{
|
||||
var builder = new WebHostBuilder().UseStartup<TStartup>();
|
||||
_server = new TestServer(builder);
|
||||
|
||||
Client = _server.CreateClient();
|
||||
Client.BaseAddress = new Uri("http://localhost:5000");
|
||||
}
|
||||
|
||||
protected HttpClient Client { get; }
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Client.Dispose();
|
||||
_server.Dispose();
|
||||
}
|
||||
|
||||
public static HttpContent MakeHttpContent(object obj)
|
||||
{
|
||||
var json = JsonConvert.SerializeObject(obj);
|
||||
return new StringContent(json, Encoding.UTF8, "application/json");
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,27 +1,36 @@
|
||||
{
|
||||
"version": "1.0.0-*",
|
||||
"testRunner": "xunit",
|
||||
"version": "1.0.0-*",
|
||||
"testRunner": "xunit",
|
||||
|
||||
"dependencies": {
|
||||
"dotnet-test-xunit": "2.2.0-preview2-build1029",
|
||||
"Microsoft.Extensions.Configuration.UserSecrets": "1.0.0",
|
||||
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
|
||||
"Microsoft.NETCore.App": {
|
||||
"version": "1.0.0",
|
||||
"type": "platform"
|
||||
},
|
||||
"Moq": "4.6.38-alpha",
|
||||
"Podsync": "1.0.0-*",
|
||||
"System.Xml.XmlSerializer": "4.0.11",
|
||||
"xunit": "2.2.0-beta2-build3300"
|
||||
"dependencies": {
|
||||
"dotnet-test-xunit": "2.2.0-preview2-build1029",
|
||||
"Microsoft.AspNetCore.TestHost": "1.0.1",
|
||||
"Microsoft.Extensions.Configuration.UserSecrets": "1.0.0",
|
||||
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
|
||||
"Microsoft.NETCore.App": {
|
||||
"version": "1.0.0",
|
||||
"type": "platform"
|
||||
},
|
||||
"Moq": "4.6.38-alpha",
|
||||
"Podsync": "1.0.0-*",
|
||||
"System.Xml.XmlSerializer": "4.0.11",
|
||||
"xunit": "2.2.0-beta2-build3300"
|
||||
},
|
||||
|
||||
"frameworks": {
|
||||
"netcoreapp1.0": {
|
||||
"imports": [
|
||||
"dotnet5.6",
|
||||
"portable-net45+win8"
|
||||
]
|
||||
}
|
||||
"frameworks": {
|
||||
"netcoreapp1.0": {
|
||||
"imports": [
|
||||
"dotnet5.6",
|
||||
"portable-net45+win8"
|
||||
]
|
||||
}
|
||||
},
|
||||
|
||||
"buildOptions": {
|
||||
"copyToOutput": [
|
||||
"project.json"
|
||||
]
|
||||
},
|
||||
|
||||
"userSecretsId": "aspnet-Podsync-20161004104901"
|
||||
}
|
||||
|
Reference in New Issue
Block a user