public async Task ShouldBatchInitialUpEventNotifications()
        {
            var queuedActions = new List <Action>();

            _bgExec.When(bge => bge.ExecuteDelayed(Arg.Any <Action>(), 2500))
            .Do(ci =>
            {
                queuedActions.Add(ci.Arg <Action>());
            });
            HttpRequestMessage message = null;

            _httpHandler.When(h => h.RealSendAsync(Arg.Any <HttpRequestMessage>(), Arg.Any <CancellationToken>()))
            .Do(ci =>
            {
                message = ci.Arg <HttpRequestMessage>();
            });

            _service.NotifyUp(new Endpoint {
                Name = "A"
            }, null);
            _service.NotifyUp(new Endpoint {
                Name = "B"
            }, null);
            _service.NotifyUp(new Endpoint {
                Name = "C"
            }, null);

            queuedActions.ForEach(a => a.Invoke());

            await _httpHandler.Received(1).RealSendAsync(Arg.Any <HttpRequestMessage>(), Arg.Any <CancellationToken>());

            Assert.AreEqual("https://webhook.example.com/hook", message.RequestUri.ToString());
            Assert.AreEqual(@"{""text"":""The following endpoints are up: `A`, `B`, `C`. Hooray!""}", await message.Content.ReadAsStringAsync());
        }
Exemple #2
0
        public void Setup()
        {
            _notifier1 = Substitute.For <INotificationService>();
            _notifier2 = Substitute.For <INotificationService>();
            _bgExec    = Substitute.For <BackgroundExecutionWrapper>();
            _service   = new AggregateNotificationService(new List <INotificationService> {
                _notifier1, _notifier2
            }, _bgExec);

            _bgExec.When(bgx => bgx.Execute(Arg.Any <Action>()))
            .Do(ci =>
            {
                var action = ci.Arg <Action>();
                action.Invoke();
            });
        }