Summary

Class:ProjectX.PublicApi.Extensions.StartupTwilio
Assembly:ProjectX.PublicApi
File(s):C:\private\projects\projectx\backend\src\ProjectX.PublicApi\Startup\StartupTwilio.cs
Covered lines:17
Uncovered lines:0
Coverable lines:17
Total lines:47
Line coverage:100%
Branch coverage:100%

History

Metrics

MethodCyclomatic complexity  NPath complexity  Sequence coverage  Branch coverage  
AddTwilio(...)64100100

File(s)

C:\private\projects\projectx\backend\src\ProjectX.PublicApi\Startup\StartupTwilio.cs

#LineLine coverage
 1using System;
 2using System.Linq;
 3using Microsoft.AspNetCore.Hosting;
 4using Microsoft.Extensions.Configuration;
 5using Microsoft.Extensions.DependencyInjection;
 6using ServiceBase.Notification.Sms;
 7using ServiceBase.Notification.Twilio;
 8
 9namespace ProjectX.PublicApi.Extensions
 10{
 11    public static class StartupTwilio
 12    {
 13        public static void AddTwilio(
 14            this IServiceCollection services,
 15            IHostingEnvironment environment,
 16            IConfiguration config)
 17        {
 2418             if (!environment.IsProduction())
 19            {
 20                // Check if ISmsService is already registerd
 2321                var descriptor = services
 74722                    .FirstOrDefault(d => d.ServiceType == typeof(ISmsService));
 23
 2324                 if (descriptor == null)
 25                {
 2226                    services.AddScoped<ISmsService, DebugSmsService>();
 27                }
 28
 2329                return;
 30            }
 31
 132            services.AddSingleton(config.GetSection("Sms")
 133                .Get<DefaultSmsServiceOptions>() ??
 134                throw new ApplicationException(
 135                    "Missing SMS configuration"));
 36
 137            services.AddScoped<ISmsService, DefaultSmsService>();
 38
 139            services.AddSingleton(config.GetSection("Sms:Twilio")
 140                .Get<TwilioOptions>() ??
 141                throw new ApplicationException(
 142                    "Missing Twilio configuration"));
 43
 144            services.AddScoped<ISmsSender, TwilioSmsSender>();
 145        }
 46    }
 47}