I'm trying to implement a unit test with a methodcall assertion. (MustHaveHappened)
I'm using the following code:
[Fact]
public void Should_set_setting_and_map_new_value_for_non_existing_setting()
{
//Arrange
var userSetting = new SettingDetailsBuilder().Build();
var respository = A.Fake<ISettingsRepository>();
A.CallTo(() => respository.GetUserSetting(0, 0, null)).WithAnyArguments().Returns(userSetting);
var dataretriever = new SettingsDataRetriever(respository);
//Act
var newUserSetting = dataretriever.SetUserSetting("variableName", "SomeOtherValue", 1, 1, "FST");
//Assert
A.CallTo(() => respository.GetUserSetting(1, 1, "variableName")).MustHaveHappened();
}
But I get randomly a failed test, whereby some arguments are mentioned as "ignored". However, the assertion is with exact parameters.
Error:
Assertion failed for the following call:
AlfaProNext.Repositories.Settings.ISettingsRepository.GetUserSetting(1, <Ignored>, <Ignored>)
Expected to find it at least once but found it #0 times among the calls:
1: AlfaProNext.Repositories.Settings.ISettingsRepository.Exists(varName: "variableName")
2: AlfaProNext.Repositories.Settings.ISettingsRepository.GetUserSetting(
userId: 1,
profileId: 1,
variableName: "variableName")
Does anybody knows why this is happening randomly?
Aucun commentaire:
Enregistrer un commentaire