jediwhale / fitsharp

Functional testing tools for .NET
http://fitsharp.github.io
Other
152 stars 73 forks source link

Problems with Dictionary<string, string> #143

Closed Thaoden closed 8 years ago

Thaoden commented 8 years ago

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 |

fitSharp.Fit.Exception.FitFailureException: Column 'Server Name' not used.

What am I missing? Can I also use Dictionary<string, object>?

jediwhale commented 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

Thaoden commented 8 years ago

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");
    }
}        
jediwhale commented 8 years ago

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|

Thaoden commented 8 years ago

Does this mean that I can only check for the value parts and not for the presence of a key?

jediwhale commented 8 years ago

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| ... |

Thaoden commented 8 years ago

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?

jediwhale commented 8 years ago

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

Thaoden commented 8 years ago

Alright, I think I get it... Thanks!