Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overload constructors for ClusterState and DestinationState to enable unit testing #2198

Merged
merged 1 commit into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/ReverseProxy/Model/ClusterState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

using System;
using System.Collections.Concurrent;
using Microsoft.AspNetCore.Http;
using Yarp.ReverseProxy.Configuration;
using Yarp.ReverseProxy.Utilities;

namespace Yarp.ReverseProxy.Model;
Expand All @@ -24,6 +26,16 @@ public ClusterState(string clusterId)
ClusterId = clusterId ?? throw new ArgumentNullException(nameof(clusterId));
}

/// <summary>
/// Constructor overload to additionally initialize the <see cref="ClusterModel"/> for tests and infrastructure,
/// such as updating the <see cref="ReverseProxyFeature"/> via <see cref="HttpContextFeaturesExtensions"/>
/// </summary>
/// <exception cref="ArgumentNullException"><paramref name="model"/> is <see langword="null"/>.</exception>
public ClusterState(string clusterId, ClusterModel model) : this(clusterId)
{
Model = model ?? throw new ArgumentNullException(nameof(model));
}

/// <summary>
/// The cluster's unique id.
/// </summary>
Expand Down
11 changes: 11 additions & 0 deletions src/ReverseProxy/Model/DestinationState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Microsoft.AspNetCore.Http;
using Yarp.ReverseProxy.Utilities;

namespace Yarp.ReverseProxy.Model;
Expand All @@ -28,6 +29,16 @@ public DestinationState(string destinationId)
DestinationId = destinationId;
}

/// <summary>
/// Constructor overload to additionally initialize the <see cref="DestinationModel"/> for tests and infrastructure,
/// such as updating the <see cref="ReverseProxyFeature"/> via <see cref="HttpContextFeaturesExtensions"/>
/// </summary>
/// <exception cref="ArgumentNullException"><paramref name="model"/> is <see langword="null"/>.</exception>
public DestinationState(string destinationId, DestinationModel model) : this(destinationId)
{
Model = model ?? throw new ArgumentNullException(nameof(model));
}

/// <summary>
/// The destination's unique id.
/// </summary>
Expand Down