public static void Test_Can_JSON_Serialize_To_NonNull_Non_Whitespace(ClientRegionLocale region, string service) { //arrange ResolveServiceEndpointRequestModel model = new ResolveServiceEndpointRequestModel(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 ResolveServiceEndpointRequestModel model = new ResolveServiceEndpointRequestModel(region, service); //act ResolveServiceEndpointRequestModel deserializedModel = JsonConvert.DeserializeObject <ResolveServiceEndpointRequestModel>(JsonConvert.SerializeObject(model)); //assert Assert.NotNull(deserializedModel); Assert.True(Enum.IsDefined(typeof(ClientRegionLocale), deserializedModel.Region)); Assert.NotNull(deserializedModel.ServiceType); }
public async Task <ResolveServiceEndpointResponseModel> Discover([FromBody] ResolveServiceEndpointRequestModel requestModel) { if (!ModelState.IsValid) { if (LoggingService.IsEnabled(LogLevel.Debug)) { LoggingService.LogDebug($"Resolution request was sent with an invalid model ModelState."); } return(new ResolveServiceEndpointResponseModel(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 ResolveServiceEndpointResponseModel(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 ResolveServiceEndpointResponseModel(ResolveServiceEndpointResponseCode.GeneralRequestError)); } //Just return the JSON model response to the client return(new ResolveServiceEndpointResponseModel(endpoint)); }