private static void ConfigureServices(IServiceCollection services, ICrewChecker crewChecker) { services.AddHostedService <EBuEf2IVUCrew.Worker>(); services.AddTransient <Mock <ILogger> >(); var messageReceiverMock = new Mock <IMessageReceiver>(); services.AddSingleton(messageReceiverMock.Object); var session = new EBuEfSession { IVUDatum = DateTime.Today, SessionStart = DateTime.Now, }; var trainRunsMock = new List <TrainRun> { Mock.Of <TrainRun>() }; var databaseConnectorMock = new Mock <IDatabaseConnector>(); databaseConnectorMock.Setup(m => m.GetEBuEfSessionActiveAsync()).Returns(Task.FromResult(true)); databaseConnectorMock.Setup(m => m.GetEBuEfSessionAsync()).Returns(Task.FromResult(session)); databaseConnectorMock.Setup(m => m.GetTrainRunsDispoAsync(It.IsAny <TimeSpan>(), It.IsAny <TimeSpan>())).Returns(Task.FromResult((IEnumerable <TrainRun>)trainRunsMock)); services.AddSingleton(databaseConnectorMock.Object); services.AddSingleton <IStateHandler, StateHandler.Handler>(); services.AddSingleton(crewChecker); }
private async Task <EBuEfSession> QueryEBuEfSessionAsync(CancellationToken queryCancellationToken) { var result = default(EBuEfSession); if (!queryCancellationToken.IsCancellationRequested) { logger.LogDebug( "Suche in der EBuEf-DB nach der aktuellen Fahrplan-Session."); using var context = new SitzungContext(connectionString); var sitzung = await context.Sitzungen .Where(s => s.Status == Convert.ToByte(SessionStatusType.InPreparation) || s.Status == Convert.ToByte(SessionStatusType.IsRunning) || s.Status == Convert.ToByte(SessionStatusType.IsPaused)) .OrderByDescending(s => s.Status == Convert.ToByte(SessionStatusType.IsRunning)) .ThenByDescending(s => s.Status == Convert.ToByte(SessionStatusType.IsPaused)) .FirstOrDefaultAsync(queryCancellationToken); if (sitzung != default) { var timeshift = new TimeSpan( hours: 0, minutes: 0, seconds: sitzung.Verschiebung * -1); result = new EBuEfSession { FahrplanId = sitzung.FahrplanId, IVUDatum = sitzung.IvuDate ?? DateTime.Today, SessionKey = sitzung.SessionKey, SessionStart = sitzung.SimStartzeit.ToDateTime().ToLocalTime(), Verschiebung = timeshift, Wochentag = sitzung.SimWochentag.GetWochentag(), }; logger.LogDebug( "Aktuelle EBuEf-Sitzung gefunden: {session}", result); } else { logger.LogError( "Es wurde keine EBuEf-Session gefunden."); } } return(result); }
protected async Task InitializeSessionAsync() { if (databaseConnector == default) { throw new ApplicationException("The database connector must be initialized firstly."); } ebuefSession = await databaseConnector.GetEBuEfSessionAsync(); ivuSessionDate = ebuefSession.IVUDatum; ebuefSessionStart = ivuSessionDate .Add(ebuefSession.SessionStart.TimeOfDay); logger.LogDebug( "Die IVU-Sitzung läuft am {sessionDate} um {sessionTime}.", ivuSessionDate.ToString("yyyy-MM-dd"), ebuefSessionStart.ToString("hh:mm")); }