Skip to content
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
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ packages/*
**/.svn
_git2_*
**/StyleCop.Cache
*.DotSettings.user
*.DotSettings.user
# Build output nuget packages
*.nupkg
# Stray Windows-style path artifacts created by local build tools
**/C:/
12 changes: 12 additions & 0 deletions InteractiveAutomationToolkit/Components/CheckBoxList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,18 @@ public void RemoveOption(string option)
}
}

/// <inheritdoc/>
/// <exception cref="ArgumentNullException">When option is null.</exception>
public bool ContainsOption(string option)
{
if (option == null)
{
throw new ArgumentNullException(nameof(option));
}

return options.ContainsKey(option);
}

/// <inheritdoc/>
/// <exception cref="ArgumentNullException">When option is null.</exception>
/// <exception cref="ArgumentException">When the option does not exist.</exception>
Expand Down
30 changes: 30 additions & 0 deletions InteractiveAutomationToolkit/Components/DropDown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,36 @@ public void RemoveOption(string option)
}
}

/// <inheritdoc/>
/// <exception cref="ArgumentNullException">When option is null.</exception>
public bool ContainsOption(string option)
{
if (option == null)
{
throw new ArgumentNullException(nameof(option));
}

return options.Contains(option);
}

/// <inheritdoc/>
/// <exception cref="ArgumentNullException">When option is null.</exception>
public bool TrySelectOption(string option)
{
if (option == null)
{
throw new ArgumentNullException(nameof(option));
}

if (ContainsOption(option))
{
Selected = option;
return true;
}

return false;
}

/// <inheritdoc />
protected internal override void LoadResult(IUIResults uiResults, ILogger logger = null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,23 @@ public void AddOption(T value)
AddOption(new Option<T>(value));
}

/// <inheritdoc/>
public bool ContainsOption(Option<T> option)
{
if (option == null)
{
throw new ArgumentNullException(nameof(option));
}

return checkBoxListOptions.ContainsKey(option);
}

/// <inheritdoc/>
public bool ContainsOption(T value)
{
return checkBoxListOptions.Keys.Any(x => Object.Equals(x.Value, value));
}

/// <inheritdoc/>
/// <exception cref="ArgumentNullException">When option is null.</exception>
/// <exception cref="ArgumentException">When the option does not exist.</exception>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,54 @@ public void RemoveOption(T value)
}
}

/// <inheritdoc/>
/// <exception cref="ArgumentNullException">When option is null.</exception>
public bool ContainsOption(Option<T> option)
{
if (option == null)
{
throw new ArgumentNullException(nameof(option));
}

return dropDownOptions.Contains(option);
}

/// <inheritdoc/>
public bool ContainsOption(T value)
{
return dropDownOptions.Any(x => Object.Equals(x.Value, value));
}

/// <inheritdoc/>
public bool TrySelectOption(T value)
{
if (ContainsOption(value))
{
Selected = value;
return true;
}

return false;
}

/// <inheritdoc/>
/// <exception cref="ArgumentNullException">When option is null.</exception>
public bool TrySelectOption(Option<T> option)
{
if (option == null)
{
throw new ArgumentNullException(nameof(option));
}

if (ContainsOption(option))
{
SelectedOption = option;
return true;
}

return false;
}

/// <inheritdoc />
protected internal override void LoadResult(IUIResults uiResults, ILogger logger = null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,53 @@ public virtual void SetOptions(IEnumerable<T> options)
SetOptions(options.Select(x => new Option<T>(x)));
}

/// <inheritdoc/>
public bool ContainsOption(Option<T> option)
{
if (option == null)
{
throw new ArgumentNullException(nameof(option));
}

return radioButtonListOptions.Contains(option);
}

/// <inheritdoc/>
public bool ContainsOption(T value)
{
return radioButtonListOptions.Any(x => Object.Equals(x.Value, value));
}

/// <inheritdoc/>
public bool TrySelectOption(T value)
{
if (ContainsOption(value))
{
Selected = value;
return true;
}

return false;
}

/// <inheritdoc/>
/// <exception cref="ArgumentNullException">When option is null.</exception>
public bool TrySelectOption(Option<T> option)
{
if (option == null)
{
throw new ArgumentNullException(nameof(option));
}

if (ContainsOption(option))
{
SelectedOption = option;
return true;
}

return false;
}

/// <inheritdoc />
protected internal override void LoadResult(IUIResults uiResults, ILogger logger = null)
{
Expand Down
21 changes: 21 additions & 0 deletions InteractiveAutomationToolkit/Components/Interfaces/IDropDown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ public interface IDropDown : IOptionWidget
/// Gets or sets the currently selected option as a string.
/// </summary>
string Selected { get; set; }

/// <summary>
/// Attempts to select the specified option. If the option does not exist in the collection, the selection remains unchanged.
/// </summary>
/// <param name="option">The option to select.</param>
/// <returns><c>true</c> if the option was found and selected; otherwise, <c>false</c>.</returns>
bool TrySelectOption(string option);
}

