示例#1
0
        public async Task FindIpAddressesAsync_ReturnsSuccessAndIpForArSubdomain()
        {
            // Act
            IpAddressesResponse actual = await _subdomainService.FindIpAddressesAsync(new List <string> {
                "ar.yahoo.com"
            });

            IpAddressesResponse expected = await Task.Run(() => new IpAddressesResponse()
            {
                Results = new List <Result>
                {
                    new Result {
                        Subdomain = "ar.yahoo.com", IpAddresses = new List <string> {
                            "106.10.248.150"
                        }
                    }
                },
                Success = true
            });

            // Assert
            Assert.NotNull(actual);
            Assert.True(actual.Success);
            Assert.Equal(expected.Results?.FirstOrDefault().Subdomain, actual.Results?.FirstOrDefault().Subdomain);
            Assert.Equal(expected.Results?.FirstOrDefault().IpAddresses, actual.Results?.FirstOrDefault().IpAddresses);
        }
示例#2
0
        public async Task FindIpAddressesAsync_ReturnsSuccess()
        {
            // Act
            IpAddressesResponse actual = await _subdomainService.FindIpAddressesAsync(new List <string> {
                "ar.yahoo.com"
            });

            // Assert
            Assert.NotNull(actual);
            Assert.True(actual.Success);
        }
示例#3
0
        public async Task FindIpAddressesAsync_ReturnsNoIpAddresses()
        {
            // Act
            IpAddressesResponse actual = await _subdomainService.FindIpAddressesAsync(new List <string> {
                "aa.yahoo.com"
            });

            // Assert
            Assert.NotNull(actual);
            Assert.True(actual.Success);
            Assert.True(actual.Results?.FirstOrDefault().IpAddresses == null);
        }
示例#4
0
        public async Task FindIpAddressesAsync_ReturnsSuccess()
        {
            // Arrange
            Mock <ILogger <SubdomainController> > mockLogger = new Mock <ILogger <SubdomainController> >();
            Mock <ISubdomainService> mockSubdomainService    = new Mock <ISubdomainService>();

            List <string> subdomains = new List <string> {
                "ar.yahoo.com"
            };

            IpAddressesResponse response = new IpAddressesResponse
            {
                Results = new List <Result>
                {
                    new Result {
                        Subdomain = "ar.yahoo.com", IpAddresses = new List <string> {
                            "106.10.248.150"
                        }
                    }
                },
                Success = true
            };

            mockSubdomainService.Setup(q => q.FindIpAddressesAsync(subdomains)).Returns(Task.FromResult(response));

            SubdomainController controller = new SubdomainController(mockLogger.Object, mockSubdomainService.Object);

            // Act
            IActionResult result = await controller.FindIpAddressesAsync(subdomains);

            ObjectResult okObjectResult = result as ObjectResult;

            // Assert
            IpAddressesResponse actual = (IpAddressesResponse)okObjectResult.Value;

            Assert.NotNull(okObjectResult);
            Assert.True(okObjectResult is OkObjectResult);
            Assert.IsType <IpAddressesResponse>(okObjectResult.Value);
            Assert.Equal(StatusCodes.Status200OK, okObjectResult.StatusCode);
            Assert.True(actual.Success);
        }
        public async Task <IActionResult> FindIpAddressesAsync([FromBody] List <string> subdomains)
        {
            _logger?.LogDebug("'{0}' has been invoked.", nameof(FindIpAddressesAsync));

            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            try
            {
                IpAddressesResponse response = await _subdomainService.FindIpAddressesAsync(subdomains);

                return(Ok(response));
            }
            catch (Exception ex)
            {
                _logger?.LogCritical("There was an error on '{0}' invocation: {1}", nameof(FindIpAddressesAsync), ex);

                return(StatusCode(StatusCodes.Status500InternalServerError, new IpAddressesResponse {
                    ErrorMessage = ex.Message
                }));
            }
        }