C# Fluent Assertions global options for ShouldBeEquivalentTo

前端 未结 3 1797
我在风中等你
我在风中等你 2021-02-19 03:41

In Fluent Assertions when comparing objects with DateTime properties there are sometimes a slight mismatch in the milliseconds and the comparison fail. The way we get around it

3条回答
  •  你的背包
    2021-02-19 04:16

    Now this can be done with the AssertionOptions static class. To use a simple example:

    [TestInitialize]
    public void TestInit() {
      AssertionOptions.AssertEquivalencyUsing(options => options.ExcludingMissingMembers());
    }
    

    Or as in the example above:

    AssertionOptions.AssertEquivalencyUsing(options =>
      options.Using(ctx => ctx.Subject.Should().BeCloseTo(ctx.Expectation)).WhenTypeIs()
    );
    

提交回复
热议问题