/// <summary>
Expand All @@ -26,6 +33,20 @@ public interface IDropDown<T> : IOptionWidget<T>
/// Gets or sets the value of the currently selected option.
/// </summary>
T Selected { get; set; }

/// <summary>
/// Attempts to select the option with the specified value. If no matching option exists, the selection remains unchanged.
/// </summary>
/// <param name="value">The value of the option to select.</param>
/// <returns><c>true</c> if a matching option was found and selected; otherwise, <c>false</c>.</returns>
bool TrySelectOption(T value);

/// <summary>
/// Attempts to select the specified option. If the option does not exist in the collection, the selection remains unchanged.
/// </summary>
/// <param name="option">The option to select.</param>
/// <returns><c>true</c> if the option was found and selected; otherwise, <c>false</c>.</returns>
bool TrySelectOption(Option<T> option);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ public interface IOptionWidget
/// </summary>
/// <param name="option">The option to remove.</param>
void RemoveOption(string option);

/// <summary>
/// Determines whether the specified option exists in the collection.
/// </summary>
/// <param name="option">The name of the option to locate. Cannot be null.</param>
/// <returns>true if the option exists in the collection; otherwise, false.</returns>
bool ContainsOption(string option);
}

/// <summary>
Expand Down Expand Up @@ -82,6 +89,20 @@ public interface IOptionWidget<T>
/// </summary>
/// <param name="value">The value to remove.</param>
void RemoveOption(T value);

/// <summary>
/// Determines whether the specified option is present in the collection.
/// </summary>
/// <param name="option">The option to locate in the collection. Cannot be null.</param>
/// <returns>true if the specified option exists in the collection; otherwise, false.</returns>
bool ContainsOption(Option<T> option);

/// <summary>
/// Determines whether the specified option exists in the collection.
/// </summary>
/// <param name="value">The option value to locate in the collection.</param>
/// <returns>true if the specified option is found; otherwise, false.</returns>
bool ContainsOption(T value);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ public interface IRadioButtonList : IOptionWidget
/// Currently selected option.
/// </summary>
string Selected { get; set; }

/// <summary>
/// Attempts to select the specified option. If the option does not exist in the collection, the selection remains unchanged.
/// </summary>
/// <param name="option">The option to select.</param>
/// <returns><c>true</c> if the option was found and selected; otherwise, <c>false</c>.</returns>
bool TrySelectOption(string option);
}

/// <summary>
Expand All @@ -26,5 +33,19 @@ public interface IRadioButtonList<T> : IOptionWidget<T>
/// Value of the currently selected option.
/// </summary>
T Selected { get; set; }

/// <summary>
/// Attempts to select the option with the specified value. If no matching option exists, the selection remains unchanged.
/// </summary>
/// <param name="value">The value of the option to select.</param>
/// <returns><c>true</c> if a matching option was found and selected; otherwise, <c>false</c>.</returns>
bool TrySelectOption(T value);

/// <summary>
/// Attempts to select the specified option. If the option does not exist in the collection, the selection remains unchanged.
/// </summary>
/// <param name="option">The option to select.</param>
/// <returns><c>true</c> if the option was found and selected; otherwise, <c>false</c>.</returns>
bool TrySelectOption(Option<T> option);
}
}
29 changes: 29 additions & 0 deletions InteractiveAutomationToolkit/Components/RadioButtonList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,35 @@ public void SetOptions(IEnumerable<string> options)
}
}

/// <inheritdoc/>
public bool ContainsOption(string option)
{
if (option == null)
{
throw new ArgumentNullException(nameof(option));
}

return options.Contains(option);
}

/// <inheritdoc/>
/// <exception cref="ArgumentNullException">When option is null.</exception>
public bool TrySelectOption(string option)
{
if (option == null)
{
throw new ArgumentNullException(nameof(option));
}

if (ContainsOption(option))
{
Selected = option;
return true;
}

return false;
}

/// <inheritdoc />
protected internal override void LoadResult(IUIResults uiResults, ILogger logger = null)
{
Expand Down
25 changes: 25 additions & 0 deletions InteractiveAutomationToolkitTests/CheckBoxListTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Skyline.DataMiner.Utils.InteractiveAutomationScript;

namespace InteractiveAutomationToolkitTests
{
[TestClass]
public class CheckBoxListTests
{
[TestMethod]
public void ContainsOption_ExistingOption_ReturnsTrue()
{
var checkBoxList = new CheckBoxList(new[] { "a", "b", "c" });

Assert.IsTrue(checkBoxList.ContainsOption("b"));
}

[TestMethod]
public void ContainsOption_MissingOption_ReturnsFalse()
{
var checkBoxList = new CheckBoxList(new[] { "a", "b", "c" });

Assert.IsFalse(checkBoxList.ContainsOption("z"));
}
}
}
Loading
Loading