-
Notifications
You must be signed in to change notification settings - Fork 751
/
SchedulerServiceTests.cs
executable file
·72 lines (61 loc) · 2.31 KB
/
SchedulerServiceTests.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
66
67
68
69
70
71
72
// ReSharper disable InconsistentNaming
using System.Collections.Generic;
using EasyNetQ.Loggers;
using EasyNetQ.SystemMessages;
using EasyNetQ.Topology;
using NUnit.Framework;
using Rhino.Mocks;
namespace EasyNetQ.Scheduler.Tests
{
[TestFixture]
public class SchedulerServiceTests
{
private SchedulerService schedulerService;
private IBus bus;
private IAdvancedBus advancedBus;
private IAdvancedPublishChannel channel;
private IScheduleRepository scheduleRepository;
[SetUp]
public void SetUp()
{
bus = MockRepository.GenerateStub<IBus>();
advancedBus = MockRepository.GenerateStub<IAdvancedBus>();
channel = MockRepository.GenerateStub<IAdvancedPublishChannel>();
bus.Stub(x => x.IsConnected).Return(true);
bus.Stub(x => x.Advanced).Return(advancedBus);
advancedBus.Stub(x => x.OpenPublishChannel()).Return(channel);
scheduleRepository = MockRepository.GenerateStub<IScheduleRepository>();
schedulerService = new SchedulerService(
bus,
new ConsoleLogger(),
scheduleRepository,
new SchedulerServiceConfiguration
{
PublishIntervalSeconds = 1,
PurgeIntervalSeconds = 1
});
}
[Test]
public void Should_get_pending_scheduled_messages_and_update_them()
{
var pendingSchedule = new List<ScheduleMe>
{
new ScheduleMe { BindingKey = "msg1"},
new ScheduleMe { BindingKey = "msg2"},
};
scheduleRepository.Stub(x => x.GetPending()).Return(pendingSchedule);
schedulerService.OnPublishTimerTick(null);
channel.AssertWasCalled(x => x.Publish(
Arg<Exchange>.Is.Anything,
Arg<string>.Is.Equal("msg1"),
Arg<MessageProperties>.Is.Anything,
Arg<byte[]>.Is.Anything));
channel.AssertWasCalled(x => x.Publish(
Arg<Exchange>.Is.Anything,
Arg<string>.Is.Equal("msg2"),
Arg<MessageProperties>.Is.Anything,
Arg<byte[]>.Is.Anything));
}
}
}
// ReSharper restore InconsistentNaming