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.

Specify desired amount of items when configuring a customization

See original GitHub issue

Hi,

I’m trying to test a piece of code that is sensible to the amount of items in a given set. Unluckily, I really can’t avoid passing proper data to activate a specific path.

I would normally use CreateMany<T>(int) to specify the amount of items I need, but the set is in a property of a container object (btw, I am addicted to the new relay for IReadOnlyList<T>) like

public class ContactIdList
{
    [JsonProperty("vids")]
    public IReadOnlyList<long> ContactIds { get; set; }

    [JsonProperty("vidOffset")]
    public long? Offset { get; set; }

    [JsonProperty("hasMore")]
    public bool HasMore { get; set; }
}

What I would suggest is to offer a way to specify the amount of items needed to be generated when customizing a type.

Ideally, something like this

var list = fixture.Build<ContactIdList>()
                  .With(p => p.HasMore, false)
                  .Without(p => p.Offset)
                  .WithMany(p => p.ContactIds, 16)
                  .Create();

The parameters should be something like (Expression<Func<T, IEnumerable<TProperty>> propertyPicker, int count) but I’m honestly torn between naming it WithMany<TProperty> and adding another overload of With<TProperty>.

Obviously, I’m aware that I can create the list before and use With<TProperty>(Expression<Func<T, TProperty> propertyPicker, TProperty value) to pass the list.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
zvirjacommented, Mar 5, 2018

Agreed 😉 Converting this to a potential feature.

1reaction
zvirjacommented, Mar 4, 2018

Thanks for raising the scenario.

I do understand the scenario you have, however I don’t like too much the suggested way to fix it. The scenario looks very specific to extend API for it.

Instead, it’s much better to implement it as a part of the #708. If we add the With() method overload taking the factory method, so it can be solved like this:

fixture.Customize<ClassToCustomize>(c =>
    c.With(x => x.Values, () => fixture.CreateMany<int>(25).ToList())
);

This solution is way more generic as behavior is not limited to collections only.

@moodmosaic I’d be really happy to implement #708 as it’s a real enabler for more specific scenario. Therefore, if you accept such a PR, I could implement it 😉

Read more comments on GitHub >

github_iconTop Results From Across the Web

Create and Manage Item Modifiers
Enter a name for the modifier set and select the items you'd like to ... Once you've customized your modifiers, your settings will...
Read more >
Customize your build - MSBuild
Many customizable build operations are controlled by properties. It is important to know how and where to set a property value in order...
Read more >
Add complementary products
Customizing the appearance of complementary products · Complementary products block ... Select the maximum number of complementary products to show.
Read more >
Customize Receipts: Advanced Configuration
You can customize your itemized receipts, configure tip lines, change how modifiers appear, and more. In this Article:
Read more >
The Alma User Interface
An administrator can configure the look and feel of Alma, including colors, logo, and default language. See User Interface Settings.
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