public async Task GivenSaveAuthenticationLog_WhenCorrectAuthenticationLogDataIsReceived_ThenShouldPersistLog() { var options = SqliteInMemory.CreateOptions <LoggingDbContext>(); await using var context = new LoggingDbContext(options); { await context.Database.EnsureCreatedAsync(); context.SeedAuthenticationLogs(); var authenticationLog = new AuthenticationLog { UserId = "001", MessageType = "UserRegisteredEvent", Timestamp = DateTime.Now, }; var authenticationLogCount = context.AuthenticationLogs.Count(); var loggingRepository = new AuthenticationLogRepository(context); await loggingRepository.SaveAuthenticationLog(authenticationLog); var updatedAuthenticationLogCount = context.AuthenticationLogs.Count(); Assert.Equal(authenticationLogCount + 1, updatedAuthenticationLogCount); } }
private static void SeedInternalErrorLogEntries(LoggingDbContext context) { if (!context.InternalErrorLogEntries.Any()) { context.InternalErrorLogEntries.AddRange(InternalErrorLogEntryFaker.Generate()); } if (!context.AccountLogEntries.Any()) { context.AccountLogEntries.AddRange(AccountLogEntryFaker.Generate()); } if (!context.PaymentLogEntries.Any()) { context.PaymentLogEntries.AddRange(PaymentLogEntryFaker.Generate()); } if (!context.SearchQueryLogEntries.Any()) { context.SearchQueryLogEntries.AddRange(SearchQueryLogEntryFaker.Generate()); } if (!context.TicketActionLogEntries.Any()) { context.TicketActionLogEntries.AddRange(TicketActionLogEntryFaker.Generate()); } if (!context.TicketDealLogEntries.Any()) { context.TicketDealLogEntries.AddRange(TicketDealLogEntryFaker.Generate()); } context.SaveChanges(); }
public async Task GivenSaveErrorLog_WhenCorrectDataReceived_ThenShouldPersistLog() { var options = SqliteInMemory.CreateOptions <LoggingDbContext>(); await using var context = new LoggingDbContext(options); { await context.Database.EnsureCreatedAsync(); context.SeedSingleErrorLog(); var errorLog = new ErrorLog { ErrorMessage = "Test ErrorCode Message", MessageType = "ErrorLog", Timestamp = DateTime.Now, UserId = "1010101" }; var currentErrorLogCount = context.ErrorLogs.Count(); var errorLogRepository = new ErrorLogRepository(context); await errorLogRepository.SaveErrorLog(errorLog); var updatedErrorLogCount = context.ErrorLogs.Count(); Assert.Equal(currentErrorLogCount + 1, updatedErrorLogCount); } }
private void Start() { LoggingEventEntity[] entities; lock (_lock) { entities = _loggingEvents.ToArray(); _loggingEvents.Clear(); } try { using var context = new LoggingDbContext(); context.Events.AddRange(entities); context.SaveChanges(); } catch (Exception e) { try { _logger.Value.LogError(e, "Error while Saving Log-Entitys"); } catch { // ignored } } }
public DbLogger(LoggingDbContext db, IEnumerable <ILoggerDataProvider> dataProviders, ILogger <DbLogger> aspCoreLogger, IOptionsSnapshot <LoggerOptions> logggerOptions) { _db = db; _dataProviders = dataProviders; _aspCoreLogger = aspCoreLogger; _options = logggerOptions.Value; }
public apiController(LakeLabDbContext context, LoggingDbContext logginContext, ValueStorage vs, DeviceStorage ds) { _dbContext = context; _loggingDbContext = logginContext; _valueStorage = vs; _deviceStorage = ds; }
public async Task Invoke(HttpContext httpContext, LoggingDbContext context) { if (httpContext.User.Identity.IsAuthenticated && httpContext.User.IsInRole("Users")) { context.UserRequests.Add(new Models.UserRequest(httpContext.User.Identity.Name, DateTime.Now)); await context.SaveChangesAsync(); } await _next.Invoke(httpContext); }
private async Task FillDatabase() { using var db = new LoggingDbContext(); await db.Events.AddRangeAsync( new LoggingEventEntity(new LogEvent(DateTimeOffset.Now, LogEventLevel.Warning, null, MessageTemplate.Empty, Array.Empty <LogEventProperty>())), new LoggingEventEntity(new LogEvent(DateTimeOffset.Now, LogEventLevel.Warning, null, MessageTemplate.Empty, Array.Empty <LogEventProperty>()))); await db.SaveChangesAsync(); }
public void Emit_Dispose_Test() { var testObject = GetTestingObject(); using (var provider = testObject.GetResolvedTestingObject()) provider.Emit(new LogEvent(DateTimeOffset.Now, LogEventLevel.Warning, null, MessageTemplate.Empty, Array.Empty <LogEventProperty>())); using var context = new LoggingDbContext(); Assert.Equal(1, context.Events.Count()); }
public void Emit_Autostart_Test() { var testObject = GetTestingObject(); var provider = testObject.GetResolvedTestingObject(); provider.Emit(new LogEvent(DateTimeOffset.Now, LogEventLevel.Warning, null, MessageTemplate.Empty, Array.Empty <LogEventProperty>())); provider.Emit(new LogEvent(DateTimeOffset.Now, LogEventLevel.Warning, null, MessageTemplate.Empty, Array.Empty <LogEventProperty>())); Thread.Sleep(TimeSpan.FromMilliseconds(5000)); using var context = new LoggingDbContext(); Assert.Equal(2, context.Events.Count()); }
public TestBase() { var options = new DbContextOptionsBuilder <LoggingDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; Context = new LoggingDbContext(options); Context.Database.EnsureCreated(); var mockMapper = new MapperConfiguration(cfg => { cfg.AddProfiles(typeof(AccountLogDomainToDbProfile).Assembly); }); Mapper = mockMapper.CreateMapper(); }
public async Task GivenGetAllAuthenticationLogs_WhenRequestIsMade_ThenShouldReturnCorrectData() { var options = SqliteInMemory.CreateOptions <LoggingDbContext>(); await using var context = new LoggingDbContext(options); { await context.Database.EnsureCreatedAsync(); context.SeedSingleAuthenticationLog(); var loggingRepository = new AuthenticationLogRepository(context); var logs = await loggingRepository.GetAllAuthenticationLogs(); Assert.IsType <List <AuthenticationLog> >(logs); Assert.Single(logs); } }
[Fact] public async Task GivenGetAllErrorLogs_WhenCalled_ThenShouldReturnAllErrorLogs() { var options = SqliteInMemory.CreateOptions <LoggingDbContext>(); await using var context = new LoggingDbContext(options); { await context.Database.EnsureCreatedAsync(); context.SeedErrorLogs(); var errorLogCount = context.ErrorLogs.Count(); var errorLogRepository = new ErrorLogRepository(context); var logs = await errorLogRepository.GetAllErrorLogs(); Assert.NotNull(logs); Assert.Equal(errorLogCount, logs.Count); Assert.IsType <List <ErrorLog> >(logs); } }
public LogsRepository(LoggingDbContext context) { _context = context; }
public LoggingService(LoggingDbContext dbContext) { _dbContext = dbContext; }
public ErrorLogRepository(LoggingDbContext context) { _context = context; }
public ItemsController(LoggingDbContext context) { this.context = context; }
public LoggingDb(LoggingDbContext context) => _context = context;
public SqlLoggingDatabase(LoggingDbContext context, IHubContext <LoggingHub, ILoggingHubService> hubContext) { _context = context; _hubContext = hubContext; }
public CustomLogger(LoggingDbContext loggerDbContext) { LoggerDbContext = loggerDbContext; StartWorker(); }
public TicketLogService(LoggingDbContext context, IMapper mapper) : base(context, mapper) { }
public SearchLogService(LoggingDbContext context, IMapper mapper) : base(context, mapper) { }
public ErrorLogService(LoggingDbContext context, IMapper mapper) : base(context, mapper) { }
public BaseService(LoggingDbContext context, IMapper mapper) { Context = context; Mapper = mapper; }
public DbLoggingProvider(LoggingDbContext context) { this.context = context; }
public static void SeedAuthenticationLogs(this LoggingDbContext context) { context.AuthenticationLogs.AddRange(AuthenticationLogs()); context.SaveChanges(); }
public static void SeedErrorLogs(this LoggingDbContext context) { context.ErrorLogs.AddRange(ErrorLogs()); context.SaveChanges(); }
public LoggingController(LoggingDbContext loggingDbContext) { _loggingDbContext = loggingDbContext; }
public AccountLogService(LoggingDbContext context, IMapper mapper) : base(context, mapper) { }
public LogsController(LoggingDbContext applicationDbContext, IRepository <Log> logsRepository) { ApplicationDbContext = applicationDbContext; LogsRepository = logsRepository; }