public async Task <IActionResult> HandleServiceRequest([FromRoute] string address, ServiceType type) { _logger.LogInformation($"Processing {type} for {address}"); try { // not a fan of the controller having to know the specific // types for search service return(type switch { ServiceType.GeoIP => new OkObjectResult(await ServiceProcessor.Process <GeoIpModel>(address, type)), ServiceType.RDAP => new OkObjectResult(await ServiceProcessor.Process <RdapModel>(address, type)), ServiceType.ReverseDNS => new OkObjectResult(await ServiceProcessor.Process <IPHostEntry>(address, type)), ServiceType.SslLabs => new OkObjectResult( await ServiceProcessor.Process <SslLabsModel>(address, type)), ServiceType.Ping => new OkObjectResult(await ServiceProcessor.Process <PingModel>(address, type)), _ => new BadRequestObjectResult(new ServiceResult <string> { Status = ServiceStatus.Bad, Type = type, ErrorMessage = $"Invalid type passed in. Expected a {nameof(ServiceType)} but got {type}", WorkerId = Environment.MachineName, }) }); }
public async Task should_catch_on_unknown_service() { var actual = await ServiceProcessor.Process <object>("calebukle.com", (ServiceType)50); Assert.IsNotNull(actual.ErrorMessage); Assert.AreEqual(ServiceStatus.Error, actual.Status); }