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
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);
//...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.