-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathIsTimeToRunShould.cs
More file actions
59 lines (51 loc) · 2.05 KB
/
IsTimeToRunShould.cs
File metadata and controls
59 lines (51 loc) · 2.05 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
using System;
using System.Collections.Generic;
using DevChatter.Bot.Core;
using DevChatter.Bot.Core.Automation;
using DevChatter.Bot.Core.Data;
using DevChatter.Bot.Core.Data.Model;
using DevChatter.Bot.Core.Data.Specifications;
using DevChatter.Bot.Core.Events;
using DevChatter.Bot.Core.Systems.Chat;
using Moq;
using UnitTests.Fakes;
using Xunit;
namespace UnitTests.Core.Automation.CurrencyUpdateTests
{
public class IsTimeToRunShould
{
[Fact]
public void ReturnFalse_UponInitialCreation()
{
var currencyUpdate = new CurrencyUpdate(1, null, new FakeClock());
bool result = currencyUpdate.IsTimeToRun();
Assert.False(result);
}
[Fact]
public void ReturnTrue_AfterWaitingFullInterval()
{
const int intervalInMinutes = 1;
var fakeClock = new FakeClock();
var currencyUpdate = new CurrencyUpdate(intervalInMinutes, null, fakeClock);
fakeClock.Now = fakeClock.Now.AddMinutes(intervalInMinutes);
Assert.True(currencyUpdate.IsTimeToRun());
}
[Fact]
public void ReturnFalse_AfterInvokingAction()
{
const int intervalInMinutes = 1;
var repository = new Mock<IRepository>();
repository.Setup(x => x.List(It.IsAny<ISpecification<ChatUser>>())).Returns(new List<ChatUser>());
var knownBotService = new Mock<IKnownBotService>();
var currencyGenerator = new CurrencyGenerator(new List<IChatClient>(),
new ChatUserCollection(repository.Object, knownBotService.Object));
var fakeClock = new FakeClock();
var currencyUpdate = new CurrencyUpdate(intervalInMinutes, currencyGenerator, fakeClock);
fakeClock.Now = fakeClock.Now.AddMinutes(intervalInMinutes);
Assert.True(currencyUpdate.IsTimeToRun());
fakeClock.Now = fakeClock.Now.AddMinutes(intervalInMinutes);
currencyUpdate.Invoke();
Assert.False(currencyUpdate.IsTimeToRun());
}
}
}