Hi all, I'm new to Typemock Isolator, and have a question about something that's not working how I'd expect.
Here is my test:
[TestMethod]
public async Task myTest()
{
//Arrange
Guid surveyRef = Guid.NewGuid();
Guid userRef = Guid.NewGuid();
UserSurveyEntity survey = new UserSurveyEntity
{
UserSurveyRef = surveyRef,
UserRef = userRef,
UserSurveyResults = new List<UserSurveyResultEntity>(),
UserAnswers = new List<UserAnswerEntity>()
};
Isolate.Swap.AllInstances<UserSurveyEntity>().With(survey);
// Act
var result = await Api.Calculate(surveyRef);
//Assert
Assert.IsNotNull(result);
}
and the method I'm testing:
public async Task<decimal> Calculate(Guid userSurveyRef)
{
using (DBEntitiesAccessor accessor = new DBEntitiesAccessor())
{
UserSurveyEntity survey1;
// get the survey from the db
UserSurveyEntity survey = await accessor.DataContext.UserSurveyEntities.Where(...).SingleOrDefaultAsync();
...
}
}
However, neither survey nor survey1 are replaced with my mocked value.
Any pointers?
Thanks.
PS, I was running this synchronously using
var result = Api.Calculate(surveyRef).Result;
I had the same issue, so I thought I'd try it async to see if it fixed it. It didn't, but now, after running it once async, I've also lost the little shield icon next to the test method, so I can't test it asynchronously any more. Is that normal?