Пример #1
0
        public void RunAddAlarmTest()
        {
            //initialize
            Mock <IDeviceRepository>    deviceRepoMock    = new Mock <IDeviceRepository>();
            Mock <ITelemetryRepository> telemetryRepoMock = new Mock <ITelemetryRepository>();
            Mock <IFreezeRepository>    freezeReop        = new Mock <IFreezeRepository>();


            int minMin = 1 * 60 + 5;
            int minMax = 2 * 60 + 5;

            deviceRepoMock.Setup(o => o.GetFailsCommunicationBetween(minMin, minMax)).Returns(deviceList);

            DeviceService       deviceService       = new DeviceService(deviceRepoMock.Object, telemetryRepoMock.Object);
            AlarmService        alarmService        = new AlarmService(deviceRepoMock.Object, freezeReop.Object);
            NotificationService notificationService = new NotificationService(deviceRepoMock.Object);

            Mock <ILogger>            logger = new Mock <ILogger>();
            CommunicationStateService communicationStateService = new CommunicationStateService(deviceService, alarmService, notificationService, logger.Object);

            //execute
            communicationStateService.Run(1, 2, Alarm.Gravity.Information);

            //tests

            // TODO : check tests (error)
            deviceRepoMock.Verify(o => o.UpdateStatusAlarm("1", It.IsAny <Alarm>()), Times.Never);
            deviceRepoMock.Verify(o => o.AddAlarm("1", It.IsAny <Alarm>()), Times.Once);
        }
        public static void Run([TimerTrigger("0 5 */4 * * *")] TimerInfo myTimer, TraceWriter log)
        {
            log.Info($"C# Timer trigger function executed at: {DateTime.Now}");
            DependencyInjection.ConfigureInjection(log);

            using (var scope = DependencyInjection.Container.BeginLifetimeScope())
            {
                CommunicationStateService service = scope.Resolve <CommunicationStateService>();
                service.Run(4, 5, Models.Alarm.Gravity.Serious);
            }
        }
Пример #3
0
        public void RunAddWithUpdateStatusAlarmTest()
        {
            //initialize
            Mock <IDeviceRepository>    deviceRepoMock    = new Mock <IDeviceRepository>();
            Mock <ITelemetryRepository> telemetryRepoMock = new Mock <ITelemetryRepository>();
            Mock <IFreezeRepository>    freezeReop        = new Mock <IFreezeRepository>();

            alarmsList = new List <Alarm>
            {
                new Alarm
                {
                    Id           = "1",
                    AlarmType    = Alarm.Type.CommuniationFailure,
                    AlarmGravity = Alarm.Gravity.Information,
                    Description  = "",
                    IsActive     = true,
                    DeviceId     = "1",
                    OccuredAt    = DateTime.UtcNow,
                    SiteId       = "1"
                },
            };
            deviceList[0].Alarms = alarmsList;


            int minMin = 7 * 60 + 5;

            deviceRepoMock.Setup(o => o.GetFailsCommunicationBetween(minMin, null)).Returns(deviceList);

            DeviceService       deviceService       = new DeviceService(deviceRepoMock.Object, telemetryRepoMock.Object);
            AlarmService        alarmService        = new AlarmService(deviceRepoMock.Object, freezeReop.Object);
            NotificationService notificationService = new NotificationService(deviceRepoMock.Object);
            Mock <ILogger>      logger = new Mock <ILogger>();

            CommunicationStateService communicationStateService = new CommunicationStateService(deviceService, alarmService, notificationService, logger.Object);

            //execute
            communicationStateService.Run(7, null, Alarm.Gravity.Serious);

            //tests

            // TODO : check tests (error)
            deviceRepoMock.Verify(o => o.UpdateStatusAlarm("1", It.IsAny <Alarm>()), Times.Once);
            deviceRepoMock.Verify(o => o.AddAlarm("1", It.IsAny <Alarm>()), Times.Once);
        }