Skip to content

Commit 3c5adaa

Browse files
authored
Merge pull request #82 from quantori/dropdown-checks-refactoring
Refactored dropdown bindings to use our implementation of FluentAssertions
2 parents e95be4c + 3f323ed commit 3c5adaa

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/Behavioral.Automation/Bindings/DropdownBinding.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Linq;
3-
using FluentAssertions;
44
using Behavioral.Automation.Elements;
55
using Behavioral.Automation.FluentAssertions;
66
using Behavioral.Automation.Model;
@@ -32,13 +32,13 @@ public void CheckSelectedValue([NotNull] IDropdownWrapper wrapper, AssertionBeha
3232
[Then("the (.*?) should have the following values:")]
3333
public void CheckAllItems([NotNull] IDropdownWrapper wrapper, [NotNull] Table items)
3434
{
35-
wrapper.Items.Should().BeEquivalentTo(items.Rows.Select(x => x.Values.Single()));
35+
CheckDropdownElements(wrapper.Items, items, $"{wrapper.Caption} values");
3636
}
3737

3838
[Then("(.*?) should have the following groups:")]
3939
public void CheckDropdownHeaders([NotNull] IGroupedDropdownWrapper wrapper, [NotNull] Table items)
4040
{
41-
wrapper.GroupTexts.Should().BeEquivalentTo(items.Rows.Select(x => x.Values.Single()));
41+
CheckDropdownElements(wrapper.GroupTexts, items, $"{wrapper.Caption} groups");
4242
}
4343

4444
[When("(.*?) (contain|not contain) \"(.*)\"")]
@@ -84,7 +84,7 @@ public void ClickOnMultipleEntries([NotNull] IMultiSelectDropdownWrapper wrapper
8484
[Then("the following values should be selected in (.*?):")]
8585
public void CheckMultipleSelectedValues([NotNull] IMultiSelectDropdownWrapper wrapper, [NotNull] Table values)
8686
{
87-
wrapper.SelectedValuesTexts.Should().BeEquivalentTo(values.Rows.Select(x => x.Values.Single()));
87+
CheckDropdownElements(wrapper.SelectedValuesTexts, values, $"{wrapper.Caption} selected values");
8888
}
8989

9090
[Given("the \"(.+?)\" value (is|become) (enabled|disabled) in (.+?)")]
@@ -136,6 +136,17 @@ public void CheckDropdownIsEmpty([NotNull] IDropdownWrapper wrapper, [NotNull] A
136136
Assert.ShouldBecome(() => wrapper.Empty, true, behavior,
137137
$"{wrapper.Caption} selected value is{behavior.BehaviorAppendix()} empty");
138138
}
139+
140+
private void CheckDropdownElements([NotNull] IEnumerable<string> actualValues, [NotNull] Table expectedValues, [NotNull] string valueType)
141+
{
142+
for (var i = 0; i < expectedValues.Rows.Count; i++)
143+
{
144+
var expectedValue = expectedValues.Rows.ElementAt(i).Values.FirstOrDefault();
145+
var actualValue = actualValues.Any()? actualValues.ElementAt(i) : null;
146+
Assert.ShouldBecome(() => expectedValue, actualValue,
147+
$"Expected one of the {valueType} to be {expectedValue} but was {actualValue}");
148+
}
149+
}
139150
}
140151
}
141152

0 commit comments

Comments
 (0)