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

[dotnet] Add nullability annotations to SessionId #14841

Merged
merged 18 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from 12 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
26 changes: 12 additions & 14 deletions dotnet/src/webdriver/SessionId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,27 @@
// under the License.
// </copyright>

using System;

#nullable enable

namespace OpenQA.Selenium
{
/// <summary>
/// Provides a mechanism for maintaining a session for a test
/// </summary>
public class SessionId
{
private string sessionOpaqueKey;
private readonly string sessionOpaqueKey;

/// <summary>
/// Initializes a new instance of the <see cref="SessionId"/> class
/// </summary>
/// <param name="opaqueKey">Key for the session in use</param>
/// <exception cref="ArgumentNullException">If <paramref name="opaqueKey"/> is <see langword="null"/>.</exception>
public SessionId(string opaqueKey)
{
this.sessionOpaqueKey = opaqueKey;
this.sessionOpaqueKey = opaqueKey ?? throw new ArgumentNullException(nameof(opaqueKey));
}

/// <summary>
Expand All @@ -54,20 +59,13 @@ public override int GetHashCode()
}

/// <summary>
/// Compares two Sessions
/// Indicates whether the current session ID value is the same as <paramref name="obj"/>.
/// </summary>
/// <param name="obj">Session to compare</param>
/// <returns>True if they are equal or False if they are not</returns>
public override bool Equals(object obj)
/// <param name="obj">The session to compare to.</param>
/// <returns><see langword="true"/> if the values are equal; otherwise, <see langword="false"/>.</returns>
public override bool Equals(object? obj)
{
bool objectsAreEqual = false;
SessionId other = obj as SessionId;
if (other != null)
{
objectsAreEqual = this.sessionOpaqueKey.Equals(other.sessionOpaqueKey);
}

return objectsAreEqual;
return obj is SessionId otherSession && this.sessionOpaqueKey.Equals(otherSession.sessionOpaqueKey);
}
}
}
4 changes: 3 additions & 1 deletion dotnet/src/webdriver/WebDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,9 @@ protected void StartSession(ICapabilities capabilities)

ReturnedCapabilities returnedCapabilities = new ReturnedCapabilities(rawCapabilities);
this.capabilities = returnedCapabilities;
this.sessionId = new SessionId(response.SessionId);

string sessionId = response.SessionId ?? throw new WebDriverException("StartSession did not return a sessionId");
this.sessionId = new SessionId(sessionId);
}

/// <summary>
Expand Down