public async Task InvokesStartMatch() { var taskCompletionSource = new TaskCompletionSource <bool>(); var server = new HttpServer(HttpServer.GetNextPort()); server.Start(); server.OnRequest += async(Uri endpoint, NameValueCollection headers, Stream stream) => { StreamReader reader = new StreamReader(stream); var jsonString = await reader.ReadToEndAsync(); var jsonObject = JsonConvert.DeserializeObject <StartMatchCommandPayload>(jsonString); Assert.IsTrue(endpoint.PathAndQuery.Contains("start-match")); Assert.AreEqual("Bearer 1234", headers.Get("Authorization")); Assert.AreEqual("matchKey", jsonObject.MatchKey); var configDictionary = jsonObject.Config as JToken; Assert.AreEqual("value", configDictionary["key"]); taskCompletionSource.SetResult(true); }; var config = new GameyeClientConfig($"http://127.0.0.1:{server.Port}", "1234"); var client = new GameyeClient(config); var matchConfig = new Dictionary <string, object> { { "key", "value" } }; await client.CommandStartMatch("matchKey", "gameKey", new[] { "locationOne", "locationTwo" }, "templateKey", matchConfig); taskCompletionSource.Task.Wait(); server.Stop(); }
public async Task Run() { var config = new GameyeClientConfig(); var client = new GameyeClient(config); var sessionId = Guid.NewGuid().ToString(); Console.WriteLine($"Creating session with id {sessionId}"); JObject finalStats = null; IEnumerable <LogLine> allLogs = null; client.SessionStore.OnChange += (SessionState state) => { session = state.SelectSession(sessionId); }; client.StatisticsStore.OnChange += (StatisticsState state) => { finalStats = state.SelectRawStatistics(); }; var currentLine = 0; client.LogStore.OnChange += (LogState state) => { var lastLogs = state.SelectLogsSince(currentLine); foreach (var log in lastLogs) { Console.WriteLine(log); } currentLine += lastLogs.Count(); allLogs = state.SelectAllLogs(); }; await client.SubscribeSessionEvents(); await client.CommandStartMatch(sessionId, "csgo-dem", new[] { "frankfurt" }, "bots", new Dictionary <string, object> { { "maxRounds", 2 } }); while (session == null) { Sleep(10); } Console.WriteLine($"Got Session at {session.Host}"); await client.SubscribeStatisticsEvents(sessionId); await client.SubscribeLogEvents(sessionId); while (session != null) { Sleep(10); } File.WriteAllText("Stats.txt", finalStats.ToString()); File.WriteAllText("Logs.txt", string.Join("", allLogs)); Console.WriteLine($"Session Destroyed"); }