Skip to content

Commit

Permalink
Added some useful inline docs for shared project
Browse files Browse the repository at this point in the history
  • Loading branch information
nvborisenko committed Feb 17, 2024
1 parent d6beea7 commit 261e3d6
Show file tree
Hide file tree
Showing 38 changed files with 682 additions and 16 deletions.
68 changes: 67 additions & 1 deletion src/ReportPortal.Shared/Execution/CommandsSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@

namespace ReportPortal.Shared.Execution
{
/// <inheritdoc cref="ICommandsSource"/>
/// <summary>
/// Represents a source of commands.
/// </summary>
public class CommandsSource : ICommandsSource
{
private IList<ICommandsListener> _listeners;

/// <summary>
/// Initializes a new instance of the <see cref="CommandsSource"/> class.
/// </summary>
/// <param name="listeners">The list of commands listeners.</param>
public CommandsSource(IList<ICommandsListener> listeners)
{
_listeners = listeners;
Expand All @@ -23,48 +29,108 @@ public CommandsSource(IList<ICommandsListener> listeners)
}
}

/// <summary>
/// Gets the test commands source.
/// </summary>
public ITestCommandsSource TestCommandsSource { get; } = new TestCommandsSource();

/// <summary>
/// Occurs when a begin log scope command is raised.
/// </summary>
public event LogCommandHandler<LogScopeCommandArgs> OnBeginLogScopeCommand;

/// <summary>
/// Occurs when an end log scope command is raised.
/// </summary>
public event LogCommandHandler<LogScopeCommandArgs> OnEndLogScopeCommand;

/// <summary>
/// Occurs when a log message command is raised.
/// </summary>
public event LogCommandHandler<LogMessageCommandArgs> OnLogMessageCommand;

/// <summary>
/// Raises the <see cref="OnBeginLogScopeCommand"/> event.
/// </summary>
/// <param name="commandsSource">The commands source.</param>
/// <param name="logContext">The log context.</param>
/// <param name="args">The command arguments.</param>
public static void RaiseOnBeginScopeCommand(CommandsSource commandsSource, ILogContext logContext, LogScopeCommandArgs args)
{
commandsSource.OnBeginLogScopeCommand?.Invoke(logContext, args);
}

/// <summary>
/// Raises the <see cref="OnEndLogScopeCommand"/> event.
/// </summary>
/// <param name="commandsSource">The commands source.</param>
/// <param name="logContext">The log context.</param>
/// <param name="args">The command arguments.</param>
public static void RaiseOnEndScopeCommand(CommandsSource commandsSource, ILogContext logContext, LogScopeCommandArgs args)
{
commandsSource.OnEndLogScopeCommand?.Invoke(logContext, args);
}

/// <summary>
/// Raises the <see cref="OnLogMessageCommand"/> event.
/// </summary>
/// <param name="commandsSource">The commands source.</param>
/// <param name="logContext">The log context.</param>
/// <param name="args">The command arguments.</param>
public static void RaiseOnLogMessageCommand(CommandsSource commandsSource, ILogContext logContext, LogMessageCommandArgs args)
{
commandsSource.OnLogMessageCommand?.Invoke(logContext, args);
}
}

