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)); }
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>()); }
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); }
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)); }
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); }
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); }
private async Task DeleteMonitorAsync(MonitorDto input) { await MonitorAppService.DeleteAsync(input.Id); await GetMonitorAsync(); }
private void OpenEditMonitorModal(MonitorDto input) { EditingMonitorId = input.Id; EditingMonitor = ObjectMapper.Map <MonitorDto, UpdateMonitorDto>(input); EditMonitorModal.Show(); }
private void OpenDetailMonitor(MonitorDto input) { NavigationManager.NavigateTo($"monitor-details/{input.Id}"); }