public async Task Ready_Mock_Returns_OK() { var mockClient = new Mock <SDK.SDKClient>(); var mockSdk = new AgonesSDK(); var expected = StatusCode.OK; var fakeCall = TestCalls.AsyncUnaryCall(Task.FromResult(new Empty()), Task.FromResult(new Metadata()), () => Status.DefaultSuccess, () => new Metadata(), () => { }); mockClient.Setup(m => m.ReadyAsync(It.IsAny <Empty>(), It.IsAny <Metadata>(), It.IsAny <DateTime?>(), It.IsAny <CancellationToken>())).Returns(fakeCall); mockSdk.client = mockClient.Object; var result = await mockSdk.ReadyAsync(); Assert.AreEqual(expected, result.StatusCode); }
private async Task RunAsync(CancellationToken ct) { try { if (!await _agonesSdk.ConnectAsync().ConfigureAwait(false)) { Console.WriteLine("Unable to connect to Agones SDK"); System.Environment.Exit(1); } } catch (Exception e) { Console.WriteLine(e); System.Environment.Exit(1); } var result = await _agonesSdk.ReadyAsync().ConfigureAwait(false); if (result.StatusCode != StatusCode.OK) { Console.WriteLine("Unable to set status to Ready"); System.Environment.Exit(1); } _agonesSdk.WatchGameServer((server => { switch (server.Status.State) { case "Allocated": Console.WriteLine("Allocated"); if (_checkTask != null && !_checkTask.IsCompleted) { return; } _checkTask = RunCheck(ct); break; case "Ready": Console.WriteLine("Ready"); break; default: break; } })); await _agonesSdk.Alpha().SetPlayerCapacityAsync(100); var capacity = await _agonesSdk.Alpha().GetPlayerCapacityAsync(); Console.WriteLine($"capacity: {capacity}"); // run health check while (true) { if (ct.IsCancellationRequested) { throw new OperationCanceledException(); } await Task.Delay(1000, ct).ConfigureAwait(false); var status = await _agonesSdk.HealthAsync().ConfigureAwait(false); if (status.StatusCode != StatusCode.OK) { Console.WriteLine("Health check failed"); } } }