/// <summary>
/// Represents a source of test commands.
/// </summary>
public class TestCommandsSource : ITestCommandsSource
{
/// <summary>
/// Occurs when a get test attributes command is raised.
/// </summary>
public event TestCommandHandler<TestAttributesCommandArgs> OnGetTestAttributes;

/// <summary>
/// Occurs when an add test attributes command is raised.
/// </summary>
public event TestCommandHandler<TestAttributesCommandArgs> OnAddTestAttributes;

/// <summary>
/// Occurs when a remove test attributes command is raised.
/// </summary>
public event TestCommandHandler<TestAttributesCommandArgs> OnRemoveTestAttributes;

/// <summary>
/// Raises the <see cref="OnGetTestAttributes"/> event.
/// </summary>
/// <param name="commandsSource">The commands source.</param>
/// <param name="testContext">The test context.</param>
/// <param name="args">The command arguments.</param>
public static void RaiseOnGetTestAttributes(TestCommandsSource commandsSource, ITestContext testContext, TestAttributesCommandArgs args)
{
commandsSource.OnGetTestAttributes?.Invoke(testContext, args);
}

/// <summary>
/// Raises the <see cref="OnAddTestAttributes"/> event.
/// </summary>
/// <param name="commandsSource">The commands source.</param>
/// <param name="testContext">The test context.</param>
/// <param name="args">The command arguments.</param>
public static void RaiseOnAddTestAttributes(TestCommandsSource commandsSource, ITestContext testContext, TestAttributesCommandArgs args)
{
commandsSource.OnAddTestAttributes?.Invoke(testContext, args);
}

/// <summary>
/// Raises the <see cref="OnRemoveTestAttributes"/> event.
/// </summary>
/// <param name="commandsSource">The commands source.</param>
/// <param name="testContext">The test context.</param>
/// <param name="args">The command arguments.</param>
public static void RaiseOnRemoveTestAttributes(TestCommandsSource commandsSource, ITestContext testContext, TestAttributesCommandArgs args)
{
commandsSource.OnRemoveTestAttributes?.Invoke(testContext, args);
Expand Down
25 changes: 24 additions & 1 deletion src/ReportPortal.Shared/Execution/Logging/LogScopeStatus.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,38 @@
namespace ReportPortal.Shared.Execution.Logging
{
/// <summary>
/// Status of logging scope.
/// Represents the status of a logging scope.
/// </summary>
public enum LogScopeStatus
{
/// <summary>
/// The logging scope is in progress.
/// </summary>
InProgress,

/// <summary>
/// The logging scope has passed.
/// </summary>
Passed,

/// <summary>
/// The logging scope has failed.
/// </summary>
Failed,

/// <summary>
/// The logging scope has been skipped.
/// </summary>
Skipped,

/// <summary>
/// The logging scope has a warning.
/// </summary>
Warn,

/// <summary>
/// The logging scope has informational messages.
/// </summary>
Info
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@

namespace ReportPortal.Shared.Execution.Metadata
{
/// <summary>
/// Represents a collection of meta attributes.
/// </summary>
public interface IMetaAttributesCollection : ICollection<MetaAttribute>
{
/// <summary>
/// Adds a new meta attribute with the specified key and value to the collection.
/// </summary>
/// <param name="key">The key of the meta attribute.</param>
/// <param name="value">The value of the meta attribute.</param>
void Add(string key, string value);
}
}
38 changes: 37 additions & 1 deletion src/ReportPortal.Shared/Execution/Metadata/MetaAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,44 @@

namespace ReportPortal.Shared.Execution.Metadata
{
/// <summary>
/// Represents a metadata attribute.
/// </summary>
public class MetaAttribute : IEquatable<MetaAttribute>
{
/// <summary>
/// Initializes a new instance of the <see cref="MetaAttribute"/> class.
/// </summary>
/// <param name="key">The attribute key.</param>
/// <param name="value">The attribute value.</param>
/// <exception cref="ArgumentException">Thrown when the attribute value is null or empty.</exception>
public MetaAttribute(string key, string value)
{
if (string.IsNullOrEmpty(value))
{
throw new ArgumentException("Attribute value cannot be null od empty.", nameof(value));
throw new ArgumentException("Attribute value cannot be null or empty.", nameof(value));
}

Key = key;
Value = value;
}

/// <summary>
/// Gets the attribute key.
/// </summary>
public string Key { get; }

/// <summary>
/// Gets the attribute value.
/// </summary>
public string Value { get; }

/// <summary>
/// Parses a string value into a <see cref="MetaAttribute"/> object.
/// </summary>
/// <param name="value">The string value to parse.</param>
/// <returns>A new instance of the <see cref="MetaAttribute"/> class.</returns>
/// <exception cref="ArgumentException">Thrown when the value is null or empty.</exception>
public static MetaAttribute Parse(string value)
{
if (string.IsNullOrEmpty(value))
Expand Down Expand Up @@ -49,6 +70,11 @@ public static MetaAttribute Parse(string value)
return new MetaAttribute(metaKey, metaValue);
}

/// <summary>
/// Determines whether the current <see cref="MetaAttribute"/> object is equal to another <see cref="MetaAttribute"/> object.
/// </summary>
/// <param name="other">The <see cref="MetaAttribute"/> object to compare with the current object.</param>
/// <returns>true if the objects are equal; otherwise, false.</returns>
public bool Equals(MetaAttribute other)
{
if (ReferenceEquals(this, other))
Expand All @@ -64,8 +90,18 @@ public bool Equals(MetaAttribute other)
return string.Equals(Key, other.Key) && string.Equals(Value, other.Value);
}

/// <summary>
/// Determines whether the current <see cref="MetaAttribute"/> object is equal to another object.
/// </summary>
/// <param name="obj">The object to compare with the current object.</param>
/// <returns>true if the objects are equal; otherwise, false.</returns>
public override bool Equals(object obj) => Equals(obj as MetaAttribute);

/// <summary>
/// Implicitly converts a <see cref="MetaAttribute"/> object to an <see cref="ItemAttribute"/> object.
/// </summary>
/// <param name="a">The <see cref="MetaAttribute"/> object to convert.</param>
/// <returns>An <see cref="ItemAttribute"/> object.</returns>
public static implicit operator ItemAttribute(MetaAttribute a) => new ItemAttribute { Key = a.Key, Value = a.Value };
}
}
17 changes: 13 additions & 4 deletions src/ReportPortal.Shared/Execution/TestContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,19 @@

namespace ReportPortal.Shared.Execution
{
/// <summary>
/// Represents the context for a test execution.
/// </summary>
public class TestContext : ITestContext
{
private readonly IExtensionManager _extensionManager;

private readonly CommandsSource _commadsSource;

/// <summary>
/// Initializes a new instance of the <see cref="TestContext"/> class.
/// </summary>
/// <param name="extensionManager">The extension manager.</param>
/// <param name="commandsSource">The commands source.</param>
public TestContext(IExtensionManager extensionManager, CommandsSource commandsSource)
{
_extensionManager = extensionManager;
Expand All @@ -19,11 +26,10 @@ public TestContext(IExtensionManager extensionManager, CommandsSource commandsSo
}

private readonly AsyncLocal<ILogScope> _activeLogScope = new AsyncLocal<ILogScope>();

private readonly AsyncLocal<ILogScope> _rootLogScope = new AsyncLocal<ILogScope>();

/// <summary>
/// Returns current active LogScope which provides methods for logging.
/// Gets or sets the current active LogScope which provides methods for logging.
/// </summary>
public ILogScope Log
{
Expand Down Expand Up @@ -59,6 +65,9 @@ private ILogScope RootScope
}
}

/// <summary>
/// Gets the metadata emitter for the test context.
/// </summary>
public ITestMetadataEmitter Metadata { get; private set; }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,30 @@

namespace ReportPortal.Shared.Extensibility.Commands.CommandArgs
{
/// <summary>
/// Represents the arguments for a log message command.
/// </summary>
public class LogMessageCommandArgs : EventArgs
{
/// <summary>
/// Initializes a new instance of the <see cref="LogMessageCommandArgs"/> class.
/// </summary>
/// <param name="logScope">The log scope.</param>
/// <param name="logMessage">The log message.</param>
public LogMessageCommandArgs(ILogScope logScope, ILogMessage logMessage)
{
LogScope = logScope;
LogMessage = logMessage;
}

/// <summary>
/// Gets the log scope.
/// </summary>
public ILogScope LogScope { get; }

/// <summary>
/// Gets the log message.
/// </summary>
public ILogMessage LogMessage { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,23 @@

namespace ReportPortal.Shared.Extensibility.Commands.CommandArgs
{
/// <summary>
/// Represents the arguments for a log scope command.
/// </summary>
public class LogScopeCommandArgs : EventArgs
{
/// <summary>
/// Initializes a new instance of the <see cref="LogScopeCommandArgs"/> class with the specified log scope.
/// </summary>
/// <param name="logScope">The log scope.</param>
public LogScopeCommandArgs(ILogScope logScope)
{
LogScope = logScope;
}

/// <summary>
/// Gets the log scope.
/// </summary>
public ILogScope LogScope { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,23 @@

namespace ReportPortal.Shared.Extensibility.Commands.CommandArgs
{
/// <summary>
/// Represents the arguments for the TestAttributesCommand event.
/// </summary>
public class TestAttributesCommandArgs : EventArgs
{
/// <summary>
/// Initializes a new instance of the <see cref="TestAttributesCommandArgs"/> class.
/// </summary>
/// <param name="attributes">The collection of meta attributes.</param>
public TestAttributesCommandArgs(ICollection<MetaAttribute> attributes)
{
Attributes = attributes ?? new List<MetaAttribute>();
}

/// <summary>
/// Gets the collection of meta attributes.
/// </summary>
public ICollection<MetaAttribute> Attributes { get; }
}
}
Loading

0 comments on commit 261e3d6

Please sign in to comment.