|
3 | 3 | using InEngine.Commands; |
4 | 4 | using InEngine.Core.Commands; |
5 | 5 | using InEngine.Core.Queuing; |
| 6 | +using InEngine.Core.Queuing.Clients; |
6 | 7 | using InEngine.Core.Queuing.Commands; |
7 | 8 | using Moq; |
8 | 9 | using NUnit.Framework; |
|
11 | 12 | namespace InEngine.Core.Test.Queuing |
12 | 13 | { |
13 | 14 | [TestFixture] |
14 | | - public class QueueTest : TestBase |
| 15 | + public class QueueTest : TestBase<Queue> |
15 | 16 | { |
16 | | - public Queue Subject { get; private set; } |
| 17 | + public Mock<IQueueClient> MockQueueClient { get; set; } |
17 | 18 |
|
18 | 19 | [SetUp] |
19 | 20 | public void Setup() |
20 | 21 | { |
21 | 22 | InEngineSettings.BasePath = TestContext.CurrentContext.TestDirectory; |
22 | | - Subject = Queue.Make(); |
| 23 | + MockQueueClient = new Mock<IQueueClient>(); |
| 24 | + Subject.QueueClient = MockQueueClient.Object; |
23 | 25 | } |
24 | 26 |
|
25 | 27 | [Test] |
26 | | - public void ShouldPublishLambda() |
| 28 | + public void ShouldPublishCommand() |
27 | 29 | { |
28 | | - Subject.Publish(() => { Console.Write("Hello, world."); }); |
| 30 | + var command = Fake.It(); |
| 31 | + MockQueueClient.Setup(x => x.Publish(command)); |
| 32 | + |
| 33 | + Subject.Publish(command); |
| 34 | + |
| 35 | + MockQueueClient.Verify(x => x.Publish(command), Times.Once()); |
| 36 | + } |
| 37 | + |
| 38 | + [Test] |
| 39 | + public void ShouldPublishLambdaCommand() |
| 40 | + { |
| 41 | + Action action = () => { Console.Write("Hello, world."); }; |
| 42 | + var lambda = new Lambda() { Action = action }; |
| 43 | + MockQueueClient.Setup(x => x.Publish(It.IsAny<Lambda>())); |
| 44 | + |
| 45 | + Subject.Publish(action); |
| 46 | + |
| 47 | + MockQueueClient.Verify(x => x.Publish(It.Is<Lambda>(y => y.Action == action)), Times.Once()); |
| 48 | + } |
| 49 | + |
| 50 | + [Test] |
| 51 | + public void ShouldPublishChainOfCommands() |
| 52 | + { |
| 53 | + var commands = new[] { |
| 54 | + new AlwaysSucceed(), |
| 55 | + new AlwaysSucceed(), |
| 56 | + new AlwaysSucceed(), |
| 57 | + new AlwaysSucceed(), |
| 58 | + }; |
| 59 | + MockQueueClient.Setup(x => x.Publish(It.IsAny<Chain>())); |
| 60 | + |
| 61 | + Subject.Publish(commands); |
| 62 | + |
| 63 | + MockQueueClient.Verify(x => x.Publish(It.Is<Chain>(y => y.Commands.Equals(commands))), Times.Once()); |
29 | 64 | } |
30 | 65 | } |
31 | 66 | } |
0 commit comments