Skip to content

Commit

Permalink
Merge branch '3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Krusen committed Oct 13, 2019
2 parents 867e120 + f82571c commit ba016f1
Show file tree
Hide file tree
Showing 57 changed files with 3,982 additions and 1,925 deletions.
18 changes: 9 additions & 9 deletions BencodeNET.Tests/BencodeNET.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net452</TargetFramework>
<TargetFrameworks>net472;netcoreapp2.0;netcoreapp2.2;netcoreapp3.0</TargetFrameworks>
<LangVersion>7.3</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand All @@ -14,15 +15,14 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="AutoFixture" Version="4.8.0" />
<PackageReference Include="AutoFixture.AutoNSubstitute" Version="4.8.0" />
<PackageReference Include="AutoFixture.Xunit2" Version="4.8.0" />
<PackageReference Include="FluentAssertions" Version="5.6.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="NSubstitute" Version="4.0.0" />
<PackageReference Include="AutoFixture" Version="4.11.0" />
<PackageReference Include="AutoFixture.AutoNSubstitute" Version="4.11.0" />
<PackageReference Include="AutoFixture.Xunit2" Version="4.11.0" />
<PackageReference Include="FluentAssertions" Version="5.9.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
<PackageReference Include="NSubstitute" Version="4.2.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.0-beta4-build3742" />
</ItemGroup>

</Project>
53 changes: 52 additions & 1 deletion BencodeNET.Tests/Extensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
using System.IO;
using System;
using System.IO;
using System.IO.Pipelines;
using System.Text;
using System.Threading.Tasks;
using BencodeNET.IO;
using BencodeNET.Objects;
using BencodeNET.Parsing;
using NSubstitute.Core;

namespace BencodeNET.Tests
{
Expand All @@ -18,5 +25,49 @@ internal static string AsString(this Stream stream, Encoding encoding)
var sr = new StreamReader(stream, encoding);
return sr.ReadToEnd();
}

internal static void SkipBytes(this BencodeReader reader, int length)
{
reader.Read(new byte[length]);
}

internal static Task SkipBytesAsync(this PipeBencodeReader reader, int length)
{
return reader.ReadAsync(new byte[length]).AsTask();
}

internal static ConfiguredCall AndSkipsAhead(this ConfiguredCall call, int length)
{
return call.AndDoes(x => x.Arg<BencodeReader>().SkipBytes(length));
}

internal static ConfiguredCall AndSkipsAheadAsync(this ConfiguredCall call, int length)
{
return call.AndDoes(async x => await x.Arg<PipeBencodeReader>().SkipBytesAsync(length));
}

internal static async ValueTask<IBObject> ParseStringAsync(this IBObjectParser parser, string bencodedString)
{
var bytes = Encoding.UTF8.GetBytes(bencodedString).AsMemory();
var (reader, writer) = new Pipe();
await writer.WriteAsync(bytes);
writer.Complete();
return await parser.ParseAsync(reader);
}

internal static async ValueTask<T> ParseStringAsync<T>(this IBObjectParser<T> parser, string bencodedString) where T : IBObject
{
var bytes = Encoding.UTF8.GetBytes(bencodedString).AsMemory();
var (reader, writer) = new Pipe();
await writer.WriteAsync(bytes);
writer.Complete();
return await parser.ParseAsync(reader);
}

internal static void Deconstruct(this Pipe pipe, out PipeReader reader, out PipeWriter writer)
{
reader = pipe.Reader;
writer = pipe.Writer;
}
}
}

0 comments on commit ba016f1

Please sign in to comment.