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
13 changes: 13 additions & 0 deletions src/Unicorn.UI.Core/Controls/Interfaces/IHasValue.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace Unicorn.UI.Core.Controls.Interfaces
{
/// <summary>
/// Interface for controls which have a value.
/// </summary>
public interface IHasValue
{
/// <summary>
/// Gets value as a <see cref="string"/>
/// </summary>
string Value { get; }
}
}
8 changes: 8 additions & 0 deletions src/Unicorn.UI.Core/Matchers/ControlMatchers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ public ControlHasValidationErrorMatcher HasValidationError() =>
public HasTitleMatcher HasTitle(string expectedTitle) =>
new HasTitleMatcher(expectedTitle);

/// <summary>
/// Gets matcher to check if control has specified value.
/// </summary>
/// <param name="expectedValue">expected control value</param>
/// <returns>matcher instance</returns>
public InputHasValueMatcher HasValue(string expectedValue) =>
new InputHasValueMatcher(expectedValue);

/// <summary>
/// Gets matcher to check if control contains specified sub-items.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
using System;
using Unicorn.Taf.Core.Verification.Matchers;
using Unicorn.UI.Core.Controls.Interfaces;
using Unicorn.UI.Core.Controls.Interfaces.Typified;

namespace Unicorn.UI.Core.Matchers.TypifiedMatchers
{
/// <summary>
/// Matcher to check if <see cref="ITextInput"/> UI control has specified value.
/// Matcher to check if <see cref="IHasValue"/> UI control has specified value.
/// </summary>
public class InputHasValueMatcher : TypeSafeMatcher<ITextInput>
public class InputHasValueMatcher : TypeSafeMatcher<IHasValue>
{
private readonly string _expectedValue;

Expand All @@ -25,11 +26,11 @@ public InputHasValueMatcher(string isChecked)
public override string CheckDescription => $"has value '{_expectedValue}'";

/// <summary>
/// Checks if text input has specified value.
/// Checks if control has specified value.
/// </summary>
/// <param name="actual">UI control under check</param>
/// <returns>true - if text input has expected value; otherwise - false</returns>
public override bool Matches(ITextInput actual)
/// <returns>true - if control has expected value; otherwise - false</returns>
public override bool Matches(IHasValue actual)
{
if (actual == null)
{
Expand All @@ -39,12 +40,12 @@ public override bool Matches(ITextInput actual)

var actualValue = actual.Value;

string mismatch = Reverse ?
actualValue :
string mismatch = Reverse ?
actualValue :
Environment.NewLine + MatchersUtils.GetStringsDiff(_expectedValue, actualValue);

DescribeMismatch(mismatch);

return actualValue.Equals(_expectedValue);
}
}
Expand Down
Loading