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
ConcurrentDictionary #1176
Comments
If anyone else comes accross the same issue, I've written a specimen builder for this: public class ConcurrentDictionaryGenerator : ISpecimenBuilder
{
public object Create(object request, ISpecimenContext context)
{
Type type = request as Type;
if (type == null)
{
return new NoSpecimen();
}
Type[] typeArguments = type.GetTypeInfo().GetGenericArguments();
if (typeArguments.Length != 2 || typeof(ConcurrentDictionary<,>).MakeGenericType(typeArguments) != type)
{
return new NoSpecimen();
}
Type nonConcurrentDictionaryType = typeof(Dictionary<,>).MakeGenericType(typeArguments);
IDictionary nonConcurrentDictionary = (IDictionary) context.Resolve(nonConcurrentDictionaryType);
IDictionary concurrentDictionary = (IDictionary) Activator.CreateInstance(type);
foreach (object key in nonConcurrentDictionary.Keys)
{
object value = nonConcurrentDictionary[key];
concurrentDictionary.Add(key, value);
}
return concurrentDictionary;
}
} |
Hello,
|
The more I learn about the internals of this library, the more I love it |
Interesting to know it's only on I guess the only remaining question for someone would then be: would this be a good feature to add? Perhaps not for |
Just that I dont spread wrong information, it is is not only Dictionary<,>. I just wanted to point out that the list of types can be found directly in Fixture.cs. E.g. it is also SortedDictionary<,>, but as you already figured out, it is not ConcurrentDictionary<,>. |
In reality what's hardcoded it's not the support rather the fact that interfaces are relayed to some concrete type. Like IDictionary and IReadOnlyDictionary are relayed to Dictionary, and so on. |
Hi,
When I use autofixture to generate a
Dictionary<T, U>
I get values populated in it by default, but with aConcurrentDictionary<T, U>
I don't.Is this by design & I should use a specimen builder to alter that behaviour myself, or is it a missing feature or bug?
The text was updated successfully, but these errors were encountered: