Esempio n. 1
0
        public void DispatchDeferred_RaiseDeferredEvents_EventArePublished(int eventsCount)
        {
            var notifications = new List <TestNotification>();

            for (int i = 0; i < eventsCount; i++)
            {
                var notification = new TestNotification();

                _eventDispatcher.DispatchDeferred(notification);

                notifications.Add(notification);
            }

            _eventDispatcher.RaiseDeferredEvents();

            foreach (var testNotification in notifications)
            {
                _mediator.Received(1).Publish(testNotification);
            }

            _mediator.Received(eventsCount).Publish(Arg.Any <IEvent>());
        }
Esempio n. 2
0
        public async Task NotificationDispatcher_Unsubscribe_NotDispatchesNotification()
        {
            // Given
            using var dispatcher = new TestNotificationDispatcher(new NullLogger <NotificationDispatcher <TestNotification, ITestNotificationSubscriber> >());
            var subscriber = Substitute.For <ITestNotificationSubscriber>();

            subscriber.UniqueId.Returns(Guid.NewGuid());
            subscriber.Callback(Arg.Any <TestNotification>()).Returns(Task.CompletedTask);

            var notification = new TestNotification();

            // When
            dispatcher.Subscribe(subscriber);

            dispatcher.Dispatch(notification, CancellationToken.None);
            Thread.Yield();

            dispatcher.Unsubscribe(subscriber);

            // Then
            await(subscriber.Received(1).Callback(notification) ?? Task.CompletedTask);
        }
Esempio n. 3
0
        private void ReadUserInput()
        {
            while (true)
            {
                Console.Write(@"Publisher Demo:\>");
                var option = Console.ReadLine();
                switch (option?.ToLower())
                {
                case "cls":
                    Console.Clear();
                    break;

                case "1":
                    var notification = new TestNotification
                    {
                        Id   = Guid.NewGuid(),
                        Name = "test mediator"
                    };
                    this.eventBus.Publish(notification);
                    Console.WriteLine("Event published!");
                    break;

                case "opt":
                    PrintOptionsMenu();
                    break;

                case "x":
                    Environment.Exit(0);
                    break;

                default:
                    Console.WriteLine("Unknown command.");
                    Console.WriteLine();
                    PrintOptionsMenu();
                    break;
                }
            }
        }
Esempio n. 4
0
        public async Task ShouldPublish()
        {
            //Arrange
            var publishAsyncReturns = new PublishResponse()
            {
                HttpStatusCode = HttpStatusCode.OK
            };
            var options = new NotificationOptions()
            {
                Region = "us-east-1", ClientId = "123456789012"
            };
            var findTopicAsyncReturns = new Topic();

            var amazonSnsMock = new Mock <IAmazonSimpleNotificationService>();

            amazonSnsMock.Setup(x => x.PublishAsync(It.IsAny <string>(), It.IsAny <string>(), default))
            .ReturnsAsync(publishAsyncReturns).Verifiable();

            var notification = new TestNotification {
                Message = Guid.NewGuid().ToString()
            };

            var notificationAttributesReaderMock = new Mock <INotificationAttributesReader>();

            notificationAttributesReaderMock.Setup(x => x.GetTopicName(It.IsAny <Type>()))
            .Returns($"{nameof(TestNotification)}Topic");

            var notificationSns = new NotificationSns(amazonSnsMock.Object, Options.Create(options), notificationAttributesReaderMock.Object);


            //Act
            await notificationSns.Publish(notification);

            //Assert
            amazonSnsMock.VerifyAll();
        }
 public void Test(TestNotification notification)
 {
 }
        public async Task HandleAsync(TestNotification _, CancellationToken cancellationToken)
        {
            await Task.Delay(TimeSpan.FromMilliseconds(1), cancellationToken).ConfigureAwait(false);

            MessageReceivedCount++;
        }
 public void Handle(TestNotification _, CancellationToken __) => MessageReceivedCount++;
 public void Handle(TestNotification _) => MessageReceivedCount++;
Esempio n. 9
0
 public int HandleReturnsInt(TestNotification _) => MessageReceivedCount++;
Esempio n. 10
0
 public void HandleOptional2(TestNotification _, CancellationToken __ = default) => MessageReceivedCount++;
Esempio n. 11
0
 public void Handle(TestNotification _, CancellationToken __, TestConventionClient1Cancellation ___) => MessageReceivedCount++;
 internal void ReceiveTestNotification(TestNotification @event)
 {
     TestNotificationResetEvent.Set();
 }