1
0
mirror of https://github.com/ZetaKebab/MpcNET.git synced 2024-09-16 05:30:09 +00:00

Test porject created + initial structure

This commit is contained in:
glucaci 2016-12-13 10:47:06 +01:00
parent ec24b3f01a
commit f3d4de7d3b
27 changed files with 279 additions and 1 deletions

5
.gitignore vendored
View File

@ -14,4 +14,9 @@
/LibMpcApp/LibMpcApp.xproj.user
/LibMpcApp/project.lock.json
/LibMpcTest/bin
/LibMpcTest/obj
/LibMpcTest/LibMpcTest.xproj.user
/LibMpcTest/project.lock.json
/LibMpc.sln.DotSettings.user

View File

@ -7,6 +7,8 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "LibMpc", "LibMpc\LibMpc.xpr
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "LibMpcApp", "LibMpcApp\LibMpcApp.xproj", "{FF176AD5-D6DA-41EE-B27D-1DBEF0CE462F}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "LibMpcTest", "LibMpcTest\LibMpcTest.xproj", "{69F1D68F-9CD5-4EA6-9B47-2A7A9BF8CED9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -21,6 +23,10 @@ Global
{FF176AD5-D6DA-41EE-B27D-1DBEF0CE462F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FF176AD5-D6DA-41EE-B27D-1DBEF0CE462F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FF176AD5-D6DA-41EE-B27D-1DBEF0CE462F}.Release|Any CPU.Build.0 = Release|Any CPU
{69F1D68F-9CD5-4EA6-9B47-2A7A9BF8CED9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{69F1D68F-9CD5-4EA6-9B47-2A7A9BF8CED9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{69F1D68F-9CD5-4EA6-9B47-2A7A9BF8CED9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{69F1D68F-9CD5-4EA6-9B47-2A7A9BF8CED9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

40
LibMpcTest/LibMpcTest.cs Normal file
View File

@ -0,0 +1,40 @@
using LibMpc;
using System;
using System.IO;
using System.Net;
using System.Reflection;
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;
namespace LibMpcTest
{
public class LibMpcTest : IClassFixture<MpdServerTest>, IDisposable
{
private readonly ITestOutputHelper _output;
private readonly Mpc _mpc;
public LibMpcTest(ITestOutputHelper output)
{
_output = output;
_mpc = new Mpc(new IPEndPoint(IPAddress.Loopback, 6600));
var connected = _mpc.ConnectAsync().GetAwaiter().GetResult();
if (connected)
{
_output.WriteLine("Connected to MPD.");
}
else
{
_output.WriteLine("Could not connect to MPD.");
}
_mpc.SendAsync(new Commands.Database.Update()).GetAwaiter().GetResult();
}
public void Dispose()
{
_mpc?.DisconnectAsync().GetAwaiter().GetResult();
}
}
}

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>69f1d68f-9cd5-4ea6-9b47-2a7a9bf8ced9</ProjectGuid>
<RootNamespace>LibMpcTest</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>

40
LibMpcTest/MpdConf.cs Normal file
View File

@ -0,0 +1,40 @@
using System.IO;
using System.Text;
namespace LibMpcTest
{
public class MpdConf
{
private const string MPD_CONF_FILE = "mpd.conf";
private const string MPD_LOG_FILE = "mpd_log.txt";
private const string MPD_DB_FILE = "mpd.db";
public static void Create(string rootDirectory)
{
File.Create(Path.Combine(rootDirectory, MPD_LOG_FILE)).Dispose();
CreateConfFile(rootDirectory);
}
private static void CreateConfFile(string rootDirectory)
{
var builder = new StringBuilder();
builder.AppendLine($"log_file \"{Path.Combine(rootDirectory, MPD_LOG_FILE).Replace("\\", "\\\\")}\"");
builder.AppendLine($"db_file \"{Path.Combine(rootDirectory, MPD_DB_FILE).Replace("\\", "\\\\")}\"");
builder.AppendLine($"bind_to_address \"any\"");
builder.AppendLine($"music_directory \"{Path.Combine(rootDirectory, "Music").Replace("\\", "\\\\")}\"");
builder.AppendLine($"playlist_directory \"{Path.Combine(rootDirectory, "Playlists").Replace("\\", "\\\\")}\"");
builder.AppendLine($"port \"6600\"");
builder.AppendLine($"mixer_type \"software\"");
var mpdConfContent = builder.ToString();
using (var file = File.CreateText(Path.Combine(rootDirectory, MPD_CONF_FILE)))
{
file.Write(mpdConfContent);
file.Flush();
}
}
}
}

View File

@ -0,0 +1,46 @@
using System;
using System.Diagnostics;
using System.IO;
namespace LibMpcTest
{
internal class MpdServerTest : IDisposable
{
private Process _process;
public MpdServerTest()
{
var serverPath = Path.Combine(AppContext.BaseDirectory, "Server");
MpdConf.Create(serverPath);
var mpdExePath = Path.Combine(serverPath, "mpd.exe");
var mpdConfPath = Path.Combine(serverPath, "mpd.conf");
_process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = mpdExePath,
WorkingDirectory = serverPath,
Arguments = string.Join(" ", mpdConfPath, "-v"),
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true,
}
};
_process.Start();
var logOutput = _process.StandardOutput.ReadToEnd();
var logError = _process.StandardError.ReadToEnd();
}
public void Dispose()
{
_process?.Kill();
_process?.Dispose();
_process = null;
}
}
}

View File

@ -0,0 +1,19 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LibMpcTest")]
[assembly: AssemblyTrademark("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("69f1d68f-9cd5-4ea6-9b47-2a7a9bf8ced9")]

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

68
LibMpcTest/Server/mpd.db Normal file
View File

@ -0,0 +1,68 @@
info_begin
format: 1
mpd_version: 0.17.4
fs_charset: cp1252
tag: Artist
tag: ArtistSort
tag: Album
tag: AlbumArtist
tag: AlbumArtistSort
tag: Title
tag: Track
tag: Name
tag: Genre
tag: Date
tag: Composer
tag: Performer
tag: Disc
tag: MUSICBRAINZ_ARTISTID
tag: MUSICBRAINZ_ALBUMID
tag: MUSICBRAINZ_ALBUMARTISTID
tag: MUSICBRAINZ_TRACKID
info_end
directory: Dir1
mtime: 1481580300
begin: Dir1
song_begin: piano2-Audacity1.2.5.mp3
Time: 6
Artist: piano2
Genre: Blues
mtime: 1481120569
song_end
end: Dir1
directory: Dir2
mtime: 1481580300
begin: Dir2
song_begin: c304-2.wav
Time: 49
mtime: 1481109933
song_end
song_begin: 32.mp3
Time: 32
Artist: organ
Album: Test 2
Date: 1995
Genre: Rock
mtime: 1481123918
song_end
end: Dir2
directory: Dir3
mtime: 1481580300
begin: Dir3
song_begin: piano2-Audacity1.2.5 (1).mp3
Time: 6
Artist: piano2
Genre: Blues
mtime: 1481120554
song_end
end: Dir3
song_begin: organfinale.mp3
Time: 13
Artist: organ
mtime: 1481120544
song_end
song_begin: piano2-CoolEdit.mp3
Time: 6
Artist: piano2
mtime: 1481120536
song_end

BIN
LibMpcTest/Server/mpd.exe Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

32
LibMpcTest/project.json Normal file
View File

@ -0,0 +1,32 @@
{
"buildOptions":
{
"copyToOutput": "Server\\"
},
"version": "1.0.0-*",
"testRunner": "xunit",
"dependencies":
{
"xunit": "2.2.0-beta2-build3300",
"LibMpc": "1.0.0-*",
"dotnet-test-xunit": "2.2.0-preview2-build1029"
},
"frameworks":
{
"netcoreapp1.0":
{
"dependencies":
{
"Microsoft.NETCore.App":
{
"type": "platform",
"version": "1.0.0"
}
}
}
}
}