Skip to content

Commit e006496

Browse files
authored
implemented new parameter to allow messages to be sent as replies or not (#317)
* implemented new parameter to allow messages to be sent as replies or not Resolves #316 * disabling some broken tests (out of scope) * refactoring to xunit
1 parent d69e4db commit e006496

File tree

16 files changed

+227
-184
lines changed

16 files changed

+227
-184
lines changed

src/FloppyBot.Chat/Entities/Identifiers/ChatMessageIdentifier.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ public static ChatMessageIdentifier NewFor(string channelId)
2323
return $"{channelId}/{NEW_MESSAGE_ID}";
2424
}
2525

26+
public static ChatMessageIdentifier NewFor(ChatMessageIdentifier channelId)
27+
{
28+
return channelId with { MessageId = NEW_MESSAGE_ID };
29+
}
30+
2631
public override string ToString()
2732
{
2833
return IdentifierUtils.GenerateId(Interface, Channel, MessageId);

src/FloppyBot.Commands.Aux.Quotes.Tests/FloppyBot.Commands.Aux.Quotes.Tests.csproj

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@
44
<ImplicitUsings>enable</ImplicitUsings>
55
<Nullable>enable</Nullable>
66
<IsPackable>false</IsPackable>
7+
<IsTestProject>true</IsTestProject>
78
</PropertyGroup>
89
<ItemGroup>
9-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
10-
<PackageReference Include="MSTest.TestAdapter" Version="3.3.1" />
11-
<PackageReference Include="MSTest.TestFramework" Version="3.3.1" />
12-
<PackageReference Include="coverlet.collector" Version="6.0.2">
10+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0"/>
11+
<PackageReference Include="xunit" Version="2.8.0" />
12+
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.0">
13+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1314
<PrivateAssets>all</PrivateAssets>
15+
</PackageReference>
16+
<PackageReference Include="coverlet.collector" Version="6.0.2">
1417
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
18+
<PrivateAssets>all</PrivateAssets>
1519
</PackageReference>
1620
</ItemGroup>
1721
<ItemGroup>

src/FloppyBot.Commands.Aux.Quotes.Tests/QuoteChannelMappingServiceTests.cs

Lines changed: 51 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
namespace FloppyBot.Commands.Aux.Quotes.Tests;
88

9-
[TestClass]
109
public class QuoteChannelMappingServiceTests
1110
{
1211
private readonly IRepository<QuoteChannelMappingJoinKeys> _joinKeyRepo;
@@ -23,7 +22,7 @@ public QuoteChannelMappingServiceTests()
2322
_service = new QuoteChannelMappingService(factory, _timeProvider);
2423
}
2524

26-
[TestMethod]
25+
[Fact]
2726
public void GetQuoteChannelMapping()
2827
{
2928
_repository.InsertMany(
@@ -32,166 +31,133 @@ public void GetQuoteChannelMapping()
3231
new QuoteChannelMapping(null!, "AnMappingId", "Mock/AdditionalChannel", false)
3332
);
3433

35-
Assert.AreEqual("AnMappingId", _service.GetQuoteChannelMapping("Mock/Channel"));
36-
Assert.AreEqual("AnMappingId", _service.GetQuoteChannelMapping("Mock/OtherChannel"));
37-
Assert.IsNull(_service.GetQuoteChannelMapping("Mock/AdditionalChannel"));
38-
Assert.IsNull(_service.GetQuoteChannelMapping("Mock/AnotherAdditionalChannel"));
34+
Assert.Equal("AnMappingId", _service.GetQuoteChannelMapping("Mock/Channel"));
35+
Assert.Equal("AnMappingId", _service.GetQuoteChannelMapping("Mock/OtherChannel"));
36+
Assert.Null(_service.GetQuoteChannelMapping("Mock/AdditionalChannel"));
37+
Assert.Null(_service.GetQuoteChannelMapping("Mock/AnotherAdditionalChannel"));
3938
}
4039

41-
[TestMethod]
40+
[Fact]
4241
public void GetQuoteChannelMappingCreatesConfirmedMapping()
4342
{
4443
var mappingId = _service.GetQuoteChannelMapping("Mock/Channel", true);
45-
Assert.IsTrue(
46-
_repository
47-
.GetAll()
48-
.Any(m => m.MappingId == mappingId && m.ChannelId == "Mock/Channel" && m.Confirmed)
44+
Assert.Contains(
45+
_repository.GetAll(),
46+
m => m.MappingId == mappingId && m.ChannelId == "Mock/Channel" && m.Confirmed
4947
);
5048
}
5149

52-
[TestMethod]
50+
[Fact]
5351
public void PositiveJoinProcess()
5452
{
5553
// Create first channel mapping
5654
var mappingId = CreateMapping("Mock/ChannelId");
5755

5856
// Ask for second channel to join
5957
var confirmCode = _service.StartJoinProcess(mappingId, "Mock/Channel2");
60-
Assert.IsNotNull(confirmCode);
58+
Assert.NotNull(confirmCode);
6159

6260
// Ensure record has been created
63-
Assert.IsTrue(
64-
_repository
65-
.GetAll()
66-
.Any(m =>
67-
m.ChannelId == "Mock/Channel2" && m.MappingId == mappingId && !m.Confirmed
68-
)
61+
Assert.Contains(
62+
_repository.GetAll(),
63+
m => m.ChannelId == "Mock/Channel2" && m.MappingId == mappingId && !m.Confirmed
6964
);
70-
Assert.IsTrue(
71-
_joinKeyRepo
72-
.GetAll()
73-
.Any(k =>
74-
k.Id == confirmCode
75-
&& k.MappingId == mappingId
76-
&& k.ChannelId == "Mock/Channel2"
77-
)
65+
Assert.Contains(
66+
_joinKeyRepo.GetAll(),
67+
k => k.Id == confirmCode && k.MappingId == mappingId && k.ChannelId == "Mock/Channel2"
7868
);
7969

8070
// Advance time a bit
8171
_timeProvider.AdvanceTimeBy(1.Minute());
8272

8373
// Confirm with code given
84-
Assert.IsTrue(_service.ConfirmJoinProcess(mappingId, "Mock/Channel2", confirmCode));
85-
Assert.IsTrue(
86-
_repository
87-
.GetAll()
88-
.Any(m => m.ChannelId == "Mock/Channel2" && m.MappingId == mappingId && m.Confirmed)
74+
Assert.True(_service.ConfirmJoinProcess(mappingId, "Mock/Channel2", confirmCode));
75+
Assert.Contains(
76+
_repository.GetAll(),
77+
m => m.ChannelId == "Mock/Channel2" && m.MappingId == mappingId && m.Confirmed
8978
);
90-
Assert.IsFalse(
91-
_joinKeyRepo
92-
.GetAll()
93-
.Any(k =>
94-
k.Id == confirmCode
95-
&& k.MappingId == mappingId
96-
&& k.ChannelId == "Mock/Channel2"
97-
)
79+
Assert.DoesNotContain(
80+
_joinKeyRepo.GetAll(),
81+
k => k.Id == confirmCode && k.MappingId == mappingId && k.ChannelId == "Mock/Channel2"
9882
);
9983
}
10084

101-
[TestMethod]
85+
[Fact]
10286
public void ExpiredJoinProcess()
10387
{
10488
// Create first channel mapping
10589
var mappingId = CreateMapping("Mock/ChannelId");
10690

10791
// Ask for second channel to join
10892
var confirmCode = _service.StartJoinProcess(mappingId, "Mock/Channel2");
109-
Assert.IsNotNull(confirmCode);
93+
Assert.NotNull(confirmCode);
11094

11195
// Advance time a bit
11296
_timeProvider.AdvanceTimeBy(6.Minute());
11397

11498
// Confirm with code given
115-
Assert.IsFalse(_service.ConfirmJoinProcess(mappingId, "Mock/Channel2", confirmCode));
116-
Assert.IsFalse(
117-
_repository
118-
.GetAll()
119-
.Any(m => m.ChannelId == "Mock/Channel2" && m.MappingId == mappingId)
99+
Assert.False(_service.ConfirmJoinProcess(mappingId, "Mock/Channel2", confirmCode));
100+
Assert.DoesNotContain(
101+
_repository.GetAll(),
102+
m => m.ChannelId == "Mock/Channel2" && m.MappingId == mappingId
120103
);
121-
Assert.IsFalse(
122-
_joinKeyRepo
123-
.GetAll()
124-
.Any(k =>
125-
k.Id == confirmCode
126-
&& k.MappingId == mappingId
127-
&& k.ChannelId == "Mock/Channel2"
128-
)
104+
Assert.DoesNotContain(
105+
_joinKeyRepo.GetAll(),
106+
k => k.Id == confirmCode && k.MappingId == mappingId && k.ChannelId == "Mock/Channel2"
129107
);
130108
}
131109

132-
[TestMethod]
110+
[Fact]
133111
public void InvalidKeyJoinProcess()
134112
{
135113
// Create first channel mapping
136114
var mappingId = CreateMapping("Mock/ChannelId");
137115

138116
// Ask for second channel to join
139117
var confirmCode = _service.StartJoinProcess(mappingId, "Mock/Channel2");
140-
Assert.IsNotNull(confirmCode);
118+
Assert.NotNull(confirmCode);
141119

142120
// Advance time a bit
143121
_timeProvider.AdvanceTimeBy(1.Minute());
144122

145123
// Confirm with code given
146-
Assert.IsFalse(_service.ConfirmJoinProcess(mappingId, "Mock/Channel2", "InvalidCode"));
147-
Assert.IsFalse(
148-
_repository
149-
.GetAll()
150-
.Any(m => m.ChannelId == "Mock/Channel2" && m.MappingId == mappingId && m.Confirmed)
124+
Assert.False(_service.ConfirmJoinProcess(mappingId, "Mock/Channel2", "InvalidCode"));
125+
Assert.DoesNotContain(
126+
_repository.GetAll(),
127+
m => m.ChannelId == "Mock/Channel2" && m.MappingId == mappingId && m.Confirmed
151128
);
152129
// Key is kept
153-
Assert.IsTrue(
154-
_joinKeyRepo
155-
.GetAll()
156-
.Any(k =>
157-
k.Id == confirmCode
158-
&& k.MappingId == mappingId
159-
&& k.ChannelId == "Mock/Channel2"
160-
)
130+
Assert.Contains(
131+
_joinKeyRepo.GetAll(),
132+
k => k.Id == confirmCode && k.MappingId == mappingId && k.ChannelId == "Mock/Channel2"
161133
);
162134
}
163135

164-
[TestMethod]
136+
[Fact]
165137
public void MissingChannelJoinProcess()
166138
{
167139
// Create first channel mapping
168140
var mappingId = CreateMapping("Mock/ChannelId");
169141

170142
// Ask for second channel to join
171143
var confirmCode = _service.StartJoinProcess(mappingId, "Mock/Channel2");
172-
Assert.IsNotNull(confirmCode);
144+
Assert.NotNull(confirmCode);
173145

174146
// Advance time a bit
175147
_timeProvider.AdvanceTimeBy(1.Minute());
176148

177149
// Confirm with code given
178-
Assert.IsFalse(
150+
Assert.False(
179151
_service.ConfirmJoinProcess(mappingId, "Mock/NotTheRightChannel", confirmCode)
180152
);
181-
Assert.IsFalse(
182-
_repository
183-
.GetAll()
184-
.Any(m => m.ChannelId == "Mock/Channel2" && m.MappingId == mappingId && m.Confirmed)
153+
Assert.DoesNotContain(
154+
_repository.GetAll(),
155+
m => m.ChannelId == "Mock/Channel2" && m.MappingId == mappingId && m.Confirmed
185156
);
186157
// Key is kept
187-
Assert.IsTrue(
188-
_joinKeyRepo
189-
.GetAll()
190-
.Any(k =>
191-
k.Id == confirmCode
192-
&& k.MappingId == mappingId
193-
&& k.ChannelId == "Mock/Channel2"
194-
)
158+
Assert.Contains(
159+
_joinKeyRepo.GetAll(),
160+
k => k.Id == confirmCode && k.MappingId == mappingId && k.ChannelId == "Mock/Channel2"
195161
);
196162
}
197163

0 commit comments

Comments
 (0)