When I run the unit tests i see that the Should_Register unit test in AccountAppService_Tests fails. When troubleshooting the issue as to why it is failing, i figured out that it is failing when trying to send the email avtivation link,
await _userEmailer.SendEmailActivationLinkAsync(user, emailActivationLink);
I see that the IEmailSender is assigned NullEmailSender if in debug mode in the Core module,
if (DebugHelper.IsDebug) { //Disabling email sending in debug mode Configuration.ReplaceService<IEmailSender, NullEmailSender>(DependencyLifeStyle.Transient); }
I have implemented a interface ISendGridEmailSender which sends emails using sendgrid. While debugging i see that sending the activation link uses this service. That why the unit test is failing.
I tried to assign the NullEmailSender to the implemented ISendGridEmailSender as follows,
Configuration.ReplaceService<ISendGridEmailSender, NullEmailSender>(DependencyLifeStyle.Transient);
This gives an error stating that there is no implicit reference conversion between the two. How can I passing the NullEmailSender to the interface i have implemened and get the unit test to pass?
4 Answer(s)
-
0
You should create an empty implementation such as NullSendGridEmailSender in the unit test for the ISendGridEmailSender interface, or simulate it using nsubstitute.
-
0
Is there any examples of such implementation i can refer to?
-
0
NullEmailSender
. https://github.com/aspnetboilerplate/aspnetboilerplate/blob/dev/src/Abp/Net/Mail/NullEmailSender.cs -
0
Thanks. I implemented a NullSendGridEmailSender and it worked.