2

I have a class with a constructor, that gets an IStringLocalizer<T> injected.

public MailBuilder(IStringLocalizer<MailTexte> stringLocalizer)
{ ... }

I'm trying to setup the fake of the string localizer:

A.CallTo(() => this.stringLocalizer["ConfirmationMailTitel"]).Returns(subject);

But I get the message

IReturnValueArgumentValidationConfiguration LocalizedString does not contain a definition for 'Returns'

The interfact of the IStringLocalizer looks like this:

LocalizedString this[string name] { get; }

How can I setup this indexer correctly in FakeItEasy?

Thanks in advance

xeraphim
  • 4,375
  • 9
  • 54
  • 102

1 Answers1

3

You get the exception because most likely you are not returning the correct type (ie subject)

As shown in the interface, the indexer returns a LocalizedString.

Which would mean the mock need to be configured accordingly.

//...

var stringLocalizer = A.Fake<IStringLocalizer<MailTexte>>();
key = "ConfirmationMailTitel";
var localizedString = new LocalizedString(key, "desired localised value here");

A.CallTo(() => stringLocalizer["ConfirmationMailTitel"]).Returns(localizedString);

//...
Nkosi
  • 235,767
  • 35
  • 427
  • 472