Base solution for your next web application
Open Closed

Account App Service Should_Register Unit Test Methods fails #6984


User avatar
0
firnas created

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)
  • User Avatar
    0
    maliming created
    Support Team

    You should create an empty implementation such as NullSendGridEmailSender in the unit test for the ISendGridEmailSender interface, or simulate it using nsubstitute.

  • User Avatar
    0
    firnas created

    Is there any examples of such implementation i can refer to?

  • User Avatar
    0
    aaron created
    Support Team

    NullEmailSender. https://github.com/aspnetboilerplate/aspnetboilerplate/blob/dev/src/Abp/Net/Mail/NullEmailSender.cs

  • User Avatar
    0
    firnas created

    Thanks. I implemented a NullSendGridEmailSender and it worked.