public void ShouldBuildEmailConfiguration()
        {
            const string businessId         = "businessId";
            var          hostSetting        = AppSetting.GetAppSetting("host");
            var          regionSetting      = AppSetting.GetAppSetting("region");
            var          emailFromSetting   = AppSetting.GetAppSetting("emailFrom");
            const string awsAccessKeyId     = "accessKey";
            const string awsSecretAccessKey = "secretKey";

            var amazonSESKeys = new AmazonSESKeys(awsAccessKeyId, awsSecretAccessKey);
            var appsettings   = new Mock <IApplicationConfiguration>();

            appsettings.Setup(o => o.GetEmailHost(businessId)).Returns(hostSetting);
            appsettings.Setup(o => o.GetEmailRegion(businessId)).Returns(regionSetting);
            appsettings.Setup(o => o.GetEmailEmailFrom(businessId)).Returns(emailFromSetting);

            var emailConfigurationBuilder = new EmailConfigurationBuilder(amazonSESKeys, appsettings.Object);

            var emailConfig = emailConfigurationBuilder.Build(businessId);

            emailConfig.Host.Should().Be(hostSetting.ToString());
            emailConfig.Region.Should().Be(regionSetting.ToString());
            emailConfig.AwsAccessKeyId.Should().Be(awsAccessKeyId);
            emailConfig.AwsSecretAccessKey.Should().Be(awsSecretAccessKey);
            emailConfig.EmailFrom.Should().Be(emailFromSetting.ToString());
        }
        public void ShouldReturnInvalidIfAPropertyIsNotValid(string host, string region, string accessKey, string secretKey, string emailFrom)
        {
            var hostSetting      = AppSetting.GetAppSetting(host);
            var regionSetting    = AppSetting.GetAppSetting(region);
            var awsKeys          = new AmazonSESKeys(accessKey, secretKey);
            var emailFromSetting = AppSetting.GetAppSetting(emailFrom);

            var amazonSesClientConfig = new AmazonSesClientConfiguration(hostSetting, regionSetting, emailFromSetting, awsKeys);

            var isValid = amazonSesClientConfig.IsValid();

            isValid.Should().BeFalse();
        }
Beispiel #3
0
        public AmazonSesClientConfiguration(AppSetting hostSetting, AppSetting regionSetting, AppSetting emailFromSetting, AmazonSESKeys awsKeys)
        {
            _hostSetting      = hostSetting;
            _regionSetting    = regionSetting;
            _emailFromSetting = emailFromSetting;
            _awsKeys          = awsKeys;

            Host               = hostSetting.ToString();
            Region             = regionSetting.ToString();
            Endpoint           = $"https://{Host}";
            AwsAccessKeyId     = awsKeys.Accesskey;
            AwsSecretAccessKey = awsKeys.SecretKey;
            EmailFrom          = emailFromSetting.ToString();
        }
        public static IServiceCollection AddSesEmailConfiguration(this IServiceCollection services, IConfiguration configuration, ILogger logger)
        {
            if (!string.IsNullOrEmpty(configuration["ses:accessKey"]) &&
                !string.IsNullOrEmpty(configuration["ses:secretKey"]))
            {
                var amazonSesKeys = new AmazonSESKeys(configuration["ses:accessKey"], configuration["ses:secretKey"]);
                services.AddSingleton(amazonSesKeys);
                var credentals = new BasicAWSCredentials(amazonSesKeys.Accesskey, amazonSesKeys.SecretKey);
                services.AddTransient <IAmazonSimpleEmailService>(
                    o => new AmazonSimpleEmailServiceClient(credentals, RegionEndpoint.EUWest1));
            }
            else
            {
                logger.Information("Secrets not found.");
            }

            return(services);
        }
        public void ShouldCreateAnAmazonSESClientConfiguration()
        {
            var host             = "a-host.com";
            var region           = "region";
            var accessKey        = "accessKey";
            var secretKey        = "secretKey";
            var emailFrom        = "*****@*****.**";
            var hostSetting      = AppSetting.GetAppSetting(host);
            var regionSetting    = AppSetting.GetAppSetting(region);
            var awsKeys          = new AmazonSESKeys(accessKey, secretKey);
            var emailFromSetting = AppSetting.GetAppSetting(emailFrom);

            var amazonSesClientConfig = new AmazonSesClientConfiguration(hostSetting, regionSetting, emailFromSetting, awsKeys);

            amazonSesClientConfig.Host.Should().Be(host);
            amazonSesClientConfig.Endpoint.Should().Be($"https://{host}");
            amazonSesClientConfig.Region.Should().Be(region);
            amazonSesClientConfig.EmailFrom.Should().Be(emailFrom);
            amazonSesClientConfig.AwsAccessKeyId.Should().Be(accessKey);
            amazonSesClientConfig.AwsSecretAccessKey.Should().Be(secretKey);

            amazonSesClientConfig.IsValid().Should().BeTrue();
        }
Beispiel #6
0
        public void ShouldBeValidIfParametersAreSet()
        {
            var keys = new AmazonSESKeys("accessKey", "secretKey");

            keys.IsValid().Should().BeFalse();
        }
Beispiel #7
0
        public void ShouldBeNotValidIfAnyParameterIsNullOrEmpty(string accessKey, string secretKey)
        {
            var keys = new AmazonSESKeys(accessKey, secretKey);

            keys.IsValid().Should().BeFalse();
        }