示例#1
0
        public void ShouldPlayEvents()
        {
            var directoryProvider = new TestDirectoryProvider();
            var events            = new ConcurrentBag <JournalEvent>();

            CollectionAssert.IsEmpty(events);

            string testFile1 = Path.Combine(directoryProvider.Directory, "Journal.1234.log");
            string testFile2 = Path.Combine(directoryProvider.Directory, "Journal.2345.log");

            File.WriteAllText(testFile1, EventsAsJson.Skip(5).First());
            File.WriteAllText(testFile2, EventsAsJson.Skip(5).First());

            var burstPlayer1 = new JournalBurstPlayer(directoryProvider.Directory, 1);

            burstPlayer1.Subscribe(events.Add);
            burstPlayer1.Play();
            CollectionAssert.IsNotEmpty(events);
            Assert.AreEqual(1, events.Count);

            var burstPlayer2 = new JournalBurstPlayer(directoryProvider.Directory, 100);

            burstPlayer2.Subscribe(events.Add);
            burstPlayer2.Play();
            CollectionAssert.IsNotEmpty(events);
            Assert.AreEqual(3, events.Count);
        }
示例#2
0
        public async Task IntegrationTestUploadToInara()
        {
            var logEventSource = new JournalBurstPlayer(new SavedGamesDirectoryHelper().Directory, 5);
            var logCounter     = new JournalEventTypeCounter();
            var stateRecorder  = new PlayerStateRecorder();

            var inaraRestClient = new ThrottlingRestClient.Factory().CreateRestClient("https://inara.cz/inapi/v1/");
            var inaraConverter  = new InaraEventConverter(stateRecorder);
            var inaraApiFacade  = new InaraApiFacade(inaraRestClient, TestCredentials.UserName, TestCredentials.Inara.ApiKey, null);

            // Populate the state recorder to avoid missing ships/starsystems data
            foreach (var ev in logEventSource.Events)
            {
                stateRecorder.OnNext(ev);
            }

            var convertedEvents = logEventSource
                                  .Events
                                  .SelectMany(inaraConverter.Convert)
                                  .ToArray();

            var results = await inaraApiFacade.ApiCall(convertedEvents);

            results = results
                      .Where(e => e.EventStatus != 200)
                      .Where(e => !ignoredErrors.Contains(e.EventStatusText))
                      .ToList();

            CollectionAssert.IsEmpty(results);
            Assert.Pass("Uploaded {0} events", convertedEvents.Length);
        }