-
-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathBObjectParserListTests.cs
More file actions
159 lines (126 loc) · 4.63 KB
/
Copy pathBObjectParserListTests.cs
File metadata and controls
159 lines (126 loc) · 4.63 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
using System;
using BencodeNET.Objects;
using BencodeNET.Parsing;
using FluentAssertions;
using Xunit;
namespace BencodeNET.Tests.Parsing
{
public class BObjectParserListTests
{
[Theory]
[AutoMockedData]
public void Add_GenericParser_ContainsOnlyThatParser(IBObjectParser<IBObject> parser)
{
var list = new BObjectParserList();
list.Add(parser);
list.Should().HaveCount(1);
list.Should().ContainSingle(x => x.Value == parser);
}
[Theory]
[AutoMockedData]
public void Add_GenericParser_AddedWithGenericTypeAsKey(IBObjectParser<IBObject> parser)
{
var list = new BObjectParserList();
list.Add(parser);
list.Should().HaveCount(1);
list.Should().ContainSingle(x => x.Key == typeof(IBObject));
}
[Theory]
[AutoMockedData]
public void Add_GenericParser_ReplacesExistingOfSameGenericType(IBObjectParser<IBObject> parser)
{
var list = new BObjectParserList();
list.Add(parser);
list.Add(parser);
list.Should().HaveCount(1);
list.Should().ContainSingle(x => x.Value == parser);
}
[Theory]
[AutoMockedData()]
public void Add_ParserWithType_ReplacesExistingOfSameGenericType(IBObjectParser parser)
{
var list = new BObjectParserList();
list.Add(typeof(BString), parser);
list.Add(typeof(BString), parser);
list.Should().HaveCount(1);
list.Should().ContainSingle(x => x.Value == parser);
}
[Theory]
[AutoMockedData(typeof(object))]
[AutoMockedData(typeof(string))]
[AutoMockedData(typeof(int))]
public void Add_ParserWithNonIBObjectType_ThrowsArgumentException(Type type, IBObjectParser parser)
{
var list = new BObjectParserList();
Action action = () => list.Add(type, parser);
action.Should().Throw<ArgumentException>("because only IBObject types are allowed");
}
[Theory]
[AutoMockedData]
public void Add_WithMultipleTypes_AddsParserForEachType(IBObjectParser parser)
{
var types = new[] {typeof (BString), typeof (BNumber), typeof (BList)};
var list = new BObjectParserList();
list.Add(types, parser);
list.Should().HaveCount(3);
list.Should().OnlyContain(x => x.Value == parser);
}
[Theory]
[AutoMockedData]
public void Clear_EmptiesList(IBObjectParser<BString> parser1, IBObjectParser<BNumber> parser2)
{
var list = new BObjectParserList {parser1, parser2};
list.Clear();
list.Should().BeEmpty();
}
[Fact]
public void Indexer_Get_ReturnsNullIfKeyMissing()
{
var list = new BObjectParserList();
var parser = list[typeof (object)];
parser.Should().BeNull();
}
[Fact]
public void Indexer_Get_ReturnsMatchingParserForType()
{
var stringParser = new BStringParser();
var list = new BObjectParserList {stringParser};
var parser = list[typeof(BString)];
parser.Should().BeSameAs(stringParser);
}
[Fact]
public void Indexer_Set_AddsParserForType()
{
var stringParser = new BStringParser();
var list = new BObjectParserList();
list[typeof (BString)] = stringParser;
list.Should().HaveCount(1);
list[typeof (BString)].Should().BeSameAs(stringParser);
}
[Fact]
public void Indexer_Set_ReplacesExistingParserForType()
{
var stringParser1 = new BStringParser();
var stringParser2 = new BStringParser();
var list = new BObjectParserList { stringParser1 };
list[typeof (BString)] = stringParser2;
list.Should().HaveCount(1);
list[typeof (BString)].Should().BeSameAs(stringParser2);
}
[Fact]
public void Get_Generic_ReturnsMatchingParser()
{
var stringParser = new BStringParser();
var list = new BObjectParserList {stringParser};
var parser = list.Get<BString>();
parser.Should().BeSameAs(stringParser);
}
[Fact]
public void Get_Generic_ReturnsNullIfNoMatchingParser()
{
var list = new BObjectParserList();
var parser = list.Get<BString>();
parser.Should().BeNull();
}
}
}