question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ConcurrentDictionary

See original GitHub issue

Hi, When I use autofixture to generate a Dictionary<T, U> I get values populated in it by default, but with a ConcurrentDictionary<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?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
Ergamoncommented, Apr 27, 2020

Hello, I cannot tell the reasons behind this, but it looking at the source code the supported collections are hard coded. So it is not something like “does type implement IDictionary”, it is “is type Dictionary<,>”. Therefore ConcurrentDictionary does not work. You dont need to create your own specimenbuilder, you can use what is already there:

      var fixture = new Fixture();

      var query = new ModestConstructorQuery();
      var methodInvoker = new MethodInvoker(query);
      var dictionaryFiller = new DictionaryFiller();
      var postProcessor = new Postprocessor(methodInvoker, dictionaryFiller);
      var exactTypeSpecification = new ExactTypeSpecification(typeof(ConcurrentDictionary<,>));
      var specimenBuilder = new FilteringSpecimenBuilder(postProcessor, exactTypeSpecification);

      fixture.Customizations.Add(specimenBuilder);
1reaction
Ergamoncommented, Apr 27, 2020

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<,>. By all means I would say that a future implementation should check for the interface.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ConcurrentDictionary<TKey,TValue> Class
Represents a thread-safe collection of key/value pairs that can be accessed by multiple threads concurrently.
Read more >
ConcurrentDictionary in C# - Introduction, Examples
ConcurrentDictionary is thread-safe collection class to store key/value pairs. It internally uses locking to provide you a thread-safe class. It provides ...
Read more >
ConcurrentDictionary in C# - Detailed Guide
This class has an internal state represented by a simple Dictionary . Its processing requires multiple steps which can execute concurrently.
Read more >
ConcurrentDictionary In C#
ConcurrentDictionary was introduced in .NET 4.0 and is available in the System.Collections.Concurrent namespace. It is thread-safe and ...
Read more >
c# - Concurrent Dictionary Correct Usage
ConcurrentDictionary <TKey, TValue> is designed for multithreaded scenarios. You do not have to use locks in your code to add or remove items ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found