Created
February 9, 2025 15:55
-
-
Save fingers10/b86e263372c4f71f96f23f3ac7554bf5 to your computer and use it in GitHub Desktop.
FluentAsserions input statements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using FluentAssertions; | |
namespace ILoveDotNet.FluentAssertionToXUnitAssertion; | |
public class Tests | |
{ | |
public void FluentAssertionsToConvert() | |
{ | |
var result = new FluentAssertionDto(); | |
var results = new List<AnotherFluentAssertionDto>(); | |
Action act = () => | |
{ | |
Error error = new(); | |
}; | |
act.Should().Throw<Exception>().WithMessage("Error"); | |
result.Strings.Count.Should().BeGreaterThanOrEqualTo(1); | |
result.Strings[0].Should().Contain("XUnit"); | |
result.Strings[0].Should().Be("XUnit"); | |
results.Count.Should().Be(0); | |
results.Should().NotBeNull(); | |
results.Should().BeNull(); | |
result.Boolean.Should().BeTrue(); | |
result.Boolean.Should().BeFalse(); | |
result.Numbers.Should().NotContain(1); | |
result.Numbers.Should().HaveCount(0); | |
result.Numbers.Should().Equal(result.Numbers); | |
result.Numbers.Should().HaveCountGreaterThanOrEqualTo(0); | |
result.Now.Should().BeCloseTo(DateTimeOffset.Now, TimeSpan.FromMinutes(10)); | |
results[0].Now.Should().BeCloseTo(DateTimeOffset.Now, TimeSpan.FromMinutes(10)); | |
results[0].Number.Should().Be(0); | |
results[0].Numbers.Count.Should().BeGreaterThanOrEqualTo(0); | |
results[0].Numbers[0].Should().Be(0); | |
results[0].Persons[0].Name.Should().Be(string.Empty); | |
results[0].Persons![0].Name!.Should().BeEmpty(); | |
result.Should().NotBe(null); | |
result.Should().BeEquivalentTo(result); | |
result.Should().BeOfType<FluentAssertionDto>(); | |
result!.Should().Be(result); | |
result.Numbers.Sum().Should().Be(1); | |
results.Sum(x => x.Number).Should().Be(0); | |
results[0].Numbers.Sum().Should().Be(0); | |
results.Should().NotBeEmpty(); | |
result.Numbers.Should().HaveCountGreaterOrEqualTo(0); | |
} | |
} | |
public class FluentAssertionDto | |
{ | |
public List<string> Strings { get; set; } = ["XUnit"]; | |
public List<int> Numbers { get; set; } = [1]; | |
public bool Boolean { get; set; } | |
public DateTimeOffset Now { get; set; } = DateTimeOffset.UtcNow; | |
} | |
public class AnotherFluentAssertionDto | |
{ | |
public int Number { get; set; } | |
public DateTimeOffset Now { get; set; } = DateTimeOffset.UtcNow; | |
public List<int> Numbers { get; set; } = []; | |
public List<Person> Persons { get; set; } = []; | |
} | |
public class Person | |
{ | |
public string Name { get; set; } | |
} | |
public class Error | |
{ | |
public Error() | |
{ | |
throw new Exception("Error"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment