示例#1
0
        public void Should_Throw_When_Creating_Monitor_With_Existing_Name()
        {
            MockExternalLinks();

            var userAndOrg = new UserAndOrganizationDto
            {
                OrganizationId = 2,
                UserId         = "1"
            };
            var monitor = new MonitorDto {
                Name = "Test1"
            };

            var ex = Assert.ThrowsAsync <ValidationException>(async() => await _monitorService.CreateMonitorAsync(monitor, userAndOrg));

            Assert.That(ex.ErrorCode, Is.EqualTo(ErrorCodes.DuplicatesIntolerable));
        }
示例#2
0
        public async Task Should_Create_New_Monitor()
        {
            MockExternalLinks();

            var userAndOrg = new UserAndOrganizationDto
            {
                OrganizationId = 2,
                UserId         = "1"
            };

            var monitor = new MonitorDto {
                Name = "Test4"
            };

            await _monitorService.CreateMonitorAsync(monitor, userAndOrg);

            _monitorsDbSet.Received(1).Add(Arg.Any <Monitor>());
        }
示例#3
0
        public async Task Should_Update_Monitor()
        {
            MockExternalLinks();

            var userAndOrg = new UserAndOrganizationDto
            {
                OrganizationId = 2,
                UserId         = "1"
            };

            var monitor = new MonitorDto {
                Name = "Test4", Id = 1
            };

            await _monitorService.UpdateMonitorAsync(monitor, userAndOrg);

            await _uow.Received(1).SaveChangesAsync(false);
        }
示例#4
0
        public void Should_Throw_When_Updating_Not_Existing_Monitor()
        {
            MockExternalLinks();

            var userAndOrg = new UserAndOrganizationDto
            {
                OrganizationId = 2,
                UserId         = "1"
            };

            var monitor = new MonitorDto {
                Name = "Test2", Id = 5
            };

            var ex = Assert.ThrowsAsync <ValidationException>(async() => await _monitorService.UpdateMonitorAsync(monitor, userAndOrg));

            Assert.That(ex.ErrorCode, Is.EqualTo(ErrorCodes.ContentDoesNotExist));
        }
示例#5
0
        public async Task CreateMonitorAsync(MonitorDto newMonitor, UserAndOrganizationDto userAndOrganizationDto)
        {
            if (await _monitorsDbSet.AnyAsync(x => x.Name == newMonitor.Name &&
                                              x.OrganizationId == userAndOrganizationDto.OrganizationId))
            {
                throw new ValidationException(ErrorCodes.DuplicatesIntolerable, "Monitor names should be unique");
            }

            var timestamp = DateTime.UtcNow;
            var monitor   = new Monitor
            {
                Created        = timestamp,
                Modified       = timestamp,
                CreatedBy      = userAndOrganizationDto.UserId,
                ModifiedBy     = userAndOrganizationDto.UserId,
                Name           = newMonitor.Name,
                OrganizationId = userAndOrganizationDto.OrganizationId
            };

            _monitorsDbSet.Add(monitor);
            await _uow.SaveChangesAsync(false);
        }
示例#6
0
        public async Task UpdateMonitorAsync(MonitorDto monitorDto, UserAndOrganizationDto userAndOrganizationDto)
        {
            var monitor = await _monitorsDbSet.FirstOrDefaultAsync(x => x.Id == monitorDto.Id &&
                                                                   x.OrganizationId == userAndOrganizationDto.OrganizationId);

            if (monitor == null)
            {
                throw new ValidationException(ErrorCodes.ContentDoesNotExist, "Monitor does not exist");
            }

            var nameAlreadyExist = await _monitorsDbSet.AnyAsync(x => x.Name == monitorDto.Name &&
                                                                 x.OrganizationId == userAndOrganizationDto.OrganizationId);

            if (monitorDto.Name != monitor.Name && nameAlreadyExist)
            {
                throw new ValidationException(ErrorCodes.DuplicatesIntolerable, "Monitor names should be unique");
            }

            monitor.Name       = monitorDto.Name;
            monitor.Modified   = DateTime.UtcNow;
            monitor.ModifiedBy = userAndOrganizationDto.UserId;

            await _uow.SaveChangesAsync(false);
        }
示例#7
0
        private async Task DeleteMonitorAsync(MonitorDto input)
        {
            await MonitorAppService.DeleteAsync(input.Id);

            await GetMonitorAsync();
        }
示例#8
0
 private void OpenEditMonitorModal(MonitorDto input)
 {
     EditingMonitorId = input.Id;
     EditingMonitor   = ObjectMapper.Map <MonitorDto, UpdateMonitorDto>(input);
     EditMonitorModal.Show();
 }
示例#9
0
 private void OpenDetailMonitor(MonitorDto input)
 {
     NavigationManager.NavigateTo($"monitor-details/{input.Id}");
 }