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 Cqrs.Bus;
9 : using Cqrs.Messages;
10 : using NUnit.Framework;
11 : using TestClass = NUnit.Framework.TestFixtureAttribute;
12 : using TestMethod = NUnit.Framework.TestAttribute;
13 : using TestInitialize = NUnit.Framework.SetUpAttribute;
14 : using TestCleanup = NUnit.Framework.TearDownAttribute;
15 : using TestContext = System.Object;
16 :
17 : namespace Cqrs.Azure.ServiceBus.Tests.Integration
18 : {
19 : [TestClass]
20 : public class RoundTripTests
21 0 : {
22 : [TestMethod]
23 0 : public void Publish_TestEvent_NoExceptions()
24 : {
25 : // Arrange
26 : IDictionary<Guid, Tuple<bool, Exception>> testResponse = new Dictionary<Guid, Tuple<bool, Exception>>();
27 :
28 : Guid processId = Guid.NewGuid();
29 : testResponse.Add(processId, new Tuple<bool, Exception>(false, null));
30 : var @event = new TestEvent{Id = processId};
31 :
32 : var azureEventBusReceiver = new AzureEventBusReceiver<Guid>(new ConfigurationManager(), new MessageSerialiser<Guid>(), new GuidSingleSignOnTokenValueHelper(), new NullCorrelationIdHelper(), new ConsoleLogger(new LoggerSettingsConfigurationSection(), new NullCorrelationIdHelper()), new AzureBusHelper<Guid>(new GuidSingleSignOnTokenValueHelper(), new NullCorrelationIdHelper(), new ConsoleLogger(new LoggerSettingsConfigurationSection(), new NullCorrelationIdHelper()), new MessageSerialiser<Guid>(), new BusHelper(new ConfigurationManager()), new ConfigurationManager(), null), new BusHelper(new ConfigurationManager()));
33 : var handler = new TestEventSuccessHandler(testResponse);
34 : azureEventBusReceiver.RegisterHandler<TestEvent>(handler.Handle, handler.GetType());
35 : azureEventBusReceiver.Start();
36 :
37 : var azureEventBusPublisher = new AzureEventBusPublisher<Guid>(new ConfigurationManager(), new MessageSerialiser<Guid>(), new GuidSingleSignOnTokenValueHelper(), new NullCorrelationIdHelper(), new ConsoleLogger(new LoggerSettingsConfigurationSection(), new NullCorrelationIdHelper()), new AzureBusHelper<Guid>(new GuidSingleSignOnTokenValueHelper(), new NullCorrelationIdHelper(), new ConsoleLogger(new LoggerSettingsConfigurationSection(), new NullCorrelationIdHelper()), new MessageSerialiser<Guid>(), new BusHelper(new ConfigurationManager()), new ConfigurationManager(), null), new BusHelper(new ConfigurationManager()));
38 :
39 : // Act
40 : azureEventBusPublisher.Publish(@event);
41 :
42 : // Assert
43 : SpinWait.SpinUntil(() => testResponse[processId].Item1);
44 : Assert.IsNull(testResponse[processId].Item2);
45 : }
46 :
47 : [TestMethod]
48 0 : public void Publish_TestCommand_NoExceptions()
49 : {
50 : // Arrange
51 : IDictionary<Guid, Tuple<bool, Exception>> testResponse = new Dictionary<Guid, Tuple<bool, Exception>>();
52 :
53 : Guid processId = Guid.NewGuid();
54 : testResponse.Add(processId, new Tuple<bool, Exception>(false, null));
55 : var command = new TestCommand { Id = processId };
56 :
57 : var azureCommandBusReceiver = new AzureCommandBusReceiver<Guid>(new ConfigurationManager(), new MessageSerialiser<Guid>(), new GuidSingleSignOnTokenValueHelper(), new NullCorrelationIdHelper(), new ConsoleLogger(new LoggerSettingsConfigurationSection(), new NullCorrelationIdHelper()), new AzureBusHelper<Guid>(new GuidSingleSignOnTokenValueHelper(), new NullCorrelationIdHelper(), new ConsoleLogger(new LoggerSettingsConfigurationSection(), new NullCorrelationIdHelper()), new MessageSerialiser<Guid>(), new BusHelper(new ConfigurationManager()), new ConfigurationManager(), null), new BusHelper(new ConfigurationManager()));
58 : var handler = new TestCommandSuccessHandler(testResponse);
59 : azureCommandBusReceiver.RegisterHandler<TestCommand>(handler.Handle, handler.GetType());
60 : azureCommandBusReceiver.Start();
61 :
62 : var azureCommandBusPublisher = new AzureCommandBusPublisher<Guid>(new ConfigurationManager(), new MessageSerialiser<Guid>(), new GuidSingleSignOnTokenValueHelper(), new NullCorrelationIdHelper(), new ConsoleLogger(new LoggerSettingsConfigurationSection(), new NullCorrelationIdHelper()), new AzureBusHelper<Guid>(new GuidSingleSignOnTokenValueHelper(), new NullCorrelationIdHelper(), new ConsoleLogger(new LoggerSettingsConfigurationSection(), new NullCorrelationIdHelper()), new MessageSerialiser<Guid>(), new BusHelper(new ConfigurationManager()), new ConfigurationManager(), null), new BusHelper(new ConfigurationManager()));
63 :
64 : // Act
65 : azureCommandBusPublisher.Send(command);
66 :
67 : // Assert
68 : SpinWait.SpinUntil(() => testResponse[processId].Item1);
69 : Assert.IsNull(testResponse[processId].Item2);
70 : }
71 : }
72 :
73 : public class TestEventSuccessHandler : IMessageHandler<TestEvent>
74 0 : {
75 0 : public TestEventSuccessHandler(IDictionary<Guid, Tuple<bool, Exception>> testResponse)
76 : {
77 : TestResponse = testResponse;
78 : }
79 :
80 : protected IDictionary<Guid, Tuple<bool, Exception>> TestResponse { get; private set; }
81 :
82 : #region Implementation of IHandler<in TestEvent>
83 :
84 0 : public void Handle(TestEvent message)
85 : {
86 : TestResponse[message.Id] = new Tuple<bool, Exception>(true, null);
87 : }
88 :
89 : #endregion
90 : }
91 :
92 : public class TestCommandSuccessHandler : IMessageHandler<TestCommand>
93 0 : {
94 0 : public TestCommandSuccessHandler(IDictionary<Guid, Tuple<bool, Exception>> testResponse)
95 : {
96 : TestResponse = testResponse;
97 : }
98 :
99 : protected IDictionary<Guid, Tuple<bool, Exception>> TestResponse { get; private set; }
100 :
101 : #region Implementation of IHandler<in TestCommand>
102 :
103 0 : public void Handle(TestCommand message)
104 : {
105 : TestResponse[message.Id] = new Tuple<bool, Exception>(true, null);
106 : }
107 :
108 : #endregion
109 : }
110 : }
|