Пример #1
0
        public async Task GetAllServers_should_return_empty_list_when_servers_does_not_exists()
        {
            A.CallTo(() => _fakeMediator.Send(A <GetAllServersQuery> ._, A <CancellationToken> ._)).Returns(new List <ServerDto>());

            var result = await _serversController.GetAllServers() as OkNegotiatedContentResult <List <ServerDto> >;

            Assert.NotNull(result);
            Assert.AreEqual(0, result.Content.Count);
        }
Пример #2
0
        public void TestExternalListTest()
        {
            List <Server> serverList = GetServers();
            IMemoryCache  cache      = CreateCache();
            List <string> serversIds = new List <string>();

            for (int i = 0; i < serverList.Count; i++)
            {
                serversIds.Add(serverList[i].ServerId);
            }
            cache.TryGetValue("servers", out List <string> ids);
            ids.AddRange(serversIds);
            for (int i = 0; i < serverList.Count; i++)
            {
                cache.Set(serverList[i].ServerId, serverList[i]);
            }
            ServersController controller = new ServersController(cache);
            var responseList             = (List <Server>)controller.GetAllServers();

            Assert.IsNotNull(responseList);
            for (int i = 0; i < serverList.Count; i++)
            {
                Assert.AreEqual(serverList[i].ServerId, responseList[i].ServerId);
            }
        }
Пример #3
0
        public void ServersController_GetServers_ReturnServers()
        {
            var expected = _mockRepo.GetServersOutput;
            ServersController serversController = new ServersController(_mockRepo);

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

            Assert.AreEqual(actual, expected, "Invalid Answer in get servers method.");
        }
Пример #4
0
        public void TestPostServer()
        {
            Server serv1 = new Server {
                ServerId = "sapir22", ServerUrl = "www.test1.com"
            };
            List <Server> servers = new List <Server>();

            servers.Add(serv1);
            IMemoryCache      cache      = CreateCache();
            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);
            var responseList = (List <Server>)controller.GetAllServers();

            Assert.AreEqual(responseList[0].ServerId, servers[0].ServerId);
            Assert.AreEqual(responseList[0].ServerUrl, servers[0].ServerUrl);
        }
Пример #5
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);
        }