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.

What is your recommendation about where to specify global configuration

See original GitHub issue

With AssertionOptions.AssertEquivalencyUsing(options => options.IncludingAllRuntimeProperties()); I can specify my global configuration. But where to define it best?

Some static constructor of some random type?

Any advice?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:15 (13 by maintainers)

github_iconTop GitHub Comments

2reactions
dennisdoomencommented, May 7, 2020

Yep. That would be my first thought as well. I would welcome a PR or at least a separate issue.

2reactions
philippdoldercommented, May 7, 2020

Might be a bit late to the party, but I think we now got a solution that works for us (we’re using xUnit.net). From my understanding shared context in xUnit.net doesn’t work, since the AssertionOptions is static, i.e. one shared instance per AppDomain, i.e. broader lifetime than any xUnit shared contexts.

public static class GlobalFluentAssertionsConfiguration
{
    private static readonly object Lock = new object();
    private static bool alreadyLoaded = false;

    public static void Configure()
    {
        lock (Lock)
        {
            if (alreadyLoaded)
            {
                return;
            }

            alreadyLoaded = true;

            AssertionOptions.AssertEquivalencyUsing(
                options => <do your thing>);
        }
    }
}

we’re calling this method from the static ctor of every test that requires the special assertions. Without the check alreadyLoaded we started to have System.InvalidOperationException : Collection was modified; enumeration operation may not execute. caused by BeEquivalentTo().

Of course this can be a bit cumbersome if you have to do that in every unit test class. But that’s the only simple, reliable way I can think of currently, if you’re not into using some kind of magic as @ursenzler chose with Fody

Read more comments on GitHub >

github_iconTop Results From Across the Web

Overview of global configurations
A global configuration represents a physical or logical piece of a product offering. It gathers configurations for itself and other contributing Rational® ...
Read more >
Setting global configuration
Global configuration for your site is read from a file. The configuration is the mostly the same across SSGs with some minor differences....
Read more >
Using Global Configuration - IBKR Guides
From within Mosaic: Use the File menu and select Global Configuration. From with Classic TWS: Use the Edit menu select Global Configuration.
Read more >
Creating global configuration files
From the main menu of the Snap Creator GUI, select Management > Global Configurations. · In the Global Configurations pane, click Create Global....
Read more >
Using the Global Configuration Object
The global configuration specified by AWS.Config provides default settings for service objects that you create subsequently, simplifying their configuration.
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