-
-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathUpdateAccountInfoCommandTest.cs
More file actions
69 lines (61 loc) · 2.53 KB
/
UpdateAccountInfoCommandTest.cs
File metadata and controls
69 lines (61 loc) · 2.53 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
using HtmlAgilityPack;
using MainCore.Commands.Update;
using MainCore.Entities;
using MainCore.Enums;
using MainCore.Services;
namespace MainCore.Test.Commands.Update
{
public class UpdateAccountInfoCommandTest
{
private const string PlusAccount = "Parsers/Info/PlusAccount.html";
[Fact]
public async Task UpdateAccountInfoCommandShouldRunWithNewAccount()
{
// Arrange
using var context = new FakeDbContextFactory().CreateDbContext(true);
var html = new HtmlDocument();
html.Load(PlusAccount);
var browser = Substitute.For<IBrowser>();
browser.Html.Returns(html);
var handleBehavior = new UpdateAccountInfoCommand.HandleBehavior(browser, context);
var command = new UpdateAccountInfoCommand.Command(new AccountId(1));
// Act
await handleBehavior.HandleAsync(command, CancellationToken.None);
// Assert
var accountInfo = context.AccountsInfo.FirstOrDefault(x => x.AccountId == 1);
accountInfo.ShouldNotBeNull();
accountInfo.Gold.ShouldBeGreaterThanOrEqualTo(0);
accountInfo.Silver.ShouldBeGreaterThanOrEqualTo(0);
accountInfo.HasPlusAccount.ShouldBeTrue();
}
[Fact]
public async Task UpdateAccountInfoCommandShouldRunWithExistingAccount()
{
// Arrange
using var context = new FakeDbContextFactory().CreateDbContext(true);
context.Add(new AccountInfo
{
AccountId = 1,
Gold = 0,
Silver = 0,
HasPlusAccount = false,
Tribe = TribeEnums.Any,
});
context.SaveChanges();
var html = new HtmlDocument();
html.Load(PlusAccount);
var browser = Substitute.For<IBrowser>();
browser.Html.Returns(html);
var handleBehavior = new UpdateAccountInfoCommand.HandleBehavior(browser, context);
var command = new UpdateAccountInfoCommand.Command(new AccountId(1));
// Act
await handleBehavior.HandleAsync(command, CancellationToken.None);
// Assert
var accountInfo = context.AccountsInfo.FirstOrDefault(x => x.AccountId == 1);
accountInfo.ShouldNotBeNull();
accountInfo.Gold.ShouldBeGreaterThanOrEqualTo(0);
accountInfo.Silver.ShouldBeGreaterThanOrEqualTo(0);
accountInfo.HasPlusAccount.ShouldBeTrue();
}
}
}