forked from getgauge/template-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
StepImplementation.cs
50 lines (44 loc) · 1.41 KB
/
StepImplementation.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System;
using System.Collections.Generic;
using System.Linq;
using FluentAssertions;
using Gauge.CSharp.Lib;
using Gauge.CSharp.Lib.Attribute;
namespace netcore.template
{
public class StepImplementation
{
private HashSet<char> _vowels;
[Step("Vowels in English language are <vowelString>.")]
public void SetLanguageVowels(string vowelString)
{
_vowels = new HashSet<char>();
foreach (var c in vowelString)
{
_vowels.Add(c);
}
}
[Step("The word <word> has <expectedCount> vowels.")]
public void VerifyVowelsCountInWord(string word, int expectedCount)
{
var actualCount = CountVowels(word);
actualCount.Should().Be(expectedCount);
}
[Step("Almost all words have vowels <wordsTable>")]
public void VerifyVowelsCountInMultipleWords(Table wordsTable)
{
var rows = wordsTable.GetTableRows();
foreach (var row in rows)
{
var word = row.GetCell("Word");
var expectedCount = Convert.ToInt32(row.GetCell("Vowel Count"));
var actualCount = CountVowels(word);
actualCount.Should().Be(expectedCount);
}
}
private int CountVowels(string word)
{
return word.Count(c => _vowels.Contains(c));
}
}
}