2

When running following test all the assertions fail. Can't figure out why they fail, because the actual implementation does have a call to the objects.

Is this a known bug? Because some other tests do succeed.

[Subject("Pst Cleanup")]
public class When_running_Pst_CleanUp
{
    Establish context = () =>
    {
        _folders = A.Fake<IOutlookFolderParameters>();
        _processor = A.Fake<IOutlookPstCleaner>();
    };

    Because of = () => _processor.Cleanup(_folders);

    It should_cleanup_the_mail_folder = () => A.CallTo(() => _folders.EmailFolder).MustHaveHappened();
    It should_cleanup_tasks_folder = () => A.CallTo(() => _folders.TaskFolder).MustHaveHappened();
    It should_cleanup_appointments_folder = () => A.CallTo(() => _folders.AppointmentFolder).MustHaveHappened();

    private static IOutlookPstCleaner _processor;
    private static IOutlookFolderParameters _folders;
}

Assertion failed for the following call: Outlook.Contracts.IOutlookFolderParameters.get_NotificationsFolder() Expected to find it at least once but no calls were made to the fake object.

at FakeItEasy.Core.FakeAsserter.AssertWasCalled(Func2 callPredicate, String callDescription, Func2 repeatPredicate, String repeatDescription) at FakeItEasy.Configuration.RuleBuilder.MustHaveHappened(Repeated repeatConstraint) at UnitTests.When_running_Pst_CleanUp.<.ctor>b__2() in When_running_Pst_CleanUp.cs: line 19

Community
  • 1
  • 1
Marco
  • 4,817
  • 5
  • 34
  • 75
  • Just added the test result. – Marco Mar 15 '13 at 12:40
  • I don't actually see an assertion to match the error. I don't see an expectation to call `get_NotificationsFolder()` (looks like the method generated for an Auto Property or something). Why are you testing that getters are called? That can't be properly pinning your behavior. What does the `_processor` _do_ to those folders that you can assert on instead? – Anthony Mastrean Mar 15 '13 at 17:41
  • 2
    Aw hell, your `_processor` is a fake, too. That's not going to work. It has to be a real instance. – Anthony Mastrean Mar 15 '13 at 17:44
  • the _processor does the actual cleanup in the pst. I test if the properties are called because this way I am for sure all the steps in the cleanup have took place... – Marco Mar 17 '13 at 13:33
  • but your _processor is a fake. you're not actually testing any of your own code here – Adam Ralph Apr 03 '13 at 10:52

1 Answers1

3

This is absolutely correct behavior of FakeItEasy. You need to use the real implementation for IOutlookPstCleaner to make your test succeed. Always make sure that you fake the correct things and don't fake your SUT accidentally.

With testing for the properties just being called you test absolutely nothing valuable. I could as well just write this implementation for IOutlookPstCleanerand your test would succeed:

public class Cleaner : IOutlookPstCleaner 
{
    public void Cleanup(IOutlookFolderParameters folders)
    {
        var email = folders.EmailFolder;
        var task = folders.TaskFolder;
        var appointment = folders.AppointmentFolder;
    }
}

If you post your implementation of IOutlookPstCleaner I'm happy to help you find the right things to test.

philippdolder
  • 271
  • 2
  • 5
  • +1 in the simplest case, it will be matter of replacing `_processor = A.Fake();` with `_processor = new OutlookPstCleaner();` and then actually testing something that should happen – Adam Ralph Apr 03 '13 at 10:54