-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
362 additions
and
347 deletions.
There are no files selected for viewing
88 changes: 43 additions & 45 deletions
88
ResourceMonitor/ResourceMonitor.Test/Aria2DownloaderTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,44 @@ | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using Castle.Core.Logging; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.Logging.Abstractions; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Moq; | ||
using ResourceMonitor.Services.Implementation; | ||
|
||
namespace ResourceMonitor.Test | ||
{ | ||
[TestClass] | ||
public class Aria2DownloaderTests | ||
{ | ||
IConfigurationRoot configuration = new ConfigurationBuilder() | ||
.AddInMemoryCollection(new Dictionary<string, string> | ||
{ | ||
{"Aria2:Url", "http://localhost:6800/jsonrpc"}, | ||
{"Aria2:Token", "token"} | ||
}) | ||
.Build(); | ||
|
||
[TestMethod] | ||
public async Task TryConnect() | ||
{ | ||
var mockFactory = new Mock<IHttpClientFactory>(); | ||
mockFactory.Setup(c => c.CreateClient()).Returns(new HttpClient()); | ||
var downloader = new Aria2Downloader(configuration, mockFactory.Object , new NullLogger<Aria2Downloader>()); | ||
var result = await downloader.TryConnect(); | ||
Assert.IsTrue(result); | ||
} | ||
|
||
[TestMethod] | ||
public async Task AddNewTorrentTask() | ||
{ | ||
var mockFactory = new Mock<IHttpClientFactory>(); | ||
mockFactory.Setup(c => c.CreateClient()).Returns(new HttpClient()); | ||
var downloader = new Aria2Downloader(configuration, mockFactory.Object, new NullLogger<Aria2Downloader>()); | ||
var torrentBytes = File.ReadAllBytes("valid.torrent"); | ||
await downloader.AddNewTorrentTask(torrentBytes); | ||
} | ||
} | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.Logging.Abstractions; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Moq; | ||
using ResourceMonitor.Services.Implementation; | ||
|
||
namespace ResourceMonitor.Test | ||
{ | ||
[TestClass] | ||
public class Aria2DownloaderTests | ||
{ | ||
IConfigurationRoot configuration = new ConfigurationBuilder() | ||
.AddInMemoryCollection(new Dictionary<string, string> | ||
{ | ||
{"Aria2:Url", "http://localhost:6800/jsonrpc"}, | ||
{"Aria2:Token", "token"} | ||
}) | ||
.Build(); | ||
|
||
[TestMethod] | ||
public async Task TryConnect() | ||
{ | ||
var mockFactory = new Mock<IHttpClientFactory>(); | ||
mockFactory.Setup(c => c.CreateClient()).Returns(new HttpClient()); | ||
var downloader = new Aria2Downloader(configuration, mockFactory.Object , new NullLogger<Aria2Downloader>()); | ||
var result = await downloader.TryConnect(); | ||
Assert.IsTrue(result); | ||
} | ||
|
||
[TestMethod] | ||
public async Task AddNewTorrentTask() | ||
{ | ||
var mockFactory = new Mock<IHttpClientFactory>(); | ||
mockFactory.Setup(c => c.CreateClient()).Returns(new HttpClient()); | ||
var downloader = new Aria2Downloader(configuration, mockFactory.Object, new NullLogger<Aria2Downloader>()); | ||
var torrentBytes = File.ReadAllBytes("valid.torrent"); | ||
await downloader.AddNewTorrentTask(torrentBytes); | ||
} | ||
} | ||
} |
61 changes: 32 additions & 29 deletions
61
ResourceMonitor/ResourceMonitor.Test/ResourceMonitor.Test.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,32 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="3.1.5" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" /> | ||
<PackageReference Include="Moq" Version="4.14.3" /> | ||
<PackageReference Include="MSTest.TestAdapter" Version="2.0.0" /> | ||
<PackageReference Include="MSTest.TestFramework" Version="2.0.0" /> | ||
<PackageReference Include="coverlet.collector" Version="1.0.1" /> | ||
<PackageReference Include="Refit" Version="5.1.67" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\ResourceMonitor\ResourceMonitor.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Update="valid.torrent"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
|
||
</Project> | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.1" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.1" /> | ||
<PackageReference Include="Moq" Version="4.18.2" /> | ||
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" /> | ||
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" /> | ||
<PackageReference Include="coverlet.collector" Version="3.1.2"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="Refit" Version="6.3.2" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\ResourceMonitor\ResourceMonitor.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Update="valid.torrent"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS runtime | ||
WORKDIR /app | ||
COPY . /app | ||
EXPOSE 80 | ||
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS runtime | ||
WORKDIR /app | ||
COPY . /app | ||
EXPOSE 80 | ||
ENTRYPOINT ["dotnet", "ResourceMonitor.dll"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,51 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.Extensions.Logging; | ||
using ResourceMonitor.Services; | ||
using Serilog; | ||
using Serilog.Events; | ||
|
||
namespace ResourceMonitor | ||
{ | ||
public class Program | ||
{ | ||
public static int Main(string[] args) | ||
{ | ||
Log.Logger = new LoggerConfiguration() | ||
.MinimumLevel.Debug() | ||
.MinimumLevel.Override("Microsoft", LogEventLevel.Information) | ||
.MinimumLevel.Override("Microsoft.AspNetCore", LogEventLevel.Warning) | ||
.Enrich.FromLogContext() | ||
.WriteTo.Console() | ||
.WriteTo.RollingFile(@"log/{Date}.txt") | ||
.CreateLogger(); | ||
|
||
try | ||
{ | ||
Log.Information("启动 ResMonitor..."); | ||
CreateHostBuilder(args).Build().Run(); | ||
return 0; | ||
} | ||
catch (Exception ex) | ||
{ | ||
Log.Fatal(ex, "ResMonitor 因意外情况终止"); | ||
return 1; | ||
} | ||
finally | ||
{ | ||
Log.CloseAndFlush(); | ||
} | ||
} | ||
|
||
public static IHostBuilder CreateHostBuilder(string[] args) => | ||
Host.CreateDefaultBuilder(args) | ||
.ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); }) | ||
.UseSerilog(); | ||
} | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.Extensions.Logging; | ||
using ResourceMonitor.Services; | ||
using Serilog; | ||
using Serilog.Events; | ||
|
||
namespace ResourceMonitor | ||
{ | ||
public class Program | ||
{ | ||
public static int Main(string[] args) | ||
{ | ||
Log.Logger = new LoggerConfiguration() | ||
.MinimumLevel.Debug() | ||
.MinimumLevel.Override("Microsoft", LogEventLevel.Information) | ||
.MinimumLevel.Override("Microsoft.AspNetCore", LogEventLevel.Warning) | ||
.Enrich.FromLogContext() | ||
.WriteTo.Console() | ||
.WriteTo.File(@"log/log-.txt", rollingInterval: RollingInterval.Day) | ||
.CreateLogger(); | ||
|
||
try | ||
{ | ||
Log.Information("启动 ResMonitor..."); | ||
CreateHostBuilder(args).Build().Run(); | ||
return 0; | ||
} | ||
catch (Exception ex) | ||
{ | ||
Log.Fatal(ex, "ResMonitor 因意外情况终止"); | ||
return 1; | ||
} | ||
finally | ||
{ | ||
Log.CloseAndFlush(); | ||
} | ||
} | ||
|
||
public static IHostBuilder CreateHostBuilder(string[] args) => | ||
Host.CreateDefaultBuilder(args) | ||
.ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); }) | ||
.UseSerilog(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,42 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
<Authors>kaedei</Authors> | ||
<Copyright>Copyright kaedei 2020-2021</Copyright> | ||
<PackageProjectUrl>https://github.com/kaedei/dandanplay-resmonitor</PackageProjectUrl> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.5" /> | ||
<PackageReference Include="OctoTorrent" Version="0.1.7" /> | ||
<PackageReference Include="Refit" Version="5.1.67" /> | ||
<PackageReference Include="Refit.HttpClientFactory" Version="5.1.67" /> | ||
<PackageReference Include="Serilog.AspNetCore" Version="3.2.0" /> | ||
<PackageReference Include="Serilog.Sinks.RollingFile" Version="3.3.0" /> | ||
<PackageReference Include="Transmission.API.RPC" Version="2.1.2" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Update="Dockerfile"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</None> | ||
<None Update=".dockerignore"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Content Update="appsettings.Development.json"> | ||
<ExcludeFromSingleFile>true</ExcludeFromSingleFile> | ||
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</Content> | ||
</ItemGroup> | ||
|
||
|
||
</Project> | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<Authors>kaedei</Authors> | ||
<Copyright>Copyright kaedei 2020-2021</Copyright> | ||
<PackageProjectUrl>https://github.com/kaedei/dandanplay-resmonitor</PackageProjectUrl> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.8" /> | ||
<PackageReference Include="MonoTorrent" Version="2.0.6" /> | ||
<PackageReference Include="Refit" Version="6.3.2" /> | ||
<PackageReference Include="Refit.HttpClientFactory" Version="6.3.2" /> | ||
<PackageReference Include="Serilog.AspNetCore" Version="6.0.1" /> | ||
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" /> | ||
<PackageReference Include="Transmission.API.RPC" Version="2.1.2" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Update="Dockerfile"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</None> | ||
<None Update=".dockerignore"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Content Update="appsettings.Development.json"> | ||
<ExcludeFromSingleFile>true</ExcludeFromSingleFile> | ||
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</Content> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Folder Include="log\" /> | ||
</ItemGroup> | ||
|
||
|
||
</Project> |
Oops, something went wrong.