Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added capability to assert that a generic dictionary with string key and custom equality comparer contains key. #61

Merged
merged 3 commits into from
Jan 13, 2014

Conversation

voicu-matei
Copy link
Contributor

IDictionary<string, string> dictionary = new
ConcurrentDictionary<string, string>(StringComparer.OrdinalIgnoreCase);
dictionary.Add("name", "foo");

//The following 2 lines assert the same and should both pass
dictionary.ContainsKey("NaMe").Should().BeTrue(); //passes
dictionary.Should().ContainKey("NaMe"); //failed before

The fix assures that the second line passes also.

…and custom equality comparer contains key.

IDictionary<string, string> dictionary = new
ConcurrentDictionary<string, string>(StringComparer.OrdinalIgnoreCase);
dictionary.Add("name", "foo");

//The following 2 lines assert the same and should both pass
dictionary.ContainsKey("NaMe").Should().BeTrue(); //passes
dictionary.Should().ContainKey("NaMe"); //failed before

The fix assures that the second line passes also.
…and custom equality comparer contains key.

IDictionary<string, string> dictionary = new
ConcurrentDictionary<string, string>(StringComparer.OrdinalIgnoreCase);
dictionary.Add("name", "foo");

//The following 2 lines assert the same and should both pass
dictionary.ContainsKey("NaMe").Should().BeTrue(); //passes
dictionary.Should().ContainKey("NaMe"); //failed before

The fix assures that the second line passes also.
@dennisdoomen
Copy link
Member

Great work! Can you please use the When_should() naming convention for the spec itself and the arrange-act-assert structure within the spec?

@voicu-matei
Copy link
Contributor Author

Thanks!
I think for this it's a bit difficult to put in a Arrange-act-assert form. I would not know what the Act is in this case.

        //-----------------------------------------------------------------------------------------------------------
        // Arrange
        //-----------------------------------------------------------------------------------------------------------
        var dictionary = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
        {
            { "One", "One" },
            { "Two", "Two" }
        };

        //-----------------------------------------------------------------------------------------------------------
        // Act
        //-----------------------------------------------------------------------------------------------------------
        ??

        //-----------------------------------------------------------------------------------------------------------
        // Assert
        //-----------------------------------------------------------------------------------------------------------
        dictionary.Should().ContainKey("One");
        dictionary.Should().ContainKey("ONE");
        dictionary.Should().ContainKey("one");

@voicu-matei
Copy link
Contributor Author

Does this make sense for test method name?
When_asserting_dictionary_with_custom_equality_comparer_contains_a_key_from_the_dictionary_the_equality_comparer_should_be_used_for_comparing_keys

*a bit long though :)

@dennisdoomen
Copy link
Member

The spec is part of the dictionary specs, so why would you repeat the word dictionary at all?

    //-----------------------------------------------------------------------------------------------------------
    // Arrange
    //-----------------------------------------------------------------------------------------------------------
    var dictionary = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
    {
        { "One", "One" },
        { "Two", "Two" }
    };

    //-----------------------------------------------------------------------------------------------------------
    // Act
    //-----------------------------------------------------------------------------------------------------------
    Action act = () => dictionary.Should().ContainKey("One");

    //-----------------------------------------------------------------------------------------------------------
    // Assert
    //-----------------------------------------------------------------------------------------------------------
    act.ShouldNotThrow();

dennisdoomen added a commit that referenced this pull request Jan 13, 2014
Added capability to assert that a generic dictionary with string key and custom equality comparer contains key.
@dennisdoomen dennisdoomen merged commit a94e3cf into fluentassertions:master Jan 13, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants