public async Task Create_and_start_timing_session() { var messageHub = new ChannelMessageHub(); using var storageService = new StorageService(Options.Create(new StorageServiceOptions { StorageConnectionString = storageConnectionString }), MessageHub); var upstreamDataStorage = new UpstreamDataRepository(storageService); var eventRepository = new EventRepository(storageService, upstreamDataStorage); var recordingRepository = new RecordingServiceRepository(storageService, SystemClock); var upstreamDataSyncService = new UpstreamDataSyncService(Options.Create(upstreamDataSyncServiceOptions), new FakeMainClient(), upstreamDataStorage, messageHub); var downloadResult = await upstreamDataSyncService.Download(true); downloadResult.Should().BeTrue(); upstreamDataStorage.ListSeries().Should().HaveCount(4); var tagSub = new FakeCheckpointSubscription(); var cpf = Substitute.For <ICheckpointServiceClientFactory>(); var cps = Substitute.For <ICheckpointServiceClient>(); cpf.CreateClient(Arg.Any <string>()).Returns(cps); cps.CreateSubscription(Arg.Any <DateTime>()).Returns(tagSub); storageService.Repo.Query <CheckpointDto>().Count().Should().Be(0); using var recordingService = new RecordingService(Options.Create(new RecordingServiceOptions { CheckpointServiceAddress = "http://localhost:6000" }), recordingRepository, eventRepository, cpf, new AutoMapperProvider(), messageHub, SystemClock); var timingSessionService = new TimingSessionService(eventRepository, recordingService, recordingRepository, MessageHub, new AutoMapperProvider(), new DefaultSystemClock()); var ev = upstreamDataStorage.ListEvents().First(x => x.Name == "Тучково кантри 12.09.2020"); var session = upstreamDataStorage.ListSessions(ev.Id).First(x => x.Name == "Эксперт и Опен"); var timingSession = timingSessionService.CreateSession("timing sess", session.Id); timingSession.Start(tagSub.Now.AddSeconds(-10)); await Task.Delay(100); tagSub.SendTags((1, "11"), (2, "12")); await Task.Delay(100); storageService.Repo.Query <CheckpointDto>().Count().Should().Be(2); //recordingRepository.GetActiveRecordingSession().Should().NotBeNull(); // timingSession.Track.Rating.Should().HaveCount(2); // timingSession.Track.Rating[0].RiderId.Should().Be("11"); // timingSession.Track.Rating[1].RiderId.Should().Be("12"); //recordingService.StopRecording(); //recordingRepository.GetActiveRecordingSession().Should().BeNull(); }
static async Task Main() { Randomizer.Seed = new Random(1); var config = new ConfigurationBuilder() .AddUserSecrets <Program>() .Build(); var options = config.GetSection(nameof(UpstreamDataSyncServiceOptions)).Get <UpstreamDataSyncServiceOptions>(); Console.WriteLine("Downloading upstream data"); var mainClient = new MainClient(options.BaseUri, new HttpClient()); var series = await mainClient.SeriesAsync(options.ApiKey, null); var championships = await mainClient.ChampionshipsAsync(options.ApiKey, null); var classes = await mainClient.ClassesAsync(options.ApiKey, null); var events = await mainClient.EventsAsync(options.ApiKey, null); var eventPrices = (await mainClient.EventPricesAsync(options.ApiKey, null)).Select(Mask).ToList(); var schedules = await mainClient.SchedulesAsync(options.ApiKey, null); var scheduleToClass = await mainClient.ScheduleToClassAsync(options.ApiKey, null); var eventConfirmations = (await mainClient.EventConfirmationsAsync(options.ApiKey, null)).Select(Mask).ToList(); var riderProfiles = (await mainClient.RiderProfilesAsync(options.ApiKey, null)).Select(Mask).ToList(); var riderRegistrations = await mainClient.RiderRegistrationsAsync(options.ApiKey, null); var riderDisqualifications = await mainClient.RiderDisqualificationsAsync(options.ApiKey); Save(nameof(mainClient.SeriesAsync), series); Save(nameof(mainClient.ChampionshipsAsync), championships); Save(nameof(mainClient.ClassesAsync), classes); Save(nameof(mainClient.EventsAsync), events); Save(nameof(mainClient.EventPricesAsync), eventPrices); Save(nameof(mainClient.SchedulesAsync), schedules); Save(nameof(mainClient.ScheduleToClassAsync), scheduleToClass); Save(nameof(mainClient.EventConfirmationsAsync), eventConfirmations); Save(nameof(mainClient.RiderProfilesAsync), riderProfiles); Save(nameof(mainClient.RiderRegistrationsAsync), riderRegistrations); Save(nameof(mainClient.RiderDisqualificationsAsync), riderDisqualifications); Console.WriteLine($"Done"); var messageHub = new ChannelMessageHub(); var storageService = new StorageService(Options.Create(new StorageServiceOptions { StorageConnectionString = "upstream-data.litedb" }), new ChannelMessageHub()); var upstreamDataStorage = new UpstreamDataRepository(storageService); var fakeMainClient = Substitute.For <IMainClient>(); fakeMainClient.SeriesAsync(Arg.Any <string>(), Arg.Any <DateTimeOffset>()).Returns(series); fakeMainClient.ChampionshipsAsync(Arg.Any <string>(), Arg.Any <DateTimeOffset>()).Returns(championships); fakeMainClient.ClassesAsync(Arg.Any <string>(), Arg.Any <DateTimeOffset>()).Returns(classes); fakeMainClient.EventsAsync(Arg.Any <string>(), Arg.Any <DateTimeOffset>()).Returns(events); fakeMainClient.EventPricesAsync(Arg.Any <string>(), Arg.Any <DateTimeOffset>()).Returns(eventPrices); fakeMainClient.SchedulesAsync(Arg.Any <string>(), Arg.Any <DateTimeOffset>()).Returns(schedules); fakeMainClient.ScheduleToClassAsync(Arg.Any <string>(), Arg.Any <DateTimeOffset>()).Returns(scheduleToClass); fakeMainClient.EventConfirmationsAsync(Arg.Any <string>(), Arg.Any <DateTimeOffset>()).Returns(eventConfirmations); fakeMainClient.RiderProfilesAsync(Arg.Any <string>(), Arg.Any <DateTimeOffset>()).Returns(riderProfiles); fakeMainClient.RiderRegistrationsAsync(Arg.Any <string>(), Arg.Any <DateTimeOffset>()).Returns(riderRegistrations); fakeMainClient.RiderDisqualificationsAsync(Arg.Any <string>()).Returns(riderDisqualifications); var upstreamDataSyncService = new UpstreamDataSyncService(Options.Create(options), fakeMainClient, upstreamDataStorage, messageHub); var downloadResult = await upstreamDataSyncService.Download(true); Console.WriteLine($"Save to litedb = {downloadResult}"); }