Closed amccool closed 9 months ago
Hi Alex, you can use the following workaround. Add the below extension method and use it instead of AsReference<T>()
. It will catch the exception during testing and return your mocked object.
public static class GrainExtensions
{
public static TGrainInterface AsSafeReference<TGrainInterface>(this IAddressable grain)
{
try
{
return grain.AsReference<TGrainInterface>();
}
catch (ArgumentException ex) when (ex.Message.Contains("Passing a half baked grain as an argument"))
{
return (TGrainInterface)grain;
}
}
}
getting the following when testing a timer
using
await Silo.FireAllTimersAsync();
onvar myGrain = await Silo.CreateGrainAsync<MyGrain>(myguid, myspecialstring);
timer is registered in
OnActivateAsync
timer callback looks like this:
the
AsReference
is used so the timer execution counts as a grain call.does the testkit handle this, or it this some other grain having an issue?