Esempio n. 1
0
        public void invalidDeleteId()
        {
            var mockRepo         = new Mock <IServerManager>();
            var serverController = new ServersController(mockRepo.Object);

            mockRepo.Setup(p => p.DeleteServer("111111")).Throws <InvalidOperationException>();
            Assert.Throws <InvalidOperationException>(() => serverController.Delete("111111"));
        }
        public void DeleteServerTest(string id)
        {
            // Arrange.
            IDataAccess       demoDataAccess    = new DemoDataAccess();
            IServersManager   serversManager    = new ServersManager(demoDataAccess);
            ServersController serversController = new ServersController(serversManager);

            // Act.
            ActionResult <string> actionResult = serversController.Delete(id);

            // Assert.
            ObjectResult expectedResult;

            if (demoDataAccess.DeleteServer(id))
            {
                expectedResult = new OkObjectResult(id);
            }
            else
            {
                expectedResult = new NotFoundObjectResult(id);
            }
            Assert.IsInstanceOfType(actionResult.Result, expectedResult.GetType());
        }
Esempio n. 3
0
        public void TestDelete()
        {
            List <Server> serverList = new List <Server>()
            {
                new Server {
                    ServerId = "sapir22", ServerUrl = "www.test1.com"
                }
            };
            IMemoryCache  cache      = CreateCache();
            List <string> serversIds = new List <string>();

            serversIds.Add(serverList[0].ServerId);
            ServersController controller = new ServersController(cache);
            string            serJson    = "{\"ServerId\":\"sapir22\",\"ServerURL\":\"www.test1.com\"}";
            JsonDocument      doc        = JsonDocument.Parse(serJson);
            JsonElement       root       = doc.RootElement;

            controller.Post(root);
            controller.Delete(serverList[0].ServerId);
            serverList.Remove(serverList[0]);
            var responseList = (List <Server>)controller.GetAllServers();

            Assert.AreEqual(responseList.Count, 0);
        }