public async Task RecordAsync(NcMonitor monitor, MonitorResult result)
        {
            var record = monitorManager.LastOpenedMonitorRecord(monitor.Id);

            if (result.IsSuccess)
            {
                if ((record != null && record.EndDate == null) || monitor.StatusEnum() != MonitorStatus.OK)
                {//ukonceni zaznamu
                    if (record != null)
                    {
                        await monitorManager.UpdateEndDateAsync(record, DateTime.Now);
                    }

                    await notificator.AddNotifyUpAsync(monitor);//poslani notifikace o tom ze web bezi, staci poslat pouze jendou.

                    await monitorManager.SetStatusAndResetLastTestCycleIntervalAsync(monitor, MonitorStatus.OK);
                }
            }
            else
            {     //nastala chyba
                if (record == null || record.EndDate != null || monitor.StatusEnum() != MonitorStatus.Error)
                { //neexistuje zadny zaznam nebo jsou vsechny uzavreny
                    await monitorManager.SetStatusAndResetLastTestCycleIntervalAsync(monitor, MonitorStatus.Error);
                    await AddNewRecordAsync(monitor, result);
                }

                //posilani notifikaci se provadi stale dokud je monitor v chybovem stavu
                await notificator.AddNotifyDownAsync(monitor);
            }
        }
        public async Task SetLastTestCycleIntervalsAsync()
        {
            // Arrange
            var expectedTimeSpan = new TimeSpan(2, 40, 42);
            var expectedStatus   = MonitorStatus.OK;

            var monitor = new NcMonitor
            {
                LastTestCycleInterval = It.IsAny <TimeSpan>(),
                StatusId = (int)expectedStatus,
            };

            var monitorRepo = new Mock <IMonitorRepository>();

            IMonitorManager monitorManager = new MonitorManager(
                It.IsAny <IChannelRepository>(),
                monitorRepo.Object,
                It.IsAny <IRecordRepository>(),
                It.IsAny <IScenarioRepository>());

            // Act
            await monitorManager.SetLastTestCycleIntervalsAsync(
                monitor, expectedTimeSpan);// TimeSpan je struct, neni potreba vytvaret novou referenci

            // Assert
            monitorRepo.Verify(x => x.UpdateAsyncWithoutResetTestCycleInterval(monitor), Times.Once());
            Assert.Equal(expectedTimeSpan, monitor.LastTestCycleInterval);
            Assert.Equal(expectedStatus, monitor.StatusEnum());
        }
        public async Task SetStatusAndResetLastTestCycleIntervalAsync(
            MonitorStatus oldStatus,
            MonitorStatus newStatus)
        {
            // Arrange
            var monitor = new NcMonitor
            {
                StatusId = (int)oldStatus,
                LastTestCycleInterval = new TimeSpan(2, 3, 4),
            };

            var monitorRepo = new Mock <IMonitorRepository>();

            IMonitorManager monitorManager = new MonitorManager(
                It.IsAny <IChannelRepository>(),
                monitorRepo.Object,
                It.IsAny <IRecordRepository>(),
                It.IsAny <IScenarioRepository>());

            // Act
            await monitorManager.SetStatusAndResetLastTestCycleIntervalAsync(
                monitor,
                newStatus);

            // Assert
            monitorRepo.Verify(x => x.UpdateAsync(monitor), Times.Once());
            Assert.Equal(new TimeSpan?(), monitor.LastTestCycleInterval);
            Assert.Equal(newStatus, monitor.StatusEnum());
        }
        public async Task SetStatusAndResetLastTestCycleIntervalAsync(NcMonitor monitor, MonitorStatus status)
        {
            if (monitor.StatusEnum() != MonitorStatus.InActive)
            {
                monitor.StatusId = (int)status;
            }

            monitor.LastTestCycleInterval = null;
            await monitorRepository.UpdateAsync(monitor);
        }