public async Task GetLocation_InvalidIpTest() { var controller = new IpController(queryMoq.Object); var res = await controller.GetLocationByIp("123.12"); res = await controller.GetLocationByIp("aa.12.12.12"); Assert.IsInstanceOf <OkObjectResult>(res); Assert.IsNull((res as OkObjectResult).Value); res = await controller.GetLocationByIp("777.12.12.12"); Assert.IsNull((res as OkObjectResult).Value); }
public IpControllerTest() { _domainService = new DomainService(); _ipRequestValidator = new DomainValidator(); _ipMapper = new IPMapper(); _errorMapper = new ErrorMapper(); _ipingMapper = new PingMapper(); _idnsMapper = new DnsMapper(); _irdapMapper = new RdapMapper(); _ipController = new IpController(_ipRequestValidator, _errorMapper, _domainService , _iconfig, _ipMapper, _idnsMapper, _ipingMapper, _irdapMapper); _ipController.ControllerContext = new ControllerContext(); _ipController.ControllerContext.HttpContext = new DefaultHttpContext(); }
public async Task Get_When_IPLookupReturnsValue_Then_SameValueReturnFromController() { // Arrange const string theServiceReturnValue = "This is whatever the service returns"; var ipLookupClient = new Mock <IIPLookupHttpClient>(); ipLookupClient.Setup(c => c.GetAsync()).ReturnsAsync(theServiceReturnValue); var controller = new IpController(Mock.Of <IHttpClientFactory>(), ipLookupClient.Object); // Act var response = await controller.Get(); // Assert var actionResult = response.Should().BeOfType <ActionResult <string> >().Subject; var okObjectResult = actionResult.Result.Should().BeOfType <OkObjectResult>().Subject; okObjectResult.Value.Should().BeOfType <string>() .Which.Should().Be(theServiceReturnValue); }
public async Task GetLocationTest() { var locationsList = new List <LocationModel>() { new LocationModel() { City = "1", Latitude = 1, Longitude = 1.2344f }, new LocationModel() { City = "2", Latitude = 2, Longitude = 2.2344f } }; var ip = "123.123.123.123"; queryMoq.Setup(p => p.GetLocationByIp(ip)).Returns(Task.FromResult(locationsList[0])); var controller = new IpController(queryMoq.Object); var res = await controller.GetLocationByIp(ip); queryMoq.Verify(p => p.GetLocationByIp(ip), Times.Once); Assert.AreEqual(locationsList[0], (res as OkObjectResult).Value);; }
public DefaultIpuSync(IpController controller, Func <IEnumerable <IpObject> > getter) { _controller = controller; _getter = getter; }