예제 #1
0
        public void Start_ValidConfiguration_Starts()
        {
            _testConfiguration = new
            {
                heartbeatEndpoint = "heartbeatendpoint",
                sessionHostId     = "serverid",
                gameCertificates  = new Dictionary <string, string>
                {
                    { "cert1", "thumb1" },
                    { "cert2", "thumb2" },
                    { "cert3", "thumb3" }
                },
                buildMetadata = new Dictionary <string, string>
                {
                    { "property1", "value1" },
                    { "property2", "value2" },
                    { "property3", "value3" }
                },
                gamePorts = new Dictionary <string, string>
                {
                    { "8080", "port1" }
                }
            };

            var sdk = new InternalSdk(_mockSystemOperations.Object, _mockHttpClientFactory.Object);

            sdk.Start(false);
            sdk.State.Should().Be(GameState.Initializing);
            sdk.ConfigMap.Should().NotBeNull();
            sdk.ConfigMap.Should().HaveCountGreaterThan(0);
            sdk.ConnectedPlayers.Should().NotBeNull();
            sdk.ConnectedPlayers.Should().HaveCount(0);
        }
예제 #2
0
        public void GameState_TerminateReturned_CallbackInvoked()
        {
            _testConfiguration = new
            {
                heartbeatEndpoint = "heartbeatendpoint",
                sessionHostId     = "serverid"
            };

            _mockHttpClient.Setup(x => x.SendHeartbeatAsync(It.IsAny <HeartbeatRequest>()))
            .ReturnsAsync(new HeartbeatResponse
            {
                Operation = GameOperation.Terminate
            });


            bool shutdownInvoked = false;

            var sdk = new InternalSdk(_mockSystemOperations.Object, _mockHttpClientFactory.Object)
            {
                ShutdownCallback = () => { shutdownInvoked = true; }
            };


            sdk.Start(false);
            Thread.Sleep(2000);

            shutdownInvoked.Should().BeTrue();
        }
예제 #3
0
        public void GameState_HealthCallbackReturnsHealthy_StatusSent()
        {
            HeartbeatRequest request = null;

            _testConfiguration = new
            {
                heartbeatEndpoint = "heartbeatendpoint",
                sessionHostId     = "serverid"
            };

            _mockHttpClient.Setup(x => x.SendHeartbeatAsync(It.IsAny <HeartbeatRequest>()))
            .ReturnsAsync(new HeartbeatResponse
            {
                Operation = GameOperation.Active
            })
            .Callback <HeartbeatRequest>(x => request = x);


            var sdk = new InternalSdk(_mockSystemOperations.Object, _mockHttpClientFactory.Object);

            sdk.HealthCallback = () => true;

            sdk.Start(false);

            sdk.State = GameState.StandingBy;
            sdk.TransitionToActiveEvent.WaitOne();

            request.Should().NotBeNull();
            request.CurrentGameHealth.Should().Be("Healthy");
        }
예제 #4
0
        public void GameState_SessionConfigReturnedNoPlayers_ConfigMapUpdated()
        {
            _testConfiguration = new
            {
                heartbeatEndpoint = "heartbeatendpoint",
                sessionHostId     = "serverid"
            };

            _mockHttpClient.Setup(x => x.SendHeartbeatAsync(It.IsAny <HeartbeatRequest>()))
            .ReturnsAsync(new HeartbeatResponse
            {
                Operation     = GameOperation.Continue,
                SessionConfig = new SessionConfig
                {
                    SessionId     = Guid.NewGuid(),
                    SessionCookie = "awesomeCookie"
                }
            });


            var sdk = new InternalSdk(_mockSystemOperations.Object, _mockHttpClientFactory.Object);

            sdk.Start(false);

            sdk.ConfigMap.Should().NotContainKey("sessionCookie");
            Thread.Sleep(2000);
            sdk.ConfigMap.Should().ContainKey("sessionCookie");
            sdk.InitialPlayers.Should().BeEmpty("Initial Player List not returned");
        }
