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

Fill SortedLists #622

Closed
ploeh opened this issue May 18, 2016 · 7 comments
Closed

Fill SortedLists #622

ploeh opened this issue May 18, 2016 · 7 comments

Comments

@ploeh
Copy link
Member

ploeh commented May 18, 2016

When you ask AutoFixture for a dictionary, it provides a non-empty value:

var fixture = new Fixture();
var actual = fixture.Create<IDictionary<int, string>>();
Assert.NotEmpty(actual); // Succeeds

When you request a sorted list, on the other hand, the returned list is empty. This test fails its assertion:

var fixture = new Fixture();
var actual = fixture.Create<SortedList<int, string>>();
Assert.NotEmpty(actual); // Fails

Since AutoFixture can already supply non-empty dictionaries, and one of the constructor overloads for SortedList<TKey, TValue> takes a dictionary, it ought to be fairly easy to add a relay from SortedList<TKey, TValue> to IDictionary<TKey, TValue>.

The implementation could for example be a new ISpecimenBuilder that handles requests for any SortedList<TKey, TValue> by resolving IDictionary<TKey, TValue> from the context, and then invoking the appropriate constructor overload with the returned value.

Another implementation option is to mimic the way concrete dictionaries are already filled. See the combination of DictionaryFiller and DictionarySpecification in the Fixture class.

@ploeh
Copy link
Member Author

ploeh commented May 18, 2016

This issue was prompted by this Stack Overflow question.

@ploeh ploeh mentioned this issue May 18, 2016
@ploeh
Copy link
Member Author

ploeh commented May 18, 2016

See also #623 and #624.

@sbrockway
Copy link
Contributor

@ploeh I'd like to take a shot at implementing this. I'm a newbie to git. I forked and have it going in VS locally. I assume I send a pull request when it is ready. Do you assign the issue to me, or is that not necessary? I don't see a way to assign it to myself.

@adamchester
Copy link
Member

@sbrockway announcing you're going to have a go at it should be enough, assigning shouldn't be necessary 👍

@ploeh
Copy link
Member Author

ploeh commented Jun 1, 2016

@sbrockway, @adamchester is right: making the announcement is usually enough. AutoFixture is a moderately successful open source project, so it sees a steady trickle of contributions, but I don't think I've ever seen a case where several contributors compete to do the same feature 😄

Other, more popular, projects may do things differently, so you did the right thing by asking 👍

If you need help with anything, please ask 😄

@sbrockway
Copy link
Contributor

I'm having trouble learning how to use GitHub. Apologies for the pull request yesterday, I was trying to re-base my fork and it mis-guessed which direction the pull request was moving. I figured it out and got my repo up to date.
I am stuck on how to rollback/revert my last commit to my repo so that I can get back the file I deleted to go the route you suggested. If you have any pointers on that, it would be helpful.

@ploeh
Copy link
Member Author

ploeh commented Jun 17, 2016

I don't know what your repo looks like. While I could look at your fork, I can't see what it looks like on your local machine, so it's difficult for me to offer concrete advice.

Often, with Git, if you're hopelessly lost, the easiest way out might be to start over with a new branch. That ensures that the original branch remains intact. This is important, because what I often hear that people do with Git is that in desperation, they attempt to run a command they don't fully understand, and they then end up deleting their work - for good!

The best advice I can give regarding Git is to take your time, and only do things you fully understand. In the rare cases where you'd like to attempt something you don't fully understand, at least do yourself the favour of creating a copy of your repository somewhere else. The beauty of Git is that it's fully file-based, so a (temporary) 'backup' can be as simple as copying the repository folder to your desktop.

@ploeh ploeh closed this as completed in ebd9e88 Aug 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants