Skip to content

Commit

Permalink
♻️ (TfsProcessor.cs): refactor Source and Target properties to includ…
Browse files Browse the repository at this point in the history
…e type validation

✨ (TfsProcessor.cs): add ConfigurationValidationException for invalid endpoint types

The Source and Target properties now include type validation to ensure they are of type TfsTeamProjectEndpoint. If the type is incorrect, a ConfigurationValidationException is thrown, providing a clear error message. This change improves robustness by preventing misconfigurations and ensuring that the endpoints are of the expected type.
  • Loading branch information
MrHinsh committed Sep 15, 2024
1 parent 5bcbf70 commit ec114b7
Showing 1 changed file with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using MigrationTools;
using MigrationTools.Clients;
using MigrationTools.Enrichers;
using MigrationTools.Exceptions;
using MigrationTools.Tools;

namespace MigrationTools.Processors.Infrastructure
Expand All @@ -19,9 +20,31 @@ protected TfsProcessor(IOptions<ProcessorOptions> options, TfsCommonTools tfsCom

}

new public TfsTeamProjectEndpoint Source => (TfsTeamProjectEndpoint)base.Source;
new public TfsTeamProjectEndpoint Source
{
get
{
var endpoint = base.Source as TfsTeamProjectEndpoint;
if (endpoint == null)
{
throw new ConfigurationValidationException(Options, ValidateOptionsResult.Fail($"The Endpoint '{Options.SourceName}' specified for `{this.GetType().Name}` is of the wrong type! {nameof(TfsTeamProjectEndpoint)} was expected."));
}
return endpoint;
}
}

new public TfsTeamProjectEndpoint Target => (TfsTeamProjectEndpoint)base.Target;
new public TfsTeamProjectEndpoint Target
{
get
{
var endpoint = base.Target as TfsTeamProjectEndpoint;
if (endpoint == null)
{
throw new ConfigurationValidationException(Options, ValidateOptionsResult.Fail($"The Endpoint '{Options.TargetName}' specified for `{this.GetType().Name}` is of the wrong type! {nameof(TfsTeamProjectEndpoint)} was expected."));
}
return endpoint;
}
}

new public TfsCommonTools CommonTools => (TfsCommonTools)base.CommonTools;

Expand Down

0 comments on commit ec114b7

Please sign in to comment.