本文整理汇总了C#中Connected.PublishAsync方法的典型用法代码示例。如果您正苦于以下问题:C# Connected.PublishAsync方法的具体用法?C# Connected.PublishAsync怎么用?C# Connected.PublishAsync使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Connected
的用法示例。
在下文中一共展示了Connected.PublishAsync方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PublishAsync_Where_No_Publication_Configurations_Which_Results_In_A_NoConfigurationFound_Result
public void PublishAsync_Where_No_Publication_Configurations_Which_Results_In_A_NoConfigurationFound_Result()
{
var _busConfigurationBuilder = new BusConfigurationBuilder();
_busConfigurationBuilder.ConnectionUris.Add(TestingConfiguration.LocalConnectionUri);
var _busConfirguration = _busConfigurationBuilder.Build();
var _connectionManager = Substitute.For<IConnectionManager>();
var _context = Substitute.For<IBusContext>();
var _SUT = new Connected(
_busConfirguration,
_connectionManager,
_context);
var _theEvent = new MyEvent(Guid.NewGuid(), null, "Some detail", 1);
var _publicationResult = _SUT.PublishAsync(_theEvent);
_publicationResult.Wait();
Assert.AreEqual(PMCG.Messaging.PublicationResultStatus.NoConfigurationFound, _publicationResult.Result.Status);
}
示例2: PublishAsync_Where_A_Single_Publication_Configuration_Which_Results_In_A_Successfull_Publication
public void PublishAsync_Where_A_Single_Publication_Configuration_Which_Results_In_A_Successfull_Publication()
{
var _busConfigurationBuilder = new BusConfigurationBuilder();
_busConfigurationBuilder.ConnectionUris.Add(TestingConfiguration.LocalConnectionUri);
_busConfigurationBuilder
.RegisterPublication<MyEvent>(
TestingConfiguration.ExchangeName,
typeof(MyEvent).Name);
var _busConfirguration = _busConfigurationBuilder.Build();
var _connectionManager = Substitute.For<IConnectionManager>();
var _connection = Substitute.For<IConnection>();
var _channel = Substitute.For<IModel>();
var _context = Substitute.For<IBusContext>();
var _waitHandle = new AutoResetEvent(false);
_connectionManager.Connection.Returns(_connection);
_connection.CreateModel().Returns(_channel);
_channel.NextPublishSeqNo.Returns(1UL);
_channel
.When(channel => channel.BasicPublish(Arg.Any<string>(), Arg.Any<string>(), Arg.Any<IBasicProperties>(), Arg.Any<byte[]>()))
.Do(callInfo => _waitHandle.Set());
var _SUT = new Connected(
_busConfirguration,
_connectionManager,
_context);
var _theEvent = new MyEvent(Guid.NewGuid(), null, "Some detail", 1);
var _publicationResult = _SUT.PublishAsync(_theEvent);
_waitHandle.WaitOne(); // Allow publication to complete
_channel.BasicAcks += Raise.Event<BasicAckEventHandler>(_channel, new BasicAckEventArgs { Multiple = true, DeliveryTag = 10 });
_publicationResult.Wait();
Assert.AreEqual(PMCG.Messaging.PublicationResultStatus.Published, _publicationResult.Result.Status);
}
示例3: PublishAsync_Where_Connection_Is_Disconnected_Results_In_A_Non_Published_Result
public void PublishAsync_Where_Connection_Is_Disconnected_Results_In_A_Non_Published_Result()
{
var _busConfigurationBuilder = new BusConfigurationBuilder();
_busConfigurationBuilder.ConnectionUris.Add(TestingConfiguration.LocalConnectionUri);
_busConfigurationBuilder
.RegisterPublication<MyEvent>(
TestingConfiguration.ExchangeName,
typeof(MyEvent).Name);
var _busConfirguration = _busConfigurationBuilder.Build();
var _connectionManager = Substitute.For<IConnectionManager>();
var _connection = Substitute.For<IConnection>();
var _channel = Substitute.For<IModel>();
var _context = Substitute.For<IBusContext>();
_connectionManager.Connection.Returns(_connection);
_connection.CreateModel().Returns(_channel);
var _SUT = new Connected(
_busConfirguration,
_connectionManager,
_context);
_context.State.Returns(callInfo => _SUT);
_connectionManager.Disconnected += Raise.Event<EventHandler<ConnectionDisconnectedEventArgs>>(_connection, new ConnectionDisconnectedEventArgs(1, "."));
var _theEvent = new MyEvent(Guid.NewGuid(), null, "Some detail", 1);
var _publicationResult = _SUT.PublishAsync(_theEvent);
_publicationResult.Wait();
Assert.AreEqual(PMCG.Messaging.PublicationResultStatus.NotPublished, _publicationResult.Result.Status);
}
示例4: BusConfigurationBuilder
public void State_Changed_Where_Connection_Is_Disconnected_And_A_Pending_Publication_Results_In_Pending_Publication_Task_Completion()
{
var _busConfigurationBuilder = new BusConfigurationBuilder();
_busConfigurationBuilder.ConnectionUris.Add(TestingConfiguration.LocalConnectionUri);
_busConfigurationBuilder.NumberOfPublishers = 1; // Only one publisher
_busConfigurationBuilder
.RegisterPublication<MyEvent>(
TestingConfiguration.ExchangeName,
typeof(MyEvent).Name);
var _busConfirguration = _busConfigurationBuilder.Build();
var _connectionManager = Substitute.For<IConnectionManager>();
var _connection = Substitute.For<IConnection>();
var _channel = Substitute.For<IModel>();
var _context = Substitute.For<IBusContext>();
_connectionManager.Connection.Returns(_connection);
_connection.CreateModel().Returns(_channel);
_channel.NextPublishSeqNo.Returns(1UL, 2UL);
_channel
.When(channel => channel.BasicPublish(Arg.Any<string>(), Arg.Any<string>(), Arg.Any<IBasicProperties>(), Arg.Any<byte[]>()))
.Do(callInfo => { Thread.Sleep(1000); }); // Slow down so second publication will not get a chance to be published as we have only one publisher - therefore only one queue consumer
var _SUT = new Connected(
_busConfirguration,
_connectionManager,
_context);
var _theEvent = new MyEvent(Guid.NewGuid(), null, "Some detail", 1);
var _publicationResult1 = _SUT.PublishAsync(_theEvent);
var _publicationResult2 = _SUT.PublishAsync(_theEvent);
_context.State.Returns(callInfo => _SUT);
State _capturedState = null;
_context.When(context => context.State = Arg.Any<State>()).Do(callInfo => _capturedState = callInfo[0] as State);
_connectionManager.Disconnected += Raise.Event<EventHandler<ConnectionDisconnectedEventArgs>>(_connection, new ConnectionDisconnectedEventArgs(1, "."));
Assert.IsNotNull(_publicationResult1);
Assert.IsNotNull(_capturedState);
_publicationResult2.Wait(); // Second never gets pulled from queue due to slow BasicPublish on first message
Assert.AreEqual(PMCG.Messaging.PublicationResultStatus.NotPublished, _publicationResult2.Result.Status);
}