Line data Source code
1 : using System;
2 : using System.Collections.Generic;
3 : using System.Threading;
4 : using Cqrs.Azure.ServiceBus.Tests.Unit;
5 : using Cqrs.Configuration;
6 : using cdmdotnet.Logging;
7 : using cdmdotnet.Logging.Configuration;
8 : using cdmdotnet.StateManagement.Threaded;
9 : using Cqrs.Bus;
10 : using Cqrs.Commands;
11 : using Cqrs.Events;
12 : using NUnit.Framework;
13 : using TestClass = NUnit.Framework.TestFixtureAttribute;
14 : using TestMethod = NUnit.Framework.TestAttribute;
15 : using TestInitialize = NUnit.Framework.SetUpAttribute;
16 : using TestCleanup = NUnit.Framework.TearDownAttribute;
17 : using TestContext = System.Object;
18 :
19 : namespace Cqrs.Azure.ServiceBus.Tests.Integration
20 : {
21 : /// <summary>
22 : /// A series of tests publishing <see cref="IEvent{TAuthenticationToken}">events</see>.
23 : /// </summary>
24 : [TestClass]
25 : public class RoundTripTests
26 1 : {
27 : /// <summary>
28 : /// Tests a test <see cref="IEvent{TAuthenticationToken}"/> can be published via
29 : /// <see cref="AzureEventBusPublisher{TAuthenticationToken}"/> and two <see cref="IEventHandler">event handlers</see>
30 : /// Will fire updating test flags.
31 : /// </summary>
32 : [TestMethod]
33 1 : public void Publish_TestEvent_NoExceptions()
34 : {
35 : // Arrange
36 : IDictionary<Guid, Tuple<bool, Exception>> testResponse = new Dictionary<Guid, Tuple<bool, Exception>>();
37 :
38 : Guid processId = Guid.NewGuid();
39 : testResponse.Add(processId, new Tuple<bool, Exception>(false, null));
40 : var @event = new TestEvent{Id = processId};
41 :
42 : var azureEventBusReceiver = new AzureEventBusReceiver<Guid>(new ConfigurationManager(), new MessageSerialiser<Guid>(), new GuidAuthenticationTokenHelper(), new NullCorrelationIdHelper(), new ConsoleLogger(new LoggerSettingsConfigurationSection(), new NullCorrelationIdHelper()), new AzureBusHelper<Guid>(new GuidAuthenticationTokenHelper(), new NullCorrelationIdHelper(), new ConsoleLogger(new LoggerSettingsConfigurationSection(), new NullCorrelationIdHelper()), new MessageSerialiser<Guid>(), new BusHelper(new ConfigurationManager(), new ThreadedContextItemCollectionFactory()), new BuiltInHashAlgorithmFactory(), new ConfigurationManager(), null), new BusHelper(new ConfigurationManager(), new ThreadedContextItemCollectionFactory()), new BuiltInHashAlgorithmFactory());
43 : var handler = new TestEventSuccessHandler(testResponse);
44 : azureEventBusReceiver.RegisterHandler<TestEvent>(handler.Handle, handler.GetType());
45 : azureEventBusReceiver.Start();
46 :
47 : var azureEventBusPublisher = new AzureEventBusPublisher<Guid>(new ConfigurationManager(), new MessageSerialiser<Guid>(), new GuidAuthenticationTokenHelper(), new NullCorrelationIdHelper(), new ConsoleLogger(new LoggerSettingsConfigurationSection(), new NullCorrelationIdHelper()), new AzureBusHelper<Guid>(new GuidAuthenticationTokenHelper(), new NullCorrelationIdHelper(), new ConsoleLogger(new LoggerSettingsConfigurationSection(), new NullCorrelationIdHelper()), new MessageSerialiser<Guid>(), new BusHelper(new ConfigurationManager(), new ThreadedContextItemCollectionFactory()), new BuiltInHashAlgorithmFactory(), new ConfigurationManager(), null), new BusHelper(new ConfigurationManager(), new ThreadedContextItemCollectionFactory()), new BuiltInHashAlgorithmFactory());
48 :
49 : // Act
50 : azureEventBusPublisher.Publish(@event);
51 :
52 : // Assert
53 : SpinWait.SpinUntil(() => testResponse[processId].Item1);
54 : Assert.IsNull(testResponse[processId].Item2);
55 : }
56 :
57 : /// <summary>
58 : /// Tests a test <see cref="ICommand{TAuthenticationToken}"/> can be published via
59 : /// <see cref="AzureCommandBusPublisher{TAuthenticationToken}"/> and two <see cref="IEventHandler">event handlers</see>
60 : /// Will fire updating test flags.
61 : /// </summary>
62 : [TestMethod]
63 1 : public void Publish_TestCommand_NoExceptions()
64 : {
65 : // Arrange
66 : IDictionary<Guid, Tuple<bool, Exception>> testResponse = new Dictionary<Guid, Tuple<bool, Exception>>();
67 :
68 : Guid processId = Guid.NewGuid();
69 : testResponse.Add(processId, new Tuple<bool, Exception>(false, null));
70 : var command = new TestCommand { Id = processId };
71 :
72 : var azureCommandBusReceiver = new AzureCommandBusReceiver<Guid>(new ConfigurationManager(), new MessageSerialiser<Guid>(), new GuidAuthenticationTokenHelper(), new NullCorrelationIdHelper(), new ConsoleLogger(new LoggerSettingsConfigurationSection(), new NullCorrelationIdHelper()), new AzureBusHelper<Guid>(new GuidAuthenticationTokenHelper(), new NullCorrelationIdHelper(), new ConsoleLogger(new LoggerSettingsConfigurationSection(), new NullCorrelationIdHelper()), new MessageSerialiser<Guid>(), new BusHelper(new ConfigurationManager(), new ThreadedContextItemCollectionFactory()), new BuiltInHashAlgorithmFactory(), new ConfigurationManager(), null), new BusHelper(new ConfigurationManager(), new ThreadedContextItemCollectionFactory()), new BuiltInHashAlgorithmFactory());
73 : var handler = new TestCommandSuccessHandler(testResponse);
74 : azureCommandBusReceiver.RegisterHandler<TestCommand>(handler.Handle, handler.GetType());
75 : azureCommandBusReceiver.Start();
76 :
77 : var azureCommandBusPublisher = new AzureCommandBusPublisher<Guid>(new ConfigurationManager(), new MessageSerialiser<Guid>(), new GuidAuthenticationTokenHelper(), new NullCorrelationIdHelper(), new ConsoleLogger(new LoggerSettingsConfigurationSection(), new NullCorrelationIdHelper()), new AzureBusHelper<Guid>(new GuidAuthenticationTokenHelper(), new NullCorrelationIdHelper(), new ConsoleLogger(new LoggerSettingsConfigurationSection(), new NullCorrelationIdHelper()), new MessageSerialiser<Guid>(), new BusHelper(new ConfigurationManager(), new ThreadedContextItemCollectionFactory()), new BuiltInHashAlgorithmFactory(), new ConfigurationManager(), null), new BusHelper(new ConfigurationManager(), new ThreadedContextItemCollectionFactory()), new BuiltInHashAlgorithmFactory());
78 :
79 : // Act
80 : azureCommandBusPublisher.Publish(command);
81 :
82 : // Assert
83 : SpinWait.SpinUntil(() => testResponse[processId].Item1);
84 : Assert.IsNull(testResponse[processId].Item2);
85 : }
86 : }
87 : }
|