Closed Thaoden closed 8 years ago
What does the code for 'Test' look like?
On 2016-01-08 07:09, Thaoden wrote:
I have a |Dictionary<string, string>| in my system under test
The following table is throwing an error:
Test Server Name Server Details server For EPV null fitSharpFitExceptionFitFailureException: Column 'Server Name' not used
What am I missing? Can I also use |Dictionary<string, object>|?
— Reply to this email directly or view it on GitHub https://github.com/jediwhale/fitsharp/issues/143.
Cheers, Mike Stockdale
/fit/Sharp http://fitsharp.github.com
More complete test:
| Get Singleton By Identifier | ldapServer_EPV |
| Ldap Section |
| Test |
| Server Name | Server Details |
| server For EPV | null |
GetSingletonByIdentifier
returns a Configuration
-object:
public class Configuration
{
(...)
public LdapSection {get; set;}
}
public class LdapSection
{
public ConcurrentDictionary<string, string> Test {get; private set;}
public LdapSection()
{
Test = new ConcurrentDictionary<string,string>();
Test.TryAdd("serverForEPV","serverForEPV");
Test.TryAdd("serverIVS1","serverIVS1");
}
}
fitSharp is using servername and serverdetails as method names to call on the dictionary values. Since the dictionary values are strings, this is failing. You can use tostring as a method name:
|test| |tostring| |serverForEPV| |serverIVS1|
Does this mean that I can only check for the value parts and not for the presence of a key?
The default handling for a Dictionary is to check the values. If you want to check for the keys, you'd need some other method available for firSharp to use, e.g.:
public IEnumerable<string> TestKeys { get { return Test.Keys; } }
|testkeys| |tostring| | ... |
or you could make the dictionary the system-under-test and check methods on it:
|with|test| |ensure|contains key| ... |
The default handling for a Dictionary is to check the values.
Well then I don't understand the examples in http://fitsharp.github.io/Fit/FixtureWrapper.html and http://fitsharp.github.io/Fit/SetFixture.html; can you elaborate on them, please?
The 'named collection' fixtures (Array, Set, Subset, Row) are checking a collection of objects. The second row lists a set of fields, properties or methods that are checked on each object in the collection. The problem is a dictionary has two objects for each item in its collection, a key and a value. So to check keys and values, you need a method to extract the key-value pairs:
public IEnumerable<KeyValuePair<string, string>> TestKeyValues() {
return Test.AsEnumerable().OrderBy(p => p.Key);
}
|test key values| <== return a collection of KeyValuePair objects |key|value| <== list the properties to be checked on each object |...|...| <== expected values |...|...| etc
Alright, I think I get it... Thanks!
I have a
Dictionary<string, string>
in my system under test.The following table is throwing an error:
What am I missing? Can I also use
Dictionary<string, object>
?