3

I have Some code where I have a fake configuration root. I would like to check that a call is made to set a config value.

var fakeConfigRoot = A.Fake<IConfigurationRoot>();

//Do something that will set config item

//A call to set the config must have happened

It is possible to fake getting a config item using

 A.CallTo(() => fakeConfigRoot["TestConfigItem"]).MustHaveHappened(Repeated.Exactly.Once);

I would like to know if it is possible using FakeItEasy to fake the assignment of a config item and if so how. If it is not possible can anyone think of any workarounds.

Keyur
  • 180
  • 1
  • 5
  • 20
milo.farrell
  • 662
  • 6
  • 19

1 Answers1

3

You want to specify a call to a property setter using A.CallToSet. The examples don't show it, but the syntax works for an indexer as well. Try this:

var fakeConfigRoot = A.Fake<IConfigurationRoot>();

fakeConfigRoot["animal"] = "hippo";

A.CallToSet(() => fakeConfigRoot["animal"]).MustHaveHappened(Repeated.Exactly.Once);
Blair Conrad
  • 233,004
  • 25
  • 132
  • 111