Ejemplo n.º 1
0
        public void ShouldUseDefaultServices()
        {
            var rdapService = new Mock <IService>();

            rdapService
            .Setup(e => e.ServiceType())
            .Returns(ServiceTypes.RDAP);

            rdapService
            .Setup(e => e.SendQueryAsync("google.com"))
            .Returns(Task.FromResult(new ServiceResultDto
            {
                Result = "DATA FROM RDAP"
            }));


            var configSection = new Mock <IConfigurationSection>();

            configSection.Setup(c => c.Value)
            .Returns("RDAP,Ping");

            var config = new Mock <IConfiguration>();

            config.Setup(s => s.GetSection("DefaultServices"))
            .Returns(configSection.Object);


            var infoCollector = new InfoCollector(new[] { rdapService.Object }, config.Object);

            var results = infoCollector.Request("google.com").Result;

            Assert.Single(results);
            Assert.Equal("DATA FROM RDAP", results[0].Result);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Get([FromQuery] string Host, [FromQuery] IList <string> QueryServices)
        {
            if (!ValidateRequest(Host, QueryServices))
            {
                return(BadRequest());
            }

            var results = await _infoCollector.Request(Host, QueryServices.ToArray());

            return(Content(JsonConvert.SerializeObject(results)));
        }
Ejemplo n.º 3
0
        public async void ShouldReturnEmptyResults()
        {
            string HostName = "google.com";

            var services = new List <IService>();

            var rdapService = new Mock <IService>();

            rdapService
            .Setup(e => e.ServiceType())
            .Returns(ServiceTypes.RDAP);

            rdapService
            .Setup(e => e.SendQueryAsync(HostName))
            .Returns(Task.FromResult(new ServiceResultDto()
            {
                Result = "",
                Status = "Error"
            }));

            services.Add(rdapService.Object);


            var pingService = new Mock <IService>();

            pingService
            .Setup(e => e.ServiceType())
            .Returns(ServiceTypes.Ping);

            pingService
            .Setup(e => e.SendQueryAsync(HostName))
            .Returns(Task.FromResult(new ServiceResultDto()
            {
                Result = "",
                Status = "Error"
            }));

            services.Add(pingService.Object);



            var configSection = new Mock <IConfigurationSection>();

            configSection.Setup(c => c.Value)
            .Returns("RDAP,Ping");

            var config = new Mock <IConfiguration>();

            config.Setup(s => s.GetSection("DefaultServices"))
            .Returns(configSection.Object);


            var infoCollector = new InfoCollector(services, config.Object);


            var results = infoCollector.Request("google.com").Result;


            foreach (var item in results)
            {
                Assert.Equal("Error", item.Status);
            }
        }