Ejemplo n.º 1
0
        public async void PostNewServer_WithNew_IsSuccessful()
        {
            using (var context = MockDataContext.GetContext()) {
                // A mock which returns the input challenge.
                var controller = new ServersController(context, ConstructChallengeRespondingMock(), logger);

                var endPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 100);
                MockControllerConnection(controller, endPoint.Address);

                var result = await controller.PostNewServer(new GameServer {
                    Name           = "Server A",
                    Address        = endPoint.Address.ToString(),
                    QueryPort      = endPoint.Port,
                    GamePort       = 100,
                    RoundStatus    = "starting",
                    RoundStartTime = DateTime.Now,
                    Game           = "SS3D"
                }).ConfigureAwait(false);

                Assert.Equal(StatusCodes.Status201Created, (result as IStatusCodeActionResult).StatusCode);
            }

            using (var context = MockDataContext.GetContext()) {
                Assert.Single(context.Servers);
            }
        }
Ejemplo n.º 2
0
        public async void PostNewServer_WithExisting_GivesError()
        {
            // Setup
            using (var context = MockDataContext.GetContext()) {
                context.Servers.Add(new GameServer {
                    Name           = "Server Not A",
                    Address        = "2001:0db8:85a3:0000:0000:8a2e:0370:7334",
                    QueryPort      = 100,
                    GamePort       = 100,
                    RoundStatus    = "starting",
                    RoundStartTime = DateTime.Now,
                    Game           = "SS3D",
                    LastUpdate     = DateTime.Now
                });
                context.SaveChanges();
            }

            using (var context = MockDataContext.GetContext()) {
                var controller = new ServersController(context, ConstructChallengeRespondingMock(), logger);

                var endPoint = new IPEndPoint(IPAddress.Parse("2001:0db8:85a3:0000:0000:8a2e:0370:7334"), 100);
                MockControllerConnection(controller, endPoint.Address);

                var result = await controller.PostNewServer(new GameServer {
                    Name           = "Server A",
                    Address        = endPoint.Address.ToString(),
                    QueryPort      = endPoint.Port,
                    GamePort       = 100,
                    RoundStatus    = "starting",
                    RoundStartTime = DateTime.Now,
                }).ConfigureAwait(false);

                Assert.Equal(StatusCodes.Status409Conflict, (result as IStatusCodeActionResult).StatusCode);
            }

            using (var context = MockDataContext.GetContext()) {
                var controller = new ServersController(context, ConstructChallengeRespondingMock(), logger);
                var servers    = await controller.GetServers().ToListAsync();

                Assert.Single(servers);
                Assert.Equal("Server Not A", servers[0].Name); // Nothing about the original entry should have changed.
            }
        }