using Opc.Ua; using ZB.MOM.WW.OtOpcUa.Client.Shared.Adapters; namespace ZB.MOM.WW.OtOpcUa.Client.Shared.Tests.Fakes; internal sealed class FakeEndpointDiscovery : IEndpointDiscovery { /// Gets or sets a value indicating whether SelectEndpoint should throw an exception. public bool ThrowOnSelect { get; set; } /// Gets the number of times SelectEndpoint has been called. public int SelectCallCount { get; private set; } /// Gets the last endpoint URL passed to SelectEndpoint. public string? LastEndpointUrl { get; private set; } /// Selects an endpoint for the given configuration and URL, optionally throwing an exception. /// The application configuration. /// The endpoint URL to select. /// The requested security mode. /// The selected endpoint description. public EndpointDescription SelectEndpoint(ApplicationConfiguration config, string endpointUrl, MessageSecurityMode requestedMode) { SelectCallCount++; LastEndpointUrl = endpointUrl; if (ThrowOnSelect) throw new InvalidOperationException($"No endpoint found for {endpointUrl}"); return new EndpointDescription { EndpointUrl = endpointUrl, SecurityMode = requestedMode, SecurityPolicyUri = requestedMode == MessageSecurityMode.None ? SecurityPolicies.None : SecurityPolicies.Basic256Sha256, Server = new ApplicationDescription { ApplicationName = "FakeServer", ApplicationUri = "urn:localhost:FakeServer" } }; } }