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); } }
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); } }