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

xunit: define codefixes for CollectionAsserts #133

Open
12 tasks
Tracked by #130
Meir017 opened this issue Jan 11, 2022 · 2 comments
Open
12 tasks
Tracked by #130

xunit: define codefixes for CollectionAsserts #133

Meir017 opened this issue Jan 11, 2022 · 2 comments

Comments

@Meir017
Copy link
Member

Meir017 commented Jan 11, 2022

The asserts defined in https://github.com/xunit/assert.xunit/blob/main/CollectionAsserts.cs

  • All
  • AllAsync?
  • Collection
  • CollectionAsync?
  • Contains
  • Distinct
  • DoesNotContain
  • Empty
  • NotEmpty
  • Equal
  • NotEqual
  • Single
@Meir017
Copy link
Member Author

Meir017 commented Jan 11, 2022

All:

public void All<T>(IEnumerable<T> collection, T expected)
{
    Assert.All(collection, x => Assert.Equal(expected, x));
    collection.Should().OnlyContain(x => x.Should().Be(expected));

    Assert.All(collection, x => Assert.NotEqual(expected, x));
    collection.Should().NotContain(x => x.Should().NotBe(expected));

    Assert.All(collection, x => Assert.Same(expected, x));
    collection.Should().OnlyContain(x => x.Should().BeSameAs(expected));

    Assert.All(collection, x => Assert.NotSame(expected, x));
    collection.Should().NotContain(x => x.Should().NotBeSameAs(expected));

    Assert.All(collection, i => Assert.IsType<int>(expected));
    collection.Should().AllBeOfType<int>();

    Assert.All(collection, i => Assert.IsAssignableFrom<int>(expected));
    collection.Should().AllBeAssignableTo<int>();
}

@Meir017
Copy link
Member Author

Meir017 commented Jan 11, 2022

Collection:

public void Collection<T>(IEnumerable<T> collection, params Action<T>[] elementInspectors)
{
    T expected = default;
    Assert.Collection(collection,
        x => Assert.Equal(x, expected),
        x => Assert.NotEqual(x, expected),
        x => Assert.Same(x, expected),
        x => Assert.NotSame(x, expected),
        x => Assert.IsType<int>(expected),
        x => Assert.IsAssignableFrom<int>(x)
    );
    collection.Should().Satisfy(
        x => x.Equals(expected),
        x => !x.Equals(expected),
        x => ReferenceEquals(expected, x),
        x => !ReferenceEquals(expected, x),
        x => x.GetType() == typeof(int),
        x => x.GetType().IsAssignableFrom(typeof(int))
    );
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant