public void FollowUpNotificationOnAcknowledgementTimeout()
        {
            // Set up
            _persistenceAdapterMock.Setup(m => m.RetrieveMonitoredService(MONITORED_SERVICE_ID))
            .Returns(GetMonitoredService(isHealthy: false, escalationLevel: ESCALATION_LEVEL_2));
            _persistenceAdapterMock.Setup(m => m.UpdateEscalationLevel(MONITORED_SERVICE_ID, ESCALATION_LEVEL_3));

            _escalationPolicyAdapterMock
            .Setup(m => m.RetrieveEscalationPolicy(SERVICE_ID))
            .Returns(GetEscalationPolicy());

            _emailAdapaterMock.Setup(m => m.SendEmail(ESCALATION_LEVEL_EMAIL_3));

            _timerAdapterMock.Setup(m => m.CreateTimer(MONITORED_SERVICE_ID, _timer15min));

            // Act
            var pager = new PagerService(_persistenceAdapterMock.Object, _escalationPolicyAdapterMock.Object, _timerAdapterMock.Object,
                                         _emailAdapaterMock.Object, _smsAdapaterMock.Object) as IPagerService;

            pager.AcknowledgmentTimeout(MONITORED_SERVICE_ID);

            // Assert
            _persistenceAdapterMock.Verify(m => m.RetrieveMonitoredService(MONITORED_SERVICE_ID), Times.Once);
            _persistenceAdapterMock.Verify(m => m.UpdateEscalationLevel(MONITORED_SERVICE_ID, ESCALATION_LEVEL_3), Times.Once);
            _escalationPolicyAdapterMock.Verify(m => m.RetrieveEscalationPolicy(SERVICE_ID), Times.Once);
            _emailAdapaterMock.Verify(m => m.SendEmail(ESCALATION_LEVEL_EMAIL_3), Times.Once);
            _timerAdapterMock.Verify(m => m.CreateTimer(MONITORED_SERVICE_ID, _timer15min), Times.Once);
        }
Exemple #2
0
 protected void Previous()
 {
     PagerService.OnNext(new Pager {
         CurrentPage = --PagerService.Value.CurrentPage
     });
     DisabledButtons();
 }
        public void NewAlertForMonitoredService()
        {
            // Set Up
            _persistenceAdapterMock.Setup(m => m.CreateOrRetrieveMonitoredService(SERVICE_ID)).Returns(GetMonitoredService());
            _persistenceAdapterMock.Setup(m => m.UpdateHealthStatus(MONITORED_SERVICE_ID, false));

            _escalationPolicyAdapterMock
            .Setup(m => m.RetrieveEscalationPolicy(SERVICE_ID))
            .Returns(GetEscalationPolicy());

            _emailAdapaterMock.Setup(m => m.SendEmail(ESCALATION_LEVEL_EMAIL_1));

            _timerAdapterMock.Setup(m => m.CreateTimer(MONITORED_SERVICE_ID, _timer15min));

            // Act
            var pager = new PagerService(_persistenceAdapterMock.Object, _escalationPolicyAdapterMock.Object, _timerAdapterMock.Object,
                                         _emailAdapaterMock.Object, _smsAdapaterMock.Object) as IPagerService;

            pager.Alert(GetAlert());

            // Assert

            _persistenceAdapterMock.Verify(m => m.UpdateHealthStatus(MONITORED_SERVICE_ID, false), Times.Once);
            _persistenceAdapterMock.Verify(m => m.CreateOrRetrieveMonitoredService(SERVICE_ID), Times.Once);
            _escalationPolicyAdapterMock.Verify(m => m.RetrieveEscalationPolicy(SERVICE_ID), Times.Once);
            _emailAdapaterMock.Verify(m => m.SendEmail(ESCALATION_LEVEL_EMAIL_1), Times.Once);
            _timerAdapterMock.Verify(m => m.CreateTimer(MONITORED_SERVICE_ID, _timer15min), Times.Once);
        }
Exemple #4
0
 protected void Next()
 {
     PagerService.OnNext(new Pager {
         CurrentPage = ++PagerService.Value.CurrentPage
     });
     DisabledButtons();
 }
        static void Main(string[] args)
        {
            /*
             * // Delegates
             #region Delegates as Method Param
             * var rechenOperation = new RechenOperation(Add);
             * rechenOperation(10, 9);
             *
             * var cleanUp = new CleanUp(CleanUpImplementation);
             * DoSomething(cleanUp);
             #endregion
             *
             #region Linq & Lambdas
             * var list = Enumerable
             *  .Range(1, 100)
             *  .Where(x => x % 2 == 0)
             *  .Average();
             *
             * var sum = 0;
             * var cnt = 1;
             * for (int i = 1; i < 100; i++)
             *  if (i % 2 == 0)
             *  {
             *      cnt++;
             *      sum += i;
             *  }
             *
             * // Average
             * Console.WriteLine(sum / cnt);
             #endregion
             */

            // Delegates & Events an einem Beispiel

            #region Delegates & Events

            var freiwilligeFeuerwehr = new FreiwilligeFeuerwehr();
            var einsatz = new Einsatz {
                Meldung = "Blitzeinschlag"
            };

            var pagerService     = new PagerService();
            var sirenenService   = new SirenenService();
            var messagingService = new MessagingService();

            freiwilligeFeuerwehr.AlarmiereFeuerwehr += pagerService.AlarmiereFeuerwehr;
            freiwilligeFeuerwehr.AlarmiereFeuerwehr += sirenenService.AlarmiereFeuerwehr;
            freiwilligeFeuerwehr.AlarmiereFeuerwehr += messagingService.AlarmiereFeuerwehr;
            freiwilligeFeuerwehr.AlarmiereFeuerwehr -= messagingService.AlarmiereFeuerwehr;

            freiwilligeFeuerwehr.Alarmiere(einsatz);

            #endregion
        }
        public void DuplicateAlertForMonitoredService()
        {
            //Set Up
            _persistenceAdapterMock.Setup(m => m.CreateOrRetrieveMonitoredService(SERVICE_ID))
            .Returns(GetMonitoredService(isHealthy: false));

            // Act
            var pager = new PagerService(_persistenceAdapterMock.Object, _escalationPolicyAdapterMock.Object, _timerAdapterMock.Object,
                                         _emailAdapaterMock.Object, _smsAdapaterMock.Object) as IPagerService;

            pager.Alert(GetAlert());

            // Assert
            _persistenceAdapterMock.Verify(m => m.CreateOrRetrieveMonitoredService(SERVICE_ID), Times.Once);
        }
Exemple #7
0
        public void GetDefaultPagedList_NoCount(int pageIndex)
        {
            var option = Options.Create(new PagerSetupOption
            {
                StartPageIndex  = pageIndex,
                DefaultPageSize = 10
            });

            var pager       = new PagerService(option);
            var orderedData = _list.AsQueryable().OrderBy(x => x.Seq);
            var rs          = pager.GetPagedList(orderedData, false);

            Assert.Equal(-1, rs.RecordCount);
            Assert.Equal(-1, rs.PageCount);
            Assert.Equal(orderedData.First().Seq, rs.Data.First().Seq);
        }
        public void MonitoredServiceAcknowledged()
        {
            // Set Up
            _persistenceAdapterMock.Setup(m => m.RetrieveMonitoredService(MONITORED_SERVICE_ID))
            .Returns(GetMonitoredService(isHealthy: false, escalationLevel: ESCALATION_LEVEL_2));
            _persistenceAdapterMock.Setup(m => m.Acknowledgement(MONITORED_SERVICE_ID));

            // Act
            var pager = new PagerService(_persistenceAdapterMock.Object, _escalationPolicyAdapterMock.Object, _timerAdapterMock.Object,
                                         _emailAdapaterMock.Object, _smsAdapaterMock.Object) as IPagerService;

            pager.Acknowledgment(MONITORED_SERVICE_ID);

            // Assert
            _persistenceAdapterMock.Verify(m => m.RetrieveMonitoredService(MONITORED_SERVICE_ID), Times.Once);
            _persistenceAdapterMock.Verify(m => m.Acknowledgement(MONITORED_SERVICE_ID), Times.Once);
        }
Exemple #9
0
        static void Main(string[] args)
        {
            var video = new Video()
            {
                Title = "Batman Returns, Again 2021"
            };
            var videoEncoder = new VideoEncoder(); // Publisher
            var mailService  = new MailService();  // subscriber
            var smsService   = new SMSService();   // another publisher
            var pageService  = new PagerService(); // another publisher based on Interface

            // before we call the encode method we need to do the subscribtion, to add a pointer to the Videoencoded "list"
            videoEncoder.VideoEncoded += mailService.OnVideoEncodedMail; //mailService.OnVideoEncodedMail; is a reference(pointer) to that method NOT A METHOD CALL
            videoEncoder.VideoEncoded += smsService.OnVideoEncodedSMS;   // register another subscriber
            videoEncoder.VideoEncoded += pageService.OnVideoEncodedPager;
            videoEncoder.Encode(video);
        }
        public void HealthyEventFollowedByAcknowledgementTimeoutSetToHealthy()
        {
            // Set Up
            _persistenceAdapterMock.Setup(m => m.RetrieveMonitoredService(MONITORED_SERVICE_ID))
            .Returns(GetMonitoredService(isHealthy: false));
            _persistenceAdapterMock.Setup(m => m.UpdateHealthStatus(MONITORED_SERVICE_ID, true));

            //Act
            var pager = new PagerService(_persistenceAdapterMock.Object, _escalationPolicyAdapterMock.Object, _timerAdapterMock.Object,
                                         _emailAdapaterMock.Object, _smsAdapaterMock.Object) as IPagerService;

            pager.UpdateHealthStatus(GetHealthyEvent());
            pager.AcknowledgmentTimeout(MONITORED_SERVICE_ID);

            //Assert
            _persistenceAdapterMock.Verify(m => m.RetrieveMonitoredService(MONITORED_SERVICE_ID), Times.Once);
            _persistenceAdapterMock.Verify(m => m.UpdateHealthStatus(MONITORED_SERVICE_ID, true), Times.Once);
        }
