fluentassertions.analyzers
fluentassertions.analyzers copied to clipboard
xunit: define codefixes for CollectionAsserts
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
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>();
}
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))
);
}