public static void Test_isSuccessful_True_On_Success(string endpoint, int port) { //arrange ResolveServiceEndpointResponseModel model = new ResolveServiceEndpointResponseModel(new ResolvedEndpoint(endpoint, port)); //assert Assert.True(model.isSuccessful); }
public static void Test_isSuccessful_False_On_Failed_ResponseCodes(ResolveServiceEndpointResponseCode resultCode) { //arrange ResolveServiceEndpointResponseModel model = new ResolveServiceEndpointResponseModel(resultCode); //assert Assert.False(model.isSuccessful); }
public static void Test_Can_JSON_Serialize_To_NonNull_Non_Whitespace(string endpoint, int port) { //arrange ResolveServiceEndpointResponseModel authModel = new ResolveServiceEndpointResponseModel(new ResolvedEndpoint(endpoint, port)); //act string serializedModel = JsonConvert.SerializeObject(authModel); //assert Assert.NotNull(serializedModel); Assert.IsNotEmpty(serializedModel); Assert.True(serializedModel.Contains(endpoint)); Assert.True(serializedModel.Contains(port.ToString())); }
public static void Test_Can_JSON_Serialize_Then_Deserialize_With_Preserved_Values(ResolveServiceEndpointResponseCode resultCode) { //arrange ResolveServiceEndpointResponseModel authModel = new ResolveServiceEndpointResponseModel(resultCode); //act ResolveServiceEndpointResponseModel deserializedModel = JsonConvert.DeserializeObject <ResolveServiceEndpointResponseModel>(JsonConvert.SerializeObject(authModel)); //assert Assert.NotNull(deserializedModel); Assert.Null(deserializedModel.Endpoint); Assert.True(Enum.IsDefined(typeof(ResolveServiceEndpointResponseCode), deserializedModel.ResultCode)); }
public static void Test_Can_JSON_Serialize_To_NonNull_Non_Whitespace(ResolveServiceEndpointResponseCode resultCode) { //arrange ResolveServiceEndpointResponseModel authModel = new ResolveServiceEndpointResponseModel(resultCode); //act string serializedModel = JsonConvert.SerializeObject(authModel); //assert Assert.NotNull(serializedModel); Assert.True(!serializedModel.Contains(nameof(authModel.isSuccessful)), $"JSON modle contains what should be unlisted field {nameof(authModel.isSuccessful)}. JSON: {serializedModel}"); Assert.IsNotEmpty(serializedModel); Assert.True(serializedModel.Contains(((int)resultCode).ToString())); }
public static void Test_Can_JSON_Serialize_Then_Deserialize_With_Preserved_Values(string endpoint, int port) { //arrange ResolveServiceEndpointResponseModel authModel = new ResolveServiceEndpointResponseModel(new ResolvedEndpoint(endpoint, port)); //act ResolveServiceEndpointResponseModel deserializedModel = JsonConvert.DeserializeObject <ResolveServiceEndpointResponseModel>(JsonConvert.SerializeObject(authModel)); //assert Assert.NotNull(deserializedModel); Assert.NotNull(deserializedModel.Endpoint); Assert.NotNull(deserializedModel.Endpoint.EndpointAddress); Assert.True(Enum.IsDefined(typeof(ResolveServiceEndpointResponseCode), deserializedModel.ResultCode)); Assert.AreEqual(endpoint, deserializedModel.Endpoint.EndpointAddress); Assert.AreEqual(port, deserializedModel.Endpoint.EndpointPort); }
private async Task <string> QueryServiceForEndpoint(string serviceType) { if (string.IsNullOrWhiteSpace(serviceType)) { throw new ArgumentException("Value cannot be null or whitespace.", nameof(serviceType)); } await Task.Delay(5000) .ConfigureAwait(false); IServiceDiscoveryService service = ServiceUrlToDiscoveryServiceMap[_ServiceDiscoveryEndpoint]; ResolveServiceEndpointResponseModel response = await service.Discover(new ResolveServiceEndpointRequestModel(Locale, serviceType)) .ConfigureAwait(false); if (!response.isSuccessful) { throw new InvalidOperationException($"Failed to query {nameof(IServiceDiscoveryService)} for the Service: {serviceType} in Locale: {Locale} for Reason: {response.ResultCode}."); } return($"{response.Endpoint.EndpointAddress}:{response.Endpoint.EndpointPort}"); }