Skip to content

Commit 2ec87f6

Browse files
Update tests
Signed-off-by: Yury-Fridlyand <[email protected]>
1 parent 61b8d6c commit 2ec87f6

File tree

4 files changed

+376
-697
lines changed

4 files changed

+376
-697
lines changed

sources/Valkey.Glide/Abstract/ConfigurationOptions.cs

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,11 @@ public static string TryNormalize(string value)
8787
}
8888
}
8989

90-
// Private fields
90+
#region Private fields
9191
private bool? ssl;
9292
private Proxy? proxy;
9393
private RetryStrategy? reconnectRetryPolicy;
94+
#endregion
9495

9596
/// <summary>
9697
/// Gets or sets whether connect/configuration timeouts should be explicitly notified via a TimeoutException.
@@ -468,10 +469,10 @@ private ConfigurationOptions DoParse(string configuration, bool ignoreUnknown =
468469
ResponseTimeout = OptionKeys.ParseInt32(key, value);
469470
break;
470471
case OptionKeys.ReadFrom:
471-
tempReadFromStrategy = ParseReadFromStrategy(value);
472+
tempReadFromStrategy = CheckReadFromValue(value);
472473
break;
473474
case OptionKeys.Az:
474-
tempAz = ParseAzParameter(value);
475+
tempAz = CheckAzValue(value);
475476
break;
476477
default:
477478
if (!ignoreUnknown) throw new ArgumentException($"Keyword '{key}' is not supported.", key);
@@ -496,53 +497,44 @@ private ConfigurationOptions DoParse(string configuration, bool ignoreUnknown =
496497
return this;
497498
}
498499

499-
private string ParseAzParameter(string value)
500+
private string CheckAzValue(string az)
500501
{
501-
if (string.IsNullOrWhiteSpace(value))
502+
if (string.IsNullOrWhiteSpace(az))
502503
{
503504
throw new ArgumentException("Availability zone cannot be empty or whitespace");
504505
}
505-
return value;
506+
return az;
506507
}
507508

508509
private ReadFrom? SetReadFrom(ReadFromStrategy? strategy, string? az)
509510
{
510511
if (strategy.HasValue)
511512
{
512513
// Use ReadFrom constructors based on strategy type - the constructors contain the validation logic
513-
#pragma warning disable IDE0066
514-
switch (strategy.Value)
514+
return strategy.Value switch
515515
{
516-
case ReadFromStrategy.AzAffinity:
517-
case ReadFromStrategy.AzAffinityReplicasAndPrimary:
518-
return new ReadFrom(strategy.Value, az!);
519-
520-
case ReadFromStrategy.Primary:
521-
case ReadFromStrategy.PreferReplica:
522-
return new ReadFrom(strategy.Value);
523-
524-
default:
525-
throw new ArgumentException($"ReadFrom strategy '{strategy.Value}' is not supported. Valid strategies are: Primary, PreferReplica, AzAffinity, AzAffinityReplicasAndPrimary");
526-
}
527-
#pragma warning restore IDE0066
516+
ReadFromStrategy.AzAffinity or ReadFromStrategy.AzAffinityReplicasAndPrimary => new ReadFrom(strategy.Value, az!),
517+
ReadFromStrategy.Primary or ReadFromStrategy.PreferReplica => new ReadFrom(strategy.Value),
518+
_ => throw new ArgumentException($"ReadFrom strategy '{strategy.Value}' is not supported. Valid strategies are: Primary, PreferReplica, AzAffinity, AzAffinityReplicasAndPrimary"),
519+
};
528520
}
529521
return null;
530522
}
531523

532-
private ReadFromStrategy ParseReadFromStrategy(string value)
524+
private ReadFromStrategy CheckReadFromValue(string readFrom)
533525
{
534-
if (string.IsNullOrWhiteSpace(value))
526+
if (string.IsNullOrWhiteSpace(readFrom))
535527
{
536528
throw new ArgumentException("ReadFrom strategy cannot be empty");
537529
}
538530

539531
try
540532
{
541-
return Enum.Parse<ReadFromStrategy>(value, ignoreCase: true);
533+
return Enum.Parse<ReadFromStrategy>(readFrom, ignoreCase: true);
542534
}
543535
catch (ArgumentException)
544536
{
545-
throw new ArgumentException($"ReadFrom strategy '{value}' is not supported. Valid strategies are: Primary, PreferReplica, AzAffinity, AzAffinityReplicasAndPrimary");
537+
throw new ArgumentException($"ReadFrom strategy '{readFrom}' is not supported. Valid strategies are: Primary, PreferReplica, AzAffinity, AzAffinityReplicasAndPrimary");
546538
}
547539
}
548540

0 commit comments

Comments
 (0)