public static void Test_Can_JSON_Serialize_To_NonNull_Non_Whitespace(ClientRegionLocale region, string service) { //arrange ResolveServiceEndpointRequest model = new ResolveServiceEndpointRequest(region, service); //act string serializedModel = JsonConvert.SerializeObject(model); //assert Assert.NotNull(serializedModel); Assert.IsNotEmpty(serializedModel); }
public static void Test_Can_JSON_Serialize_Then_Deserialize_With_Preserved_Values(ClientRegionLocale region, string service) { //arrange ResolveServiceEndpointRequest model = new ResolveServiceEndpointRequest(region, service); //act ResolveServiceEndpointRequest deserializedModel = JsonConvert.DeserializeObject <ResolveServiceEndpointRequest>(JsonConvert.SerializeObject(model)); //assert Assert.NotNull(deserializedModel); Assert.True(Enum.IsDefined(typeof(ClientRegionLocale), deserializedModel.Region)); Assert.NotNull(deserializedModel.ServiceType); }
public async Task <ResolveServiceEndpointResponse> Discover([FromBody] ResolveServiceEndpointRequest requestModel) { if (LoggingService.IsEnabled(LogLevel.Debug)) { LoggingService.LogDebug($"Service Discover request for: {requestModel.Region}:{requestModel.ServiceType}"); } if (!ModelState.IsValid) { if (LoggingService.IsEnabled(LogLevel.Debug)) { LoggingService.LogDebug($"Resolution request was sent with an invalid model ModelState."); } return(new ResolveServiceEndpointResponse(ResolveServiceEndpointResponseCode.GeneralRequestError)); } //We need to check if we know about the locale //If we don't we should indicate it is unlisted //We also need to check if the keypair region and servicetype exist if (!await EndpointRepository.HasEntryAsync(requestModel.Region, requestModel.ServiceType)) { if (LoggingService.IsEnabled(LogLevel.Debug)) { LoggingService.LogDebug($"Client requested unlisted service Region: {requestModel.Region} Service: {requestModel.ServiceType}."); } return(new ResolveServiceEndpointResponse(ResolveServiceEndpointResponseCode.ServiceUnlisted)); } ResolvedEndpoint endpoint = await EndpointRepository.RetrieveAsync(requestModel.Region, requestModel.ServiceType); if (endpoint == null) { //Log the error. It shouldn't be null if the checks passed if (LoggingService.IsEnabled(LogLevel.Error)) { LoggingService.LogError($"Resolution request {requestModel.ServiceType} for region {requestModel.Region} failed even through it was a known pair."); } return(new ResolveServiceEndpointResponse(ResolveServiceEndpointResponseCode.GeneralRequestError)); } //Just return the JSON model response to the client return(new ResolveServiceEndpointResponse(endpoint)); }