-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
CancelCommandTests.cs
65 lines (56 loc) · 2.34 KB
/
CancelCommandTests.cs
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
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using Framework;
using Microsoft.Extensions.Caching.Distributed;
using TelegramTests.Shared;
using Xunit;
namespace TelegramTests
{
[Collection("/cancel command")]
public class CancelCommandTests : IClassFixture<TestsFixture>
{
private readonly TestsFixture _fxt;
public CancelCommandTests(TestsFixture fixture)
{
_fxt = fixture;
}
[OrderedFact("Should delete all the cached items")]
public async Task Should_Remove_Cache()
{
string update = @"{
update_id: 645,
message: {
message_id: 352,
text: ""/cancel"",
chat: { id: 333, type: ""private"" },
from: { id: 333, first_name: ""John"", is_bot: false },
entities: [ { offset: 0, length: 7, type: ""bot_command"" } ],
date: 5641457
}
}";
// ensure cache has values
await _fxt.Cache.SetStringAsync(@"{""u"":333,""c"":333,""k"":""profile""}", "foo: 1");
await _fxt.Cache.SetStringAsync(@"{""u"":333,""c"":333,""k"":""bus""}", "{}");
await _fxt.Cache.SetStringAsync(@"{""u"":333,""c"":333,""k"":""location""}", "VALUE");
HttpResponseMessage response = await _fxt.HttpClient.PostWebhookUpdateAsync(update);
Assert.Equal(HttpStatusCode.Created, response.StatusCode);
string responseContent = await response.Content.ReadAsStringAsync();
Asserts.JsonEqual(@"{
method: ""sendChatAction"",
chat_id: 333,
action: ""typing""
}",
responseContent
);
_fxt.MockBotClient.VerifyAll();
_fxt.MockBotClient.VerifyNoOtherCalls();
string cachedLocation = await _fxt.Cache.GetStringAsync(@"{""u"":333,""c"":333,""k"":""location""}");
string cachedBus = await _fxt.Cache.GetStringAsync(@"{""u"":333,""c"":333,""k"":""bus""}");
string cachedProfile = await _fxt.Cache.GetStringAsync(@"{""u"":333,""c"":333,""k"":""profile""}");
Assert.Null(cachedLocation);
Assert.Null(cachedBus);
Assert.Null(cachedProfile);
}
}
}