public void Delete_WithDifferentIp_IsForbidden()
        {
            var endPoint = new IPEndPoint(101, 1);

            using (var context = MockDataContext.GetContext()) {
                context.Servers.Add(new GameServer {
                    Name           = "C",
                    Address        = endPoint.Address.ToString(),
                    QueryPort      = endPoint.Port,
                    GamePort       = 300,
                    RoundStatus    = "starting",
                    RoundStartTime = DateTime.Now,
                    Game           = "SS3D",
                    LastUpdate     = DateTime.Now - TimeSpan.FromMinutes(6)
                });
                context.SaveChanges();
            }

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

                IActionResult response = controller.DeleteServer(endPoint.ToString());

                Assert.Equal(StatusCodes.Status204NoContent, (response as IStatusCodeActionResult).StatusCode);
            }
        }
        public void ServersController_postServer_ReturnValidResponse()
        {
            var expected = _mockRepo.DeleteServerOutput;
            ServersController serversController = new ServersController(_mockRepo);

            var answer = (OkObjectResult)serversController.DeleteServer("").Result;
            var actual = answer.Value;

            Assert.AreEqual(actual, expected, "Invalid Answer in get servers method.");
        }
        public void Delete_WithNonExistant_GivesNotFound()
        {
            var endPoint = new IPEndPoint(100, 1);

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

            IActionResult response = controller.DeleteServer(endPoint.ToString());

            Assert.Equal(StatusCodes.Status404NotFound, (response as IStatusCodeActionResult).StatusCode);
        }
Exemple #4
0
        public void Test_DeleteServer()
        {
            // Setup
            string serverUrl = "http://test3.com";
            string serverId  = "test_server3";
            Server server    = new Server(serverId, serverUrl);

            var mockRemoteServersConnector = new RemoteServersConnector();

            mockRemoteServersConnector.AddServer(server);
            var serversController = new ServersController(mockRemoteServersConnector);

            // Act
            IActionResult delAction = serversController.DeleteServer(server.ServerId);


            // Assert
            Assert.IsType <OkResult>(delAction);
            Assert.Empty(mockRemoteServersConnector.GetAllServers());
        }