public void ConfigureCertificateOptions_ThrowsOnNull()
        {
            var config         = new ConfigurationBuilder().Build();
            var configCertOpts = new ConfigureCertificateOptions(config);

            var constructorException = Assert.Throws <ArgumentNullException>(() => new ConfigureCertificateOptions(null));

            Assert.Equal("config", constructorException.ParamName);
            var configureException = Assert.Throws <ArgumentNullException>(() => configCertOpts.Configure(null, null));

            Assert.Equal("options", configureException.ParamName);
        }
        public void ConfigureCertificateOptions_NoPath_NoCertificate()
        {
            var config = new ConfigurationBuilder()
                         .AddInMemoryCollection(new Dictionary <string, string> {
                { "certificate", string.Empty }
            })
                         .Build();

            Assert.NotNull(config["certificate"]);
            var pkcs12Config = new ConfigureCertificateOptions(config);
            var opts         = new CertificateOptions();

            pkcs12Config.Configure(opts);
            Assert.Null(opts.Certificate);
            Assert.Equal(Microsoft.Extensions.Options.Options.DefaultName, opts.Name);
        }
        public void ConfigureCertificateOptions_ReadsFile_CreatesCertificate()
        {
            // Skipped on Mac due to inability to open a PKCS#12 with no password
            // https://github.com/dotnet/runtime/issues/23635
            var config = new ConfigurationBuilder()
                         .AddCertificateFile("instance.p12")
                         .Build();

            Assert.NotNull(config["certificate"]);
            var pkcs12Config = new ConfigureCertificateOptions(config);
            var opts         = new CertificateOptions();

            pkcs12Config.Configure(opts);
            Assert.NotNull(opts.Certificate);
            Assert.Equal(Microsoft.Extensions.Options.Options.DefaultName, opts.Name);
            Assert.True(opts.Certificate.HasPrivateKey);
        }