0

I have the following situation and any help would be appreciated.

public class Poco
{
  public string SomeData { get;set; }
  public string SomeMoreData { get;set; }
}

public class Worker
{
     public Poco DoWork()
     {
         // do stuff
     }
}

TESTING METHOD A.......

[Test]
public static void TestPocoIsPopulated()
{
    var objUt = new Worker();
    var actual = objUt.DoWork();       
    var expected = new Poco { SomeData = "reusltOne", SomeMoreData = "resultTwo" };

    actual.ShouldBeEquivalentTo(expected);

}

This works fine. However, with larger tests of nested classes, using ShouldBeEquivalentTo() becomes cumbersome, and I'd like to be able to do this as follows...

EDIT: Also with Method A you cant do this.... var expected = new Poco { SomeData = [NOT_NULL] , SomeMoreData = "resultTwo" };

TESTING METHOD B.......

[Test]
public static void TestPocoIsPopulated()
{
    var objUt = new Worker();
    var actual = objUt.DoWork();    

    actual.SomeData.Should().Be("resultOne");
    actual.SomeMoreData.Should().Be("resultTwo");
}

However, if I add a new property to Poco, then Testing Method B does not complain, and the property may not get tested. Using Method A however, the test will fail as ShouldBeEquivalentTo() will note that the new property is null

So, my question is, is there a method C as follows.

TESTING METHOD C.........

[Test]
public static void TestPocoIsPopulated()
{
    var objUt = new Worker();
    var actual = objUt.DoWork();    

    actual.SomeData.Should().Be("resultOne");
    actual.SomeMoreData.Should().Be("resultTwo");

    actual.Should().HaveAllPropertiesBeenTested().EqualTo(true); // <-------- is this possible?

}
SkeetJon
  • 1,491
  • 1
  • 19
  • 40
  • What's wrong with ShouldBeEquivalentTo exactly? It specifically does the thing you are asking. – Ufuk Hacıoğulları Dec 03 '13 at 15:28
  • you cant use Should().BeGreaterThan(1) within a ShouldBeEquivalentTo for example (see edit above) – SkeetJon Dec 03 '13 at 15:30
  • Yes you can. Just use one of the Using() methods on the options object to override the assertion for a particular property. See https://github.com/dennisdoomen/fluentassertions/wiki/Documentation#object-graph-comparison – Dennis Doomen Dec 04 '13 at 06:53

1 Answers1

0

The ultimate question to your answer is no, we don't support verifying whether all properties have been tested. That would require some kind of proxy generation technique that tracks access to a property. I must admit it is an interesting idea, so you could propose an enhancement on https://github.com/dennisdoomen/FluentAssertions/issues?state=open

Dennis Doomen
  • 8,368
  • 1
  • 32
  • 44