diff --git a/dotnet/src/webdriver/DevTools/AuthRequiredEventArgs.cs b/dotnet/src/webdriver/DevTools/AuthRequiredEventArgs.cs index b80ff70628c32..0763b730eb120 100644 --- a/dotnet/src/webdriver/DevTools/AuthRequiredEventArgs.cs +++ b/dotnet/src/webdriver/DevTools/AuthRequiredEventArgs.cs @@ -19,6 +19,8 @@ using System; +#nullable enable + namespace OpenQA.Selenium.DevTools { /// @@ -26,14 +28,25 @@ namespace OpenQA.Selenium.DevTools /// public class AuthRequiredEventArgs : EventArgs { + /// + /// Initializes a new instance of the type. + /// + /// The request ID of the request raised the event. + /// The URI for which the event is raised. + public AuthRequiredEventArgs(string requestId, string uri) + { + Uri = uri; + RequestId = requestId; + } + /// /// Gets the URI for which the event is raised. /// - public string Uri { get; internal set; } + public string Uri { get; } /// /// Gets the request ID of the request raising the event. /// - public string RequestId { get; internal set; } + public string RequestId { get; } } } diff --git a/dotnet/src/webdriver/DevTools/BindingCalledEventArgs.cs b/dotnet/src/webdriver/DevTools/BindingCalledEventArgs.cs index dacb1d1af14e3..b51fc14f5f962 100644 --- a/dotnet/src/webdriver/DevTools/BindingCalledEventArgs.cs +++ b/dotnet/src/webdriver/DevTools/BindingCalledEventArgs.cs @@ -19,6 +19,8 @@ using System; +#nullable enable + namespace OpenQA.Selenium.DevTools { /// @@ -26,19 +28,32 @@ namespace OpenQA.Selenium.DevTools /// public class BindingCalledEventArgs : EventArgs { + /// + /// Initializes a new instance of the type. + /// + /// The execution ID of the call to the binding. + /// The name of the call to the binding. + /// The payload of the call to the binding. + public BindingCalledEventArgs(long executionContextId, string name, string payload) + { + this.ExecutionContextId = executionContextId; + this.Name = name; + this.Payload = payload; + } + /// /// Gets the execution context ID of the call to the binding. /// - public long ExecutionContextId { get; internal set; } + public long ExecutionContextId { get; } /// /// Gets the name of the call to the binding. /// - public string Name { get; internal set; } + public string Name { get; } /// /// Gets the payload of the call to the binding. /// - public string Payload { get; internal set; } + public string Payload { get; } } } diff --git a/dotnet/src/webdriver/DevTools/CommandResponseExtensions.cs b/dotnet/src/webdriver/DevTools/CommandResponseExtensions.cs index 2b619a7089089..d08895c4f9dd7 100644 --- a/dotnet/src/webdriver/DevTools/CommandResponseExtensions.cs +++ b/dotnet/src/webdriver/DevTools/CommandResponseExtensions.cs @@ -17,6 +17,8 @@ // under the License. // +#nullable enable + namespace OpenQA.Selenium.DevTools { /// @@ -29,8 +31,8 @@ public static class ICommandResponseExtensions /// /// The concrete implementation type of command response expected. /// The object to convert to the implementation type - /// The concrete implementation of the command response. - public static TCommandResponse GetResponse(this ICommandResponse response) + /// The concrete implementation of the command response, or if is not the right type. + public static TCommandResponse? GetResponse(this ICommandResponse response) where TCommandResponse : class, ICommandResponse { return response as TCommandResponse; diff --git a/dotnet/src/webdriver/DevTools/CommandResponseTypeMap.cs b/dotnet/src/webdriver/DevTools/CommandResponseTypeMap.cs index d0fb592e9740a..d4d3756238085 100644 --- a/dotnet/src/webdriver/DevTools/CommandResponseTypeMap.cs +++ b/dotnet/src/webdriver/DevTools/CommandResponseTypeMap.cs @@ -19,6 +19,9 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; + +#nullable enable namespace OpenQA.Selenium.DevTools { @@ -34,8 +37,19 @@ public class CommandResponseTypeMap /// /// The type of command to add the mapping for. /// The type of response object corresponding to the command. + /// If or are . public void AddCommandResponseType(Type commandSettingsType, Type commandResponseType) { + if (commandSettingsType is null) + { + throw new ArgumentNullException(nameof(commandSettingsType)); + } + + if (commandResponseType is null) + { + throw new ArgumentNullException(nameof(commandResponseType)); + } + if (!commandResponseTypeDictionary.ContainsKey(commandSettingsType)) { commandResponseTypeDictionary.Add(commandSettingsType, commandResponseType); @@ -48,7 +62,7 @@ public void AddCommandResponseType(Type commandSettingsType, Type commandRespons /// The type of command for which to retrieve the response type. /// The returned response type. /// if the specified command type has a mapped response type; otherwise, . - public bool TryGetCommandResponseType(out Type commandResponseType) + public bool TryGetCommandResponseType([NotNullWhen(true)] out Type? commandResponseType) where T : ICommand { return commandResponseTypeDictionary.TryGetValue(typeof(T), out commandResponseType); @@ -60,7 +74,7 @@ public bool TryGetCommandResponseType(out Type commandResponseType) /// The type of command for which to retrieve the response type. /// The returned response type. /// if the specified command type has a mapped response type; otherwise, . - public bool TryGetCommandResponseType(ICommand command, out Type commandResponseType) + public bool TryGetCommandResponseType(ICommand command, [NotNullWhen(true)] out Type? commandResponseType) { return commandResponseTypeDictionary.TryGetValue(command.GetType(), out commandResponseType); } diff --git a/dotnet/src/webdriver/DevTools/ConsoleApiArgument.cs b/dotnet/src/webdriver/DevTools/ConsoleApiArgument.cs index 0aa28ea11f188..bd5aae21cdb2f 100644 --- a/dotnet/src/webdriver/DevTools/ConsoleApiArgument.cs +++ b/dotnet/src/webdriver/DevTools/ConsoleApiArgument.cs @@ -17,6 +17,10 @@ // under the License. // +#nullable enable + +using System; + namespace OpenQA.Selenium.DevTools { /// @@ -24,14 +28,26 @@ namespace OpenQA.Selenium.DevTools /// public class ConsoleApiArgument { + /// + /// Initializes a new instance of the type. + /// + /// The type of the argument in the call to the browser's console API. + /// The value of the argument in the call to the browser's console API. + /// If is . + public ConsoleApiArgument(string type, string? value) + { + Type = type ?? throw new ArgumentNullException(nameof(type)); + Value = value; + } + /// /// Gets the type of the argument in the call to the browser's console API. /// - public string Type { get; internal set; } + public string Type { get; } /// /// Gets the value of the argument in the call to the browser's console API. /// - public string Value { get; internal set; } + public string? Value { get; } } } diff --git a/dotnet/src/webdriver/DevTools/ConsoleApiCalledEventArgs.cs b/dotnet/src/webdriver/DevTools/ConsoleApiCalledEventArgs.cs index 0295fb30e9dee..0c702fe22b558 100644 --- a/dotnet/src/webdriver/DevTools/ConsoleApiCalledEventArgs.cs +++ b/dotnet/src/webdriver/DevTools/ConsoleApiCalledEventArgs.cs @@ -20,6 +20,8 @@ using System; using System.Collections.ObjectModel; +#nullable enable + namespace OpenQA.Selenium.DevTools { /// @@ -27,19 +29,33 @@ namespace OpenQA.Selenium.DevTools /// public class ConsoleApiCalledEventArgs : EventArgs { + /// + /// Initializes a new instance of the type. + /// + /// The time stanp when the browser's console API is called. + /// The type of message when the browser's console API is called. + /// The arguments of the call to the browser's console API. + /// If is . + public ConsoleApiCalledEventArgs(DateTime timestamp, string type, ReadOnlyCollection arguments) + { + Timestamp = timestamp; + Type = type; + Arguments = arguments ?? throw new ArgumentNullException(nameof(arguments)); + } + /// /// Gets the time stanp when the browser's console API is called. /// - public DateTime Timestamp { get; internal set; } + public DateTime Timestamp { get; } /// /// Gets the type of message when the browser's console API is called. /// - public string Type { get; internal set; } + public string Type { get; } /// /// Gets the arguments of the call to the browser's console API. /// - public ReadOnlyCollection Arguments { get; internal set; } + public ReadOnlyCollection Arguments { get; } } } diff --git a/dotnet/src/webdriver/DevTools/DevToolsCommandData.cs b/dotnet/src/webdriver/DevTools/DevToolsCommandData.cs index bee0765169061..95e665fb634a3 100644 --- a/dotnet/src/webdriver/DevTools/DevToolsCommandData.cs +++ b/dotnet/src/webdriver/DevTools/DevToolsCommandData.cs @@ -17,11 +17,14 @@ // under the License. // +using System; using System.Text.Json; using System.Text.Json.Nodes; using System.Text.Json.Serialization; using System.Threading; +#nullable enable + namespace OpenQA.Selenium.DevTools { /// @@ -35,6 +38,7 @@ public class DevToolsCommandData /// The ID of the commmand execution. /// The method name of the DevTools command. /// The parameters of the DevTools command. + /// If is . public DevToolsCommandData(long commandId, string commandName, JsonNode commandParameters) : this(commandId, null, commandName, commandParameters) { @@ -47,11 +51,12 @@ public DevToolsCommandData(long commandId, string commandName, JsonNode commandP /// The session ID of the current command execution. /// The method name of the DevTools command. /// The parameters of the DevTools command. - public DevToolsCommandData(long commandId, string sessionId, string commandName, JsonNode commandParameters) + /// If is . + public DevToolsCommandData(long commandId, string? sessionId, string commandName, JsonNode commandParameters) { CommandId = commandId; SessionId = sessionId; - CommandName = commandName; + CommandName = commandName ?? throw new ArgumentNullException(nameof(commandName)); CommandParameters = commandParameters; SyncEvent = new ManualResetEventSlim(false); } @@ -61,7 +66,7 @@ public DevToolsCommandData(long commandId, string sessionId, string commandName, /// [JsonPropertyName("sessionId")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public string SessionId { get; } + public string? SessionId { get; } /// /// Gets the numeric ID of the command execution. diff --git a/dotnet/src/webdriver/DevTools/DevToolsEventData.cs b/dotnet/src/webdriver/DevTools/DevToolsEventData.cs index 1c527fb34f854..89cf25fec0624 100644 --- a/dotnet/src/webdriver/DevTools/DevToolsEventData.cs +++ b/dotnet/src/webdriver/DevTools/DevToolsEventData.cs @@ -19,6 +19,8 @@ using System; +#nullable enable + namespace OpenQA.Selenium.DevTools { /// @@ -31,10 +33,11 @@ public class DevToolsEventData /// /// The type of the event args for the event to be raised. /// The method that will be used to invoke the event. + /// If or is . public DevToolsEventData(Type eventArgsType, Action invoker) { - EventArgsType = eventArgsType; - EventInvoker = invoker; + EventArgsType = eventArgsType ?? throw new ArgumentNullException(nameof(eventArgsType)); + EventInvoker = invoker ?? throw new ArgumentNullException(nameof(invoker)); } /// diff --git a/dotnet/src/webdriver/DevTools/EntryAddedEventArgs.cs b/dotnet/src/webdriver/DevTools/EntryAddedEventArgs.cs index 83394c5b72347..42513ddd46479 100644 --- a/dotnet/src/webdriver/DevTools/EntryAddedEventArgs.cs +++ b/dotnet/src/webdriver/DevTools/EntryAddedEventArgs.cs @@ -19,6 +19,8 @@ using System; +#nullable enable + namespace OpenQA.Selenium.DevTools { /// @@ -26,9 +28,19 @@ namespace OpenQA.Selenium.DevTools /// public class EntryAddedEventArgs : EventArgs { + /// + /// Initializes a new instance of the type. + /// + /// The entry added to the browser's log. + /// If + public EntryAddedEventArgs(LogEntry entry) + { + Entry = entry ?? throw new ArgumentNullException(nameof(entry)); + } + /// /// The entry added to the browser's log. /// - public LogEntry Entry { get; set; } + public LogEntry Entry { get; } } } diff --git a/dotnet/src/webdriver/DevTools/LogEntry.cs b/dotnet/src/webdriver/DevTools/LogEntry.cs index cf9d379adc4fc..df120de4ee179 100644 --- a/dotnet/src/webdriver/DevTools/LogEntry.cs +++ b/dotnet/src/webdriver/DevTools/LogEntry.cs @@ -17,6 +17,8 @@ // under the License. // +#nullable enable + namespace OpenQA.Selenium.DevTools { /// @@ -24,14 +26,25 @@ namespace OpenQA.Selenium.DevTools /// public class LogEntry { + /// + /// Initializes a new instance of the type. + /// + /// The kind of message written to the log. + /// The text of the message written to the log. + public LogEntry(string kind, string message) + { + Kind = kind; + Message = message; + } + /// /// Gets the kind of message written to the log. /// - public string Kind { get; internal set; } + public string Kind { get; } /// /// Gets the text of the message written to the log. /// - public string Message { get; internal set; } + public string Message { get; } } } diff --git a/dotnet/src/webdriver/DevTools/RequestPausedEventArgs.cs b/dotnet/src/webdriver/DevTools/RequestPausedEventArgs.cs index 533ffaeee9a18..717a411cfc17e 100644 --- a/dotnet/src/webdriver/DevTools/RequestPausedEventArgs.cs +++ b/dotnet/src/webdriver/DevTools/RequestPausedEventArgs.cs @@ -19,6 +19,8 @@ using System; +#nullable enable + namespace OpenQA.Selenium.DevTools { /// @@ -26,14 +28,25 @@ namespace OpenQA.Selenium.DevTools /// public class RequestPausedEventArgs : EventArgs { + /// + /// Initializes a new instance of the type. + /// + /// The request ID. + /// The object for this request. + public RequestPausedEventArgs(string? requestId, HttpRequestData requestData) + { + RequestId = requestId; + RequestData = requestData; + } + /// /// Gets the request ID. /// - public string RequestId { get; internal set; } + public string? RequestId { get; } /// /// Gets the object for this request. /// - public HttpRequestData RequestData { get; internal set; } + public HttpRequestData RequestData { get; } } } diff --git a/dotnet/src/webdriver/DevTools/ResponsePausedEventArgs.cs b/dotnet/src/webdriver/DevTools/ResponsePausedEventArgs.cs index 30d658d856709..417a1e4b43680 100644 --- a/dotnet/src/webdriver/DevTools/ResponsePausedEventArgs.cs +++ b/dotnet/src/webdriver/DevTools/ResponsePausedEventArgs.cs @@ -26,9 +26,19 @@ namespace OpenQA.Selenium.DevTools /// public class ResponsePausedEventArgs : EventArgs { + /// + /// Initializes a new instance of the type. + /// + /// The object for this request. + /// If is . + public ResponsePausedEventArgs(HttpResponseData responseData) + { + ResponseData = responseData ?? throw new ArgumentNullException(nameof(responseData)); + } + /// /// Gets the object for this request. /// - public HttpResponseData ResponseData { get; internal set; } + public HttpResponseData ResponseData { get; } } } diff --git a/dotnet/src/webdriver/DevTools/TargetAttachedEventArgs.cs b/dotnet/src/webdriver/DevTools/TargetAttachedEventArgs.cs index ef95dcaacff5c..90cc8c2c2db44 100644 --- a/dotnet/src/webdriver/DevTools/TargetAttachedEventArgs.cs +++ b/dotnet/src/webdriver/DevTools/TargetAttachedEventArgs.cs @@ -19,6 +19,8 @@ using System; +#nullable enable + namespace OpenQA.Selenium.DevTools { /// @@ -26,17 +28,32 @@ namespace OpenQA.Selenium.DevTools /// public class TargetAttachedEventArgs : EventArgs { + /// + /// Initializes a new instance of the type. + /// + /// The ID of the session of the target attached. + /// The target which is attached. + /// If the target is waiting on the debugger. Target continues after invoking Runtime.runIfWaitingForDebugger. + public TargetAttachedEventArgs(string sessionId, TargetInfo? targetInfo, bool waitingForDebugger) + { + SessionId = sessionId; + TargetInfo = targetInfo; + WaitingForDebugger = waitingForDebugger; + } + /// /// Gets the ID of the session of the target attached. /// - public string SessionId { get; internal set; } + public string SessionId { get; } + /// /// Gets the target which is attached. /// - public TargetInfo TargetInfo { get; internal set; } + public TargetInfo? TargetInfo { get; } + /// - /// Gets if the target is waiting on the debugger. Target continues after invoking Runtime.runIfWaitingForDebugger. + /// Gets if the target is waiting on the debugger. Target continues after invoking Runtime.runIfWaitingForDebugger. /// - public bool WaitingForDebugger { get; internal set; } + public bool WaitingForDebugger { get; } } } diff --git a/dotnet/src/webdriver/DevTools/TargetDetachedEventArgs.cs b/dotnet/src/webdriver/DevTools/TargetDetachedEventArgs.cs index e2379ccf87767..a171f49b723e6 100644 --- a/dotnet/src/webdriver/DevTools/TargetDetachedEventArgs.cs +++ b/dotnet/src/webdriver/DevTools/TargetDetachedEventArgs.cs @@ -19,6 +19,8 @@ using System; +#nullable enable + namespace OpenQA.Selenium.DevTools { /// @@ -26,14 +28,25 @@ namespace OpenQA.Selenium.DevTools /// public class TargetDetachedEventArgs : EventArgs { + /// + /// Initializes a new instance of the type. + /// + /// The ID of the session of the target detached. + /// The ID of the target detached. + public TargetDetachedEventArgs(string sessionId, string? targetId) + { + SessionId = sessionId; + TargetId = targetId; + } + /// /// Gets the ID of the session of the target detached. /// - public string SessionId { get; internal set; } + public string SessionId { get; } /// /// Gets the ID of the target detached. /// - public string TargetId { get; internal set; } + public string? TargetId { get; } } } diff --git a/dotnet/src/webdriver/DevTools/WebSocketConnectionDataReceivedEventArgs.cs b/dotnet/src/webdriver/DevTools/WebSocketConnectionDataReceivedEventArgs.cs index a49755e8d53a7..1d062373ad952 100644 --- a/dotnet/src/webdriver/DevTools/WebSocketConnectionDataReceivedEventArgs.cs +++ b/dotnet/src/webdriver/DevTools/WebSocketConnectionDataReceivedEventArgs.cs @@ -19,6 +19,8 @@ using System; +#nullable enable + namespace OpenQA.Selenium.DevTools { /// @@ -26,20 +28,19 @@ namespace OpenQA.Selenium.DevTools /// public class WebSocketConnectionDataReceivedEventArgs : EventArgs { - private readonly string data; - /// /// Initializes a new instance of the class. /// /// The data received from the connection. + /// If is . public WebSocketConnectionDataReceivedEventArgs(string data) { - this.data = data; + this.Data = data ?? throw new ArgumentNullException(nameof(data)); } /// /// Gets the data received from the connection. /// - public string Data => this.data; + public string Data { get; } } } diff --git a/dotnet/src/webdriver/DevTools/v130/V130JavaScript.cs b/dotnet/src/webdriver/DevTools/v130/V130JavaScript.cs index 5980a7b8b1ce1..be462967b0f0b 100644 --- a/dotnet/src/webdriver/DevTools/v130/V130JavaScript.cs +++ b/dotnet/src/webdriver/DevTools/v130/V130JavaScript.cs @@ -140,12 +140,12 @@ internal override async Task Evaluate(string script) private void OnRuntimeBindingCalled(object sender, Runtime.BindingCalledEventArgs e) { - BindingCalledEventArgs wrapped = new BindingCalledEventArgs() - { - ExecutionContextId = e.ExecutionContextId, - Name = e.Name, - Payload = e.Payload - }; + BindingCalledEventArgs wrapped = new BindingCalledEventArgs + ( + executionContextId: e.ExecutionContextId, + name: e.Name, + payload: e.Payload + ); this.OnBindingCalled(wrapped); } @@ -167,20 +167,16 @@ private void OnRuntimeConsoleApiCalled(object sender, ConsoleAPICalledEventArgs List args = new List(); foreach (var arg in e.Args) { - string argValue = null; - if (arg.Value != null) - { - argValue = arg.Value.ToString(); - } - args.Add(new ConsoleApiArgument() { Type = arg.Type.ToString(), Value = argValue }); + string argValue = arg.Value?.ToString(); + args.Add(new ConsoleApiArgument(arg.Type.ToString(), argValue)); } - var wrapped = new ConsoleApiCalledEventArgs() - { - Timestamp = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(e.Timestamp), - Type = e.Type, - Arguments = args.AsReadOnly() - }; + var wrapped = new ConsoleApiCalledEventArgs + ( + timestamp: new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(e.Timestamp), + type: e.Type, + arguments: args.AsReadOnly() + ); this.OnConsoleApiCalled(wrapped); } diff --git a/dotnet/src/webdriver/DevTools/v130/V130Log.cs b/dotnet/src/webdriver/DevTools/v130/V130Log.cs index 74db09b353414..4a2e0a47b5f9f 100644 --- a/dotnet/src/webdriver/DevTools/v130/V130Log.cs +++ b/dotnet/src/webdriver/DevTools/v130/V130Log.cs @@ -68,10 +68,11 @@ public override async Task Clear() private void OnAdapterEntryAdded(object sender, Log.EntryAddedEventArgs e) { - EntryAddedEventArgs propagated = new EntryAddedEventArgs(); - propagated.Entry = new LogEntry(); - propagated.Entry.Kind = e.Entry.Source.ToString(); - propagated.Entry.Message = e.Entry.Text; + var entry = new LogEntry( + kind: e.Entry.Source.ToString(), + message: e.Entry.Text + ); + EntryAddedEventArgs propagated = new EntryAddedEventArgs(entry); this.OnEntryAdded(propagated); } } diff --git a/dotnet/src/webdriver/DevTools/v130/V130Network.cs b/dotnet/src/webdriver/DevTools/v130/V130Network.cs index cb7ccddbb1a00..74be92a081246 100644 --- a/dotnet/src/webdriver/DevTools/v130/V130Network.cs +++ b/dotnet/src/webdriver/DevTools/v130/V130Network.cs @@ -280,11 +280,11 @@ public override async Task ContinueResponseWithoutModification(HttpResponseData private void OnFetchAuthRequired(object sender, Fetch.AuthRequiredEventArgs e) { - AuthRequiredEventArgs wrapped = new AuthRequiredEventArgs() - { - RequestId = e.RequestId, - Uri = e.Request.Url - }; + AuthRequiredEventArgs wrapped = new AuthRequiredEventArgs + ( + requestId: e.RequestId, + uri: e.Request.Url + ); this.OnAuthRequired(wrapped); } @@ -293,8 +293,7 @@ private void OnFetchRequestPaused(object sender, Fetch.RequestPausedEventArgs e) { if (e.ResponseErrorReason == null && e.ResponseStatusCode == null) { - RequestPausedEventArgs wrapped = new RequestPausedEventArgs(); - wrapped.RequestData = new HttpRequestData() + var requestData = new HttpRequestData() { RequestId = e.RequestId, Method = e.Request.Method, @@ -303,17 +302,18 @@ private void OnFetchRequestPaused(object sender, Fetch.RequestPausedEventArgs e) Headers = new Dictionary(e.Request.Headers) }; + RequestPausedEventArgs wrapped = new RequestPausedEventArgs(null, requestData); this.OnRequestPaused(wrapped); } else { - ResponsePausedEventArgs wrappedResponse = new ResponsePausedEventArgs(); - wrappedResponse.ResponseData = new HttpResponseData() + var responseData = new HttpResponseData() { RequestId = e.RequestId, Url = e.Request.Url, ResourceType = e.ResourceType.ToString() }; + ResponsePausedEventArgs wrappedResponse = new ResponsePausedEventArgs(responseData); if (e.ResponseStatusCode.HasValue) { diff --git a/dotnet/src/webdriver/DevTools/v130/V130Target.cs b/dotnet/src/webdriver/DevTools/v130/V130Target.cs index 1a63134b3c547..24fed11d7408e 100644 --- a/dotnet/src/webdriver/DevTools/v130/V130Target.cs +++ b/dotnet/src/webdriver/DevTools/v130/V130Target.cs @@ -119,15 +119,12 @@ public override async Task SetAutoAttach() private void OnDetachedFromTarget(object sender, DetachedFromTargetEventArgs e) { - this.OnTargetDetached(new TargetDetachedEventArgs() { SessionId = e.SessionId, TargetId = e.TargetId }); + this.OnTargetDetached(new TargetDetachedEventArgs(e.SessionId, e.TargetId)); } private void OnAttachedToTarget(object sender, AttachedToTargetEventArgs e) { - this.OnTargetAttached(new TargetAttachedEventArgs() - { - SessionId = e.SessionId, - TargetInfo = e.TargetInfo == null ? null : new TargetInfo + var targetInfo = e.TargetInfo == null ? null : new TargetInfo { BrowserContextId = e.TargetInfo.BrowserContextId, IsAttached = e.TargetInfo.Attached, @@ -136,9 +133,14 @@ private void OnAttachedToTarget(object sender, AttachedToTargetEventArgs e) Title = e.TargetInfo.Title, Type = e.TargetInfo.Type, Url = e.TargetInfo.Url - }, - WaitingForDebugger = e.WaitingForDebugger - }); + }; + + this.OnTargetAttached(new TargetAttachedEventArgs + ( + sessionId: e.SessionId, + targetInfo: targetInfo, + waitingForDebugger: e.WaitingForDebugger + )); } internal override ICommand CreateSetAutoAttachCommand(bool waitForDebuggerOnStart) diff --git a/dotnet/src/webdriver/DevTools/v131/V131JavaScript.cs b/dotnet/src/webdriver/DevTools/v131/V131JavaScript.cs index 98ca5dc7f514a..873c03cc5360b 100644 --- a/dotnet/src/webdriver/DevTools/v131/V131JavaScript.cs +++ b/dotnet/src/webdriver/DevTools/v131/V131JavaScript.cs @@ -140,12 +140,12 @@ internal override async Task Evaluate(string script) private void OnRuntimeBindingCalled(object sender, Runtime.BindingCalledEventArgs e) { - BindingCalledEventArgs wrapped = new BindingCalledEventArgs() - { - ExecutionContextId = e.ExecutionContextId, - Name = e.Name, - Payload = e.Payload - }; + BindingCalledEventArgs wrapped = new BindingCalledEventArgs + ( + executionContextId: e.ExecutionContextId, + name: e.Name, + payload: e.Payload + ); this.OnBindingCalled(wrapped); } @@ -167,20 +167,16 @@ private void OnRuntimeConsoleApiCalled(object sender, ConsoleAPICalledEventArgs List args = new List(); foreach (var arg in e.Args) { - string argValue = null; - if (arg.Value != null) - { - argValue = arg.Value.ToString(); - } - args.Add(new ConsoleApiArgument() { Type = arg.Type.ToString(), Value = argValue }); + string argValue = arg.Value?.ToString(); + args.Add(new ConsoleApiArgument(arg.Type.ToString(), argValue)); } - var wrapped = new ConsoleApiCalledEventArgs() - { - Timestamp = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(e.Timestamp), - Type = e.Type, - Arguments = args.AsReadOnly() - }; + var wrapped = new ConsoleApiCalledEventArgs + ( + timestamp: new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(e.Timestamp), + type: e.Type, + arguments: args.AsReadOnly() + ); this.OnConsoleApiCalled(wrapped); } diff --git a/dotnet/src/webdriver/DevTools/v131/V131Log.cs b/dotnet/src/webdriver/DevTools/v131/V131Log.cs index 4b4ab1d667b70..a2134dbc9240b 100644 --- a/dotnet/src/webdriver/DevTools/v131/V131Log.cs +++ b/dotnet/src/webdriver/DevTools/v131/V131Log.cs @@ -68,10 +68,11 @@ public override async Task Clear() private void OnAdapterEntryAdded(object sender, Log.EntryAddedEventArgs e) { - EntryAddedEventArgs propagated = new EntryAddedEventArgs(); - propagated.Entry = new LogEntry(); - propagated.Entry.Kind = e.Entry.Source.ToString(); - propagated.Entry.Message = e.Entry.Text; + var entry = new LogEntry( + kind: e.Entry.Source.ToString(), + message: e.Entry.Text + ); + EntryAddedEventArgs propagated = new EntryAddedEventArgs(entry); this.OnEntryAdded(propagated); } } diff --git a/dotnet/src/webdriver/DevTools/v131/V131Network.cs b/dotnet/src/webdriver/DevTools/v131/V131Network.cs index 30e6e68f03e21..c8887543338be 100644 --- a/dotnet/src/webdriver/DevTools/v131/V131Network.cs +++ b/dotnet/src/webdriver/DevTools/v131/V131Network.cs @@ -280,11 +280,11 @@ public override async Task ContinueResponseWithoutModification(HttpResponseData private void OnFetchAuthRequired(object sender, Fetch.AuthRequiredEventArgs e) { - AuthRequiredEventArgs wrapped = new AuthRequiredEventArgs() - { - RequestId = e.RequestId, - Uri = e.Request.Url - }; + AuthRequiredEventArgs wrapped = new AuthRequiredEventArgs + ( + requestId: e.RequestId, + uri: e.Request.Url + ); this.OnAuthRequired(wrapped); } @@ -293,8 +293,7 @@ private void OnFetchRequestPaused(object sender, Fetch.RequestPausedEventArgs e) { if (e.ResponseErrorReason == null && e.ResponseStatusCode == null) { - RequestPausedEventArgs wrapped = new RequestPausedEventArgs(); - wrapped.RequestData = new HttpRequestData() + var requestData = new HttpRequestData() { RequestId = e.RequestId, Method = e.Request.Method, @@ -303,17 +302,18 @@ private void OnFetchRequestPaused(object sender, Fetch.RequestPausedEventArgs e) Headers = new Dictionary(e.Request.Headers) }; + RequestPausedEventArgs wrapped = new RequestPausedEventArgs(null, requestData); this.OnRequestPaused(wrapped); } else { - ResponsePausedEventArgs wrappedResponse = new ResponsePausedEventArgs(); - wrappedResponse.ResponseData = new HttpResponseData() + var responseData = new HttpResponseData() { RequestId = e.RequestId, Url = e.Request.Url, ResourceType = e.ResourceType.ToString() }; + ResponsePausedEventArgs wrappedResponse = new ResponsePausedEventArgs(responseData); if (e.ResponseStatusCode.HasValue) { diff --git a/dotnet/src/webdriver/DevTools/v131/V131Target.cs b/dotnet/src/webdriver/DevTools/v131/V131Target.cs index 3bf15943cbfec..760e2ecd3d876 100644 --- a/dotnet/src/webdriver/DevTools/v131/V131Target.cs +++ b/dotnet/src/webdriver/DevTools/v131/V131Target.cs @@ -119,15 +119,12 @@ public override async Task SetAutoAttach() private void OnDetachedFromTarget(object sender, DetachedFromTargetEventArgs e) { - this.OnTargetDetached(new TargetDetachedEventArgs() { SessionId = e.SessionId, TargetId = e.TargetId }); + this.OnTargetDetached(new TargetDetachedEventArgs(e.SessionId, e.TargetId)); } private void OnAttachedToTarget(object sender, AttachedToTargetEventArgs e) { - this.OnTargetAttached(new TargetAttachedEventArgs() - { - SessionId = e.SessionId, - TargetInfo = e.TargetInfo == null ? null : new TargetInfo + var targetInfo = e.TargetInfo == null ? null : new TargetInfo { BrowserContextId = e.TargetInfo.BrowserContextId, IsAttached = e.TargetInfo.Attached, @@ -136,9 +133,14 @@ private void OnAttachedToTarget(object sender, AttachedToTargetEventArgs e) Title = e.TargetInfo.Title, Type = e.TargetInfo.Type, Url = e.TargetInfo.Url - }, - WaitingForDebugger = e.WaitingForDebugger - }); + }; + + this.OnTargetAttached(new TargetAttachedEventArgs + ( + sessionId: e.SessionId, + targetInfo: targetInfo, + waitingForDebugger: e.WaitingForDebugger + )); } internal override ICommand CreateSetAutoAttachCommand(bool waitForDebuggerOnStart) diff --git a/dotnet/src/webdriver/DevTools/v132/V132JavaScript.cs b/dotnet/src/webdriver/DevTools/v132/V132JavaScript.cs index 798cc8226941e..6e9a093d145dd 100644 --- a/dotnet/src/webdriver/DevTools/v132/V132JavaScript.cs +++ b/dotnet/src/webdriver/DevTools/v132/V132JavaScript.cs @@ -140,12 +140,12 @@ internal override async Task Evaluate(string script) private void OnRuntimeBindingCalled(object sender, Runtime.BindingCalledEventArgs e) { - BindingCalledEventArgs wrapped = new BindingCalledEventArgs() - { - ExecutionContextId = e.ExecutionContextId, - Name = e.Name, - Payload = e.Payload - }; + BindingCalledEventArgs wrapped = new BindingCalledEventArgs + ( + executionContextId: e.ExecutionContextId, + name: e.Name, + payload: e.Payload + ); this.OnBindingCalled(wrapped); } @@ -167,20 +167,16 @@ private void OnRuntimeConsoleApiCalled(object sender, ConsoleAPICalledEventArgs List args = new List(); foreach (var arg in e.Args) { - string argValue = null; - if (arg.Value != null) - { - argValue = arg.Value.ToString(); - } - args.Add(new ConsoleApiArgument() { Type = arg.Type.ToString(), Value = argValue }); + string argValue = arg.Value?.ToString(); + args.Add(new ConsoleApiArgument(arg.Type.ToString(), argValue)); } - var wrapped = new ConsoleApiCalledEventArgs() - { - Timestamp = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(e.Timestamp), - Type = e.Type, - Arguments = args.AsReadOnly() - }; + var wrapped = new ConsoleApiCalledEventArgs + ( + timestamp: new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(e.Timestamp), + type: e.Type, + arguments: args.AsReadOnly() + ); this.OnConsoleApiCalled(wrapped); } diff --git a/dotnet/src/webdriver/DevTools/v132/V132Log.cs b/dotnet/src/webdriver/DevTools/v132/V132Log.cs index d4ee345831ca6..615290d05534e 100644 --- a/dotnet/src/webdriver/DevTools/v132/V132Log.cs +++ b/dotnet/src/webdriver/DevTools/v132/V132Log.cs @@ -68,10 +68,11 @@ public override async Task Clear() private void OnAdapterEntryAdded(object sender, Log.EntryAddedEventArgs e) { - EntryAddedEventArgs propagated = new EntryAddedEventArgs(); - propagated.Entry = new LogEntry(); - propagated.Entry.Kind = e.Entry.Source.ToString(); - propagated.Entry.Message = e.Entry.Text; + var entry = new LogEntry( + kind: e.Entry.Source.ToString(), + message: e.Entry.Text + ); + EntryAddedEventArgs propagated = new EntryAddedEventArgs(entry); this.OnEntryAdded(propagated); } } diff --git a/dotnet/src/webdriver/DevTools/v132/V132Network.cs b/dotnet/src/webdriver/DevTools/v132/V132Network.cs index a4cdee5658576..6acaf24d58472 100644 --- a/dotnet/src/webdriver/DevTools/v132/V132Network.cs +++ b/dotnet/src/webdriver/DevTools/v132/V132Network.cs @@ -280,11 +280,11 @@ public override async Task ContinueResponseWithoutModification(HttpResponseData private void OnFetchAuthRequired(object sender, Fetch.AuthRequiredEventArgs e) { - AuthRequiredEventArgs wrapped = new AuthRequiredEventArgs() - { - RequestId = e.RequestId, - Uri = e.Request.Url - }; + AuthRequiredEventArgs wrapped = new AuthRequiredEventArgs + ( + requestId: e.RequestId, + uri: e.Request.Url + ); this.OnAuthRequired(wrapped); } @@ -293,8 +293,7 @@ private void OnFetchRequestPaused(object sender, Fetch.RequestPausedEventArgs e) { if (e.ResponseErrorReason == null && e.ResponseStatusCode == null) { - RequestPausedEventArgs wrapped = new RequestPausedEventArgs(); - wrapped.RequestData = new HttpRequestData() + var requestData = new HttpRequestData() { RequestId = e.RequestId, Method = e.Request.Method, @@ -303,17 +302,18 @@ private void OnFetchRequestPaused(object sender, Fetch.RequestPausedEventArgs e) Headers = new Dictionary(e.Request.Headers) }; + RequestPausedEventArgs wrapped = new RequestPausedEventArgs(null, requestData); this.OnRequestPaused(wrapped); } else { - ResponsePausedEventArgs wrappedResponse = new ResponsePausedEventArgs(); - wrappedResponse.ResponseData = new HttpResponseData() + var responseData = new HttpResponseData() { RequestId = e.RequestId, Url = e.Request.Url, ResourceType = e.ResourceType.ToString() }; + ResponsePausedEventArgs wrappedResponse = new ResponsePausedEventArgs(responseData); if (e.ResponseStatusCode.HasValue) { diff --git a/dotnet/src/webdriver/DevTools/v132/V132Target.cs b/dotnet/src/webdriver/DevTools/v132/V132Target.cs index 6194dcad9a784..a1c69443bf21c 100644 --- a/dotnet/src/webdriver/DevTools/v132/V132Target.cs +++ b/dotnet/src/webdriver/DevTools/v132/V132Target.cs @@ -119,15 +119,12 @@ public override async Task SetAutoAttach() private void OnDetachedFromTarget(object sender, DetachedFromTargetEventArgs e) { - this.OnTargetDetached(new TargetDetachedEventArgs() { SessionId = e.SessionId, TargetId = e.TargetId }); + this.OnTargetDetached(new TargetDetachedEventArgs(e.SessionId, e.TargetId)); } private void OnAttachedToTarget(object sender, AttachedToTargetEventArgs e) { - this.OnTargetAttached(new TargetAttachedEventArgs() - { - SessionId = e.SessionId, - TargetInfo = e.TargetInfo == null ? null : new TargetInfo + var targetInfo = e.TargetInfo == null ? null : new TargetInfo { BrowserContextId = e.TargetInfo.BrowserContextId, IsAttached = e.TargetInfo.Attached, @@ -136,9 +133,14 @@ private void OnAttachedToTarget(object sender, AttachedToTargetEventArgs e) Title = e.TargetInfo.Title, Type = e.TargetInfo.Type, Url = e.TargetInfo.Url - }, - WaitingForDebugger = e.WaitingForDebugger - }); + }; + + this.OnTargetAttached(new TargetAttachedEventArgs + ( + sessionId: e.SessionId, + targetInfo: targetInfo, + waitingForDebugger: e.WaitingForDebugger + )); } internal override ICommand CreateSetAutoAttachCommand(bool waitForDebuggerOnStart) diff --git a/dotnet/src/webdriver/DevTools/v85/V85JavaScript.cs b/dotnet/src/webdriver/DevTools/v85/V85JavaScript.cs index 167d624e74541..570d05ada0c67 100644 --- a/dotnet/src/webdriver/DevTools/v85/V85JavaScript.cs +++ b/dotnet/src/webdriver/DevTools/v85/V85JavaScript.cs @@ -140,12 +140,12 @@ internal override async Task Evaluate(string script) private void OnRuntimeBindingCalled(object sender, Runtime.BindingCalledEventArgs e) { - BindingCalledEventArgs wrapped = new BindingCalledEventArgs() - { - ExecutionContextId = e.ExecutionContextId, - Name = e.Name, - Payload = e.Payload - }; + BindingCalledEventArgs wrapped = new BindingCalledEventArgs + ( + executionContextId: e.ExecutionContextId, + name: e.Name, + payload: e.Payload + ); this.OnBindingCalled(wrapped); } @@ -167,20 +167,16 @@ private void OnRuntimeConsoleApiCalled(object sender, ConsoleAPICalledEventArgs List args = new List(); foreach (var arg in e.Args) { - string argValue = null; - if (arg.Value != null) - { - argValue = arg.Value.ToString(); - } - args.Add(new ConsoleApiArgument() { Type = arg.Type.ToString(), Value = argValue }); + string argValue = arg.Value?.ToString(); + args.Add(new ConsoleApiArgument(arg.Type.ToString(), argValue)); } - var wrapped = new ConsoleApiCalledEventArgs() - { - Timestamp = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(e.Timestamp), - Type = e.Type, - Arguments = args.AsReadOnly() - }; + var wrapped = new ConsoleApiCalledEventArgs + ( + timestamp: new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(e.Timestamp), + type: e.Type, + arguments: args.AsReadOnly() + ); this.OnConsoleApiCalled(wrapped); } diff --git a/dotnet/src/webdriver/DevTools/v85/V85Log.cs b/dotnet/src/webdriver/DevTools/v85/V85Log.cs index 80b5816a597b4..12d9d4cbcb249 100644 --- a/dotnet/src/webdriver/DevTools/v85/V85Log.cs +++ b/dotnet/src/webdriver/DevTools/v85/V85Log.cs @@ -68,10 +68,11 @@ public override async Task Clear() private void OnAdapterEntryAdded(object sender, Log.EntryAddedEventArgs e) { - EntryAddedEventArgs propagated = new EntryAddedEventArgs(); - propagated.Entry = new LogEntry(); - propagated.Entry.Kind = e.Entry.Source.ToString(); - propagated.Entry.Message = e.Entry.Text; + var entry = new LogEntry( + kind: e.Entry.Source.ToString(), + message: e.Entry.Text + ); + EntryAddedEventArgs propagated = new EntryAddedEventArgs(entry); this.OnEntryAdded(propagated); } } diff --git a/dotnet/src/webdriver/DevTools/v85/V85Network.cs b/dotnet/src/webdriver/DevTools/v85/V85Network.cs index 6de68d8a60c3f..f660049cf2548 100644 --- a/dotnet/src/webdriver/DevTools/v85/V85Network.cs +++ b/dotnet/src/webdriver/DevTools/v85/V85Network.cs @@ -277,11 +277,11 @@ public override async Task ContinueResponseWithoutModification(HttpResponseData private void OnFetchAuthRequired(object sender, Fetch.AuthRequiredEventArgs e) { - AuthRequiredEventArgs wrapped = new AuthRequiredEventArgs() - { - RequestId = e.RequestId, - Uri = e.Request.Url - }; + AuthRequiredEventArgs wrapped = new AuthRequiredEventArgs + ( + requestId: e.RequestId, + uri: e.Request.Url + ); this.OnAuthRequired(wrapped); } @@ -290,8 +290,7 @@ private void OnFetchRequestPaused(object sender, Fetch.RequestPausedEventArgs e) { if (e.ResponseErrorReason == null && e.ResponseStatusCode == null) { - RequestPausedEventArgs wrapped = new RequestPausedEventArgs(); - wrapped.RequestData = new HttpRequestData() + var requestData = new HttpRequestData() { RequestId = e.RequestId, Method = e.Request.Method, @@ -300,17 +299,18 @@ private void OnFetchRequestPaused(object sender, Fetch.RequestPausedEventArgs e) Headers = new Dictionary(e.Request.Headers) }; + RequestPausedEventArgs wrapped = new RequestPausedEventArgs(null, requestData); this.OnRequestPaused(wrapped); } else { - ResponsePausedEventArgs wrappedResponse = new ResponsePausedEventArgs(); - wrappedResponse.ResponseData = new HttpResponseData() + var responseData = new HttpResponseData() { RequestId = e.RequestId, Url = e.Request.Url, ResourceType = e.ResourceType.ToString() }; + ResponsePausedEventArgs wrappedResponse = new ResponsePausedEventArgs(responseData); if (e.ResponseStatusCode.HasValue) { diff --git a/dotnet/src/webdriver/DevTools/v85/V85Target.cs b/dotnet/src/webdriver/DevTools/v85/V85Target.cs index a2b619ace0d74..70714c8d3406d 100644 --- a/dotnet/src/webdriver/DevTools/v85/V85Target.cs +++ b/dotnet/src/webdriver/DevTools/v85/V85Target.cs @@ -114,15 +114,12 @@ public override async Task SetAutoAttach() private void OnDetachedFromTarget(object sender, DetachedFromTargetEventArgs e) { - this.OnTargetDetached(new TargetDetachedEventArgs() { SessionId = e.SessionId, TargetId = e.TargetId }); + this.OnTargetDetached(new TargetDetachedEventArgs(e.SessionId, e.TargetId)); } private void OnAttachedToTarget(object sender, AttachedToTargetEventArgs e) - { - this.OnTargetAttached(new TargetAttachedEventArgs() { - SessionId = e.SessionId, - TargetInfo = e.TargetInfo == null ? null : new TargetInfo + var targetInfo = e.TargetInfo == null ? null : new TargetInfo { BrowserContextId = e.TargetInfo.BrowserContextId, IsAttached = e.TargetInfo.Attached, @@ -131,9 +128,14 @@ private void OnAttachedToTarget(object sender, AttachedToTargetEventArgs e) Title = e.TargetInfo.Title, Type = e.TargetInfo.Type, Url = e.TargetInfo.Url - }, - WaitingForDebugger = e.WaitingForDebugger - }); + }; + + this.OnTargetAttached(new TargetAttachedEventArgs + ( + sessionId: e.SessionId, + targetInfo: targetInfo, + waitingForDebugger: e.WaitingForDebugger + )); } internal override ICommand CreateSetAutoAttachCommand(bool waitForDebuggerOnStart)