forked from Krusen/BencodeNET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBObjectParserTests.cs
More file actions
63 lines (52 loc) · 1.77 KB
/
Copy pathBObjectParserTests.cs
File metadata and controls
63 lines (52 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System.IO;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using BencodeNET.IO;
using BencodeNET.Objects;
using BencodeNET.Parsing;
using NSubstitute;
using Xunit;
namespace BencodeNET.Tests.Parsing
{
public class BObjectParserTests
{
[Theory]
[AutoMockedData]
public void Parse_String_CallsOverriddenParse(IBObjectParser<IBObject> parserMock)
{
var parser = new MockBObjectParser(parserMock);
parser.ParseString("bencoded string");
parserMock.Received().Parse(Arg.Any<BencodeReader>());
}
[Theory]
[AutoMockedData]
public void Parse_Stream_CallsOverriddenParse(IBObjectParser<IBObject> parserMock)
{
var parser = new MockBObjectParser(parserMock);
var bytes = Encoding.UTF8.GetBytes("bencoded string");
using (var stream = new MemoryStream(bytes))
{
parser.Parse(stream);
}
parserMock.Received().Parse(Arg.Any<BencodeReader>());
}
class MockBObjectParser : BObjectParser<IBObject>
{
public MockBObjectParser(IBObjectParser<IBObject> substitute)
{
Substitute = substitute;
}
public IBObjectParser<IBObject> Substitute { get; set; }
public override Encoding Encoding => Encoding.UTF8;
public override IBObject Parse(BencodeReader stream)
{
return Substitute.Parse(stream);
}
public override ValueTask<IBObject> ParseAsync(PipeBencodeReader pipeReader, CancellationToken cancellationToken = default)
{
throw new System.NotImplementedException();
}
}
}
}