예제 #5
0
        public void GameState_MaintDateReturned_CallbackInvokedOnlyOnce()
        {
            _testConfiguration = new
            {
                heartbeatEndpoint = "heartbeatendpoint",
                sessionHostId     = "serverid"
            };

            _mockHttpClient.Setup(x => x.SendHeartbeatAsync(It.IsAny <HeartbeatRequest>()))
            .ReturnsAsync(new HeartbeatResponse
            {
                Operation = GameOperation.Continue,
                NextScheduledMaintenanceUtc = "2018-11-12T04:11:14Z"
            });


            int invocationCount = 0;

            var sdk = new InternalSdk(_mockSystemOperations.Object, _mockHttpClientFactory.Object)
            {
                MaintenanceCallback = dt => { invocationCount++; }
            };

            sdk.Start(false);

            Thread.Sleep(5000);

            invocationCount.Should().Be(1);
        }
예제 #6
0
        public void GameStateToActive_ActiveReturned_StateUpdated()
        {
            _testConfiguration = new
            {
                heartbeatEndpoint = "heartbeatendpoint",
                sessionHostId     = "serverid"
            };

            _mockHttpClient.Setup(x => x.SendHeartbeatAsync(It.IsAny <HeartbeatRequest>()))
            .ReturnsAsync(new HeartbeatResponse
            {
                Operation = GameOperation.Active
            });

            var sdk = new InternalSdk(_mockSystemOperations.Object, _mockHttpClientFactory.Object);

            sdk.Start(false);

            sdk.State = GameState.StandingBy;
            sdk.TransitionToActiveEvent.WaitOne();
            sdk.State.Should().Be(GameState.Active);
        }
예제 #7
0
        public void GameState_TerminateReturned_StateUpdated()
        {
            _testConfiguration = new
            {
                heartbeatEndpoint = "heartbeatendpoint",
                sessionHostId     = "serverid"
            };

            _mockHttpClient.Setup(x => x.SendHeartbeatAsync(It.IsAny <HeartbeatRequest>()))
            .ReturnsAsync(new HeartbeatResponse
            {
                Operation = GameOperation.Terminate
            });


            var sdk = new InternalSdk(_mockSystemOperations.Object, _mockHttpClientFactory.Object);

            sdk.Start(false);
            Thread.Sleep(2000);

            sdk.State.Should().Be(GameState.Terminating);
        }
예제 #8
0
        public void GameState_MaintDateReturned_CallbackInvoked()
        {
            _testConfiguration = new
            {
                heartbeatEndpoint = "heartbeatendpoint",
                sessionHostId     = "serverid"
            };

            _mockHttpClient.Setup(x => x.SendHeartbeatAsync(It.IsAny <HeartbeatRequest>()))
            .ReturnsAsync(new HeartbeatResponse
            {
                Operation = GameOperation.Continue,
                NextScheduledMaintenanceUtc = "2018-11-12T04:11:14Z"
            });


            DateTimeOffset   maintDate = DateTime.MinValue;
            ManualResetEvent evt       = new ManualResetEvent(false);

            var sdk = new InternalSdk(_mockSystemOperations.Object, _mockHttpClientFactory.Object)
            {
                MaintenanceCallback = dt =>
                {
                    maintDate = dt;
                    evt.Set();
                }
            };


            sdk.Start(false);

            evt.WaitOne();
            maintDate.Should().Be(
                DateTime.Parse(
                    "2018-11-12T04:11:14Z",
                    null,
                    DateTimeStyles.RoundtripKind));
        }
예제 #9
0
        public void GameState_SessionConfigReturnedWithSessionMetadata_ConfigMapUpdated()
        {
            _testConfiguration = new
            {
                heartbeatEndpoint = "heartbeatendpoint",
                sessionHostId     = "serverid"
            };

            var sessionMetadataKey   = "sessionMetadataKey";
            var sessionMetadataValue = "sessionMetadataValue";

            _mockHttpClient.Setup(x => x.SendHeartbeatAsync(It.IsAny <HeartbeatRequest>()))
            .ReturnsAsync(new HeartbeatResponse
            {
                Operation     = GameOperation.Continue,
                SessionConfig = new SessionConfig
                {
                    SessionId     = Guid.NewGuid(),
                    SessionCookie = "awesomeCookie",
                    Metadata      = new Dictionary <string, string>()
                    {
                        { sessionMetadataKey, sessionMetadataValue }
                    }
                }
            });


            var sdk = new InternalSdk(_mockSystemOperations.Object, _mockHttpClientFactory.Object);

            sdk.Start(false);

            sdk.ConfigMap.Should().NotContainKey("sessionCookie");
            Thread.Sleep(2000);
            sdk.ConfigMap.Should().ContainKey("sessionCookie");
            Assert.AreEqual(sessionMetadataValue, sdk.ConfigMap[sessionMetadataKey]);
        }