Exemple #11
0
        static void Main(string[] args)
        {
            var video = new Video()
            {
                Title = "Lord of the Rings"
            };
            var videoEncoder   = new VideoEncoder();   // publisher
            var mailService    = new MailService();    // subscriber
            var messageService = new MessageService(); // subscriber
            var pagerService   = new PagerService();   // subsriber

            videoEncoder.VideoEncoded += mailService.OnVideoEncoded;
            videoEncoder.VideoEncoded += messageService.OnVideoEncoded;
            videoEncoder.VideoEncoded += pagerService.OnVideoEncoded;


            videoEncoder.Encode(video);
        }
Exemple #12
0
        public void GetDefaultPagedList_OutRange(int pageIndex)
        {
            var option = Options.Create(new PagerSetupOption
            {
                StartPageIndex  = pageIndex,
                DefaultPageSize = 10
            });

            var pager       = new PagerService(option);
            var orderedData = _list.AsQueryable().OrderBy(x => x.Seq);
            var rs          = pager.GetPagedList(orderedData, new PagerParams
            {
                PageIndex = pageIndex + 12,
                PageSize  = 10
            });

            Assert.Equal(100, rs.RecordCount);
            Assert.Equal(10, rs.PageCount);
            Assert.Empty(rs.Data);
        }
        public void NotifyAllTargets()
        {
            // Set up
            _persistenceAdapterMock.Setup(m => m.RetrieveMonitoredService(MONITORED_SERVICE_ID))
            .Returns(GetMonitoredService(isHealthy: false, escalationLevel: ESCALATION_LEVEL_1));
            _persistenceAdapterMock.Setup(m => m.UpdateEscalationLevel(MONITORED_SERVICE_ID, ESCALATION_LEVEL_2));

            _escalationPolicyAdapterMock
            .Setup(m => m.RetrieveEscalationPolicy(SERVICE_ID))
            .Returns(GetEscalationPolicy());

            _emailAdapaterMock.Setup(m => m.SendEmail(ESCALATION_LEVEL_EMAIL_1));
            _emailAdapaterMock.Setup(m => m.SendEmail(ESCALATION_LEVEL_EMAIL_2));

            _smsAdapaterMock.Setup(m => m.SendSms(ESCALATION_LEVEL_SMS_1));
            _smsAdapaterMock.Setup(m => m.SendSms(ESCALATION_LEVEL_SMS_2));

            _timerAdapterMock.Setup(m => m.CreateTimer(MONITORED_SERVICE_ID, _timer15min));

            // Act
            var pager = new PagerService(_persistenceAdapterMock.Object, _escalationPolicyAdapterMock.Object, _timerAdapterMock.Object,
                                         _emailAdapaterMock.Object, _smsAdapaterMock.Object) as IPagerService;

            pager.AcknowledgmentTimeout(MONITORED_SERVICE_ID);

            // Assert
            _persistenceAdapterMock.Verify(m => m.RetrieveMonitoredService(MONITORED_SERVICE_ID), Times.Once);
            _persistenceAdapterMock.Verify(m => m.UpdateEscalationLevel(MONITORED_SERVICE_ID, ESCALATION_LEVEL_2), Times.Once);
            _escalationPolicyAdapterMock.Verify(m => m.RetrieveEscalationPolicy(SERVICE_ID), Times.Once);

            _emailAdapaterMock.Verify(m => m.SendEmail(It.IsAny <string>()), Times.Exactly(2));
            _emailAdapaterMock.Verify(m => m.SendEmail(ESCALATION_LEVEL_EMAIL_1), Times.Once);
            _emailAdapaterMock.Verify(m => m.SendEmail(ESCALATION_LEVEL_EMAIL_2), Times.Once);

            _smsAdapaterMock.Verify(m => m.SendSms(It.IsAny <string>()), Times.Exactly(2));
            _smsAdapaterMock.Verify(m => m.SendSms(ESCALATION_LEVEL_SMS_1), Times.Once);
            _smsAdapaterMock.Verify(m => m.SendSms(ESCALATION_LEVEL_SMS_2), Times.Once);

            _timerAdapterMock.Verify(m => m.CreateTimer(MONITORED_SERVICE_ID, _timer15min), Times.Once);
        }
Exemple #14
0
 public UIPaginationModel(int?currentPage, string searchString, int?sizePage, int totalItems)
 {
     _pager       = new PagerService(totalItems, currentPage.HasValue ? currentPage.Value : PaginationConstants.DefaultPage, sizePage.HasValue ? sizePage.Value : PaginationConstants.DefaultPageSize);
     SearchString = searchString;
 }