Skip to content
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

Add Assert.RaisesAny and Assert.RaisesAnyAsync non-generic for EventArgs #2773

Closed
bradwilson opened this issue Sep 7, 2023 Discussed in #2772 · 1 comment
Closed

Add Assert.RaisesAny and Assert.RaisesAnyAsync non-generic for EventArgs #2773

bradwilson opened this issue Sep 7, 2023 Discussed in #2772 · 1 comment

Comments

@bradwilson
Copy link
Member

Discussed in #2772

Originally posted by tencek September 5, 2023
I know there's public static RaisedEvent<T> Raises<T>(...) in EventAsserts.cs but that only works for the EventHandler<TEventArgs>, AFAIK.
My event is of plain EventHandler type and I'd like to verify it was raised.
I ended up implementing it a bit dummy way on my own, here's the code:

    public class Testing
    {
        public static void RaisesEvent(
            Action<EventHandler> attach,
            Action<EventHandler> detach,
            Action testCode)
        {
            bool isEventRaised = false;
            var eventHandler = new EventHandler(delegate
            {
                isEventRaised = true;
            });

            attach(eventHandler);
            testCode();
            detach(eventHandler);

            Assert.True(isEventRaised);
        }
    }

Is there a way to achieve that using a standard xunit tools?
If not, would you consider adding it?

@bradwilson
Copy link
Member Author

In v2: 2.5.1-pre.31
In v3: 0.1.1-pre.279

agocke added a commit to agocke/arcade that referenced this issue Oct 11, 2023
…a..46dfaa92

46dfaa92 xunit/xunit#2773: Add Assert.RaisesAny and Assert.RaisesAnyAsync non-generic for EventArgs
c0485bdd Add additional NETSTANDARD excludeions for System.AppDomain usage
b6cb339c xunit/xunit#2767: Verify types match when comparing FileSystemInfo values
03b07513 Use AppDomain.CurrentDomain.GetAssemblies() to find System.IO.FileSystemInfo type
482be8e0 xunit/xunit#2767: Special case FileSystemInfo objects by just comparing the FullName in Assert.Equivalent
78d70dec xunit/xunit#2767: Prevent stack overflow in Assert.Equivalent with a max traversal depth of 50
d0a234a5 Delay calling Dispose() on CollectionTracker's inner enumerator, for xunit/xunit#2762
96236a4c Add disable for CS8607 in AssertEqualityComparerAdapter because of nullability inconsistency
6193f9ee Move to explicit DateTime(Offset) handling in Assert.Equivalent (related: xunit/xunit#2758)
20e76223 xunit/xunit#2743: Assert.Equal with HashSet and custom comparer ignores comparer
247c1016 Mark BitArray as safe to multi-enumerate
8926c0fc Wrap AssertEqualityComparer collection logic in !XUNIT_FRAMEWORK for v2 xunit.execution.*
90d59772 xunit/xunit#2755: Assert.Equal regression for dictionaries with collection values
17c7b611 Add nullable annotation to Assert.NotNull<T>(T?) (dotnet#64)
1886f126 xunit/xunit#2741: Ensure all exception factory methods are public

git-subtree-dir: src/Microsoft.DotNet.XUnitAssert/src
git-subtree-split: 46dfaa9248b7aa4c8c88e5cf6d4a6c84671a93f5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant