Autofixture: Fill SortedLists

Created on 18 May 2016  ·  7Comments  ·  Source: AutoFixture/AutoFixture

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

``` C#
var fixture = new Fixture();
var actual = fixture.Create>();
Assert.NotEmpty(actual); // Succeeds

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

``` C#
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.

enhancement good first issue

Most helpful comment

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

All 7 comments

This issue was prompted by this Stack Overflow question.

See also #623 and #624.

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

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

@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 :smile:

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

If you need help with anything, please ask :smile:

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.

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zvirja picture zvirja  ·  3Comments

ecampidoglio picture ecampidoglio  ·  7Comments

zvirja picture zvirja  ·  4Comments

gtbuchanan picture gtbuchanan  ·  3Comments

JoshKeegan picture JoshKeegan  ·  6Comments