コード例 #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });

            services
            .AddSingleton <IContentLinkUrlResolver, CustomContentLinkUrlResolver>()
            .AddSingleton <ITypeProvider, CustomTypeProvider>()
            .AddDeliveryClient(DeliveryOptionsBuilder.CreateInstance()
                               .WithProjectId("09fc0115-dd4d-00c7-5bd9-5f73836aee81")
                               .UseProductionApi
                               .WithMaxRetryAttempts(5)
                               .Build());

            // Equal expresison
            //services
            //    .AddSingleton(DeliveryClientBuilder
            //        .WithOptions(builder => builder
            //            .WithProjectId("09fc0115-dd4d-00c7-5bd9-5f73836aee81")
            //            .UseProductionApi
            //            .WithMaxRetryAttempts(5)
            //            .Build())
            //        .WithTypeProvider(new CustomTypeProvider())
            //        .WithContentLinkUrlResolver(new CustomContentLinkUrlResolver())
            //        .Build());

            // Here could be added Controller definition
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
        }
        private static IServiceCollection BuildOptions(this IServiceCollection services, Func <IDeliveryOptionsBuilder, DeliveryOptions> buildDeliveryOptions)
        {
            var builder = DeliveryOptionsBuilder.CreateInstance();
            var options = buildDeliveryOptions(builder);

            return(services.RegisterOptions(options));
        }
コード例 #3
0
 private static DeliveryOptions MockDeliveryOptions(string baseUrl)
 => DeliveryOptionsBuilder
 .CreateInstance()
 .WithProjectId(Guid.NewGuid())
 .UseProductionApi()
 .WithCustomEndpoint($"{baseUrl}/{{0}}")
 .Build();
コード例 #4
0
        public void ValidateOptionsWithNullSecuredApiKey()
        {
            var deliveryOptionsStep = DeliveryOptionsBuilder
                                      .CreateInstance()
                                      .WithProjectId(_guid);

            Assert.Throws <ArgumentNullException>(() => deliveryOptionsStep.UseSecuredProductionApi(null));
        }
コード例 #5
0
        public void ValidateOptionsBuiltWithBuilderWithIncorrectApiKeyFormat()
        {
            var deliveryOptions = DeliveryOptionsBuilder
                                  .CreateInstance()
                                  .WithProjectId(_guid);

            Assert.Throws <ArgumentException>(() => deliveryOptions.UsePreviewApi("badPreviewApiFormat"));
        }
コード例 #6
0
        public IOptionalClientSetup BuildWithDeliveryOptions(Func <IDeliveryOptionsBuilder, Delivery.DeliveryOptions> buildDeliveryOptions)
        {
            var builder = DeliveryOptionsBuilder.CreateInstance();

            _deliveryOptions = buildDeliveryOptions(builder);

            return(this);
        }
 public void BuildWithNullRetryPolicyOptions_ThrowsException()
 {
     Assert.Throws <ArgumentNullException>(() => DeliveryOptionsBuilder
                                           .CreateInstance()
                                           .WithProjectId(ProjectId)
                                           .UseProductionApi()
                                           .WithDefaultRetryPolicyOptions(null)
                                           .Build());
 }
コード例 #8
0
        public void ValidateOptionsWithInvalidEndpointFormat(string endpoint)
        {
            var deliveryOptionsSteps = DeliveryOptionsBuilder
                                       .CreateInstance()
                                       .WithProjectId(_guid)
                                       .UseProductionApi;

            Assert.Throws <ArgumentException>(() => deliveryOptionsSteps.WithCustomEndpoint(endpoint));
        }
コード例 #9
0
        public void ValidateOptionsWithNullUriEndpoint()
        {
            var deliveryOptionsSteps = DeliveryOptionsBuilder
                                       .CreateInstance()
                                       .WithProjectId(_guid)
                                       .UseProductionApi;

            Assert.Throws <ArgumentNullException>(() => deliveryOptionsSteps.WithCustomEndpoint((Uri)null));
        }
コード例 #10
0
        public void ValidateOptionsWithRelativeUriEndpoint()
        {
            var relativeUri          = new Uri("/abc/cde", UriKind.Relative);
            var deliveryOptionsSteps = DeliveryOptionsBuilder
                                       .CreateInstance()
                                       .WithProjectId(_guid)
                                       .UseProductionApi;

            Assert.Throws <ArgumentException>(() => deliveryOptionsSteps.WithCustomEndpoint(relativeUri));
        }
コード例 #11
0
        public void ValidateOptionsWithUriEndpointWrongScheme()
        {
            var incorrectSchemeUri   = new Uri("ftp://www.abc.com");
            var deliveryOptionsSteps = DeliveryOptionsBuilder
                                       .CreateInstance()
                                       .WithProjectId(_guid)
                                       .UseProductionApi;

            Assert.Throws <ArgumentException>(() => deliveryOptionsSteps.WithCustomEndpoint(incorrectSchemeUri));
        }
        public void BuildWithIncludeTotalCount()
        {
            var deliveryOptions = DeliveryOptionsBuilder
                                  .CreateInstance()
                                  .WithProjectId(Guid.NewGuid())
                                  .UseProductionApi()
                                  .IncludeTotalCount()
                                  .Build();

            Assert.True(deliveryOptions.IncludeTotalCount);
        }
コード例 #13
0
        public void BuildWithDisabledResilienceLogic()
        {
            var deliveryOptions = DeliveryOptionsBuilder
                                  .CreateInstance()
                                  .WithProjectId(Guid.NewGuid())
                                  .UseProductionApi
                                  .DisableResilienceLogic
                                  .Build();

            Assert.False(deliveryOptions.EnableResilienceLogic);
        }
コード例 #14
0
        public void BuildWithWaitForLoadingNewContent()
        {
            var deliveryOptions = DeliveryOptionsBuilder
                                  .CreateInstance()
                                  .WithProjectId(Guid.NewGuid())
                                  .UseProductionApi
                                  .WaitForLoadingNewContent
                                  .Build();

            Assert.True(deliveryOptions.WaitForLoadingNewContent);
        }
コード例 #15
0
        public void BuildWithProjectIdAndPreviewApi()
        {
            var deliveryOptions = DeliveryOptionsBuilder
                                  .CreateInstance()
                                  .WithProjectId(_guid)
                                  .UsePreviewApi(PreviewApiKey)
                                  .Build();

            Assert.Equal(ProjectId, deliveryOptions.ProjectId);
            Assert.True(deliveryOptions.UsePreviewApi);
            Assert.Equal(PreviewApiKey, deliveryOptions.PreviewApiKey);
        }
コード例 #16
0
        public void BuildWithProjectIdAndUseProductionApi()
        {
            var deliveryOptions = DeliveryOptionsBuilder
                                  .CreateInstance()
                                  .WithProjectId(ProjectId)
                                  .UseProductionApi
                                  .Build();

            Assert.Equal(deliveryOptions.ProjectId, ProjectId);
            Assert.False(deliveryOptions.UsePreviewApi);
            Assert.False(deliveryOptions.UseSecuredProductionApi);
        }
コード例 #17
0
        public void BuildWithProjectIdAndSecuredProductionApi()
        {
            var deliveryOptions = DeliveryOptionsBuilder
                                  .CreateInstance()
                                  .WithProjectId(ProjectId)
                                  .UseSecuredProductionApi(SecuredApiKey)
                                  .Build();

            Assert.Equal(ProjectId, deliveryOptions.ProjectId);
            Assert.True(deliveryOptions.UseSecuredProductionApi);
            Assert.Equal(SecuredApiKey, deliveryOptions.SecuredProductionApiKey);
        }
        public void BuildWithRetryPolicyOptions()
        {
            var retryOptions = new DefaultRetryPolicyOptions();

            var deliveryOptions = DeliveryOptionsBuilder
                                  .CreateInstance()
                                  .WithProjectId(ProjectId)
                                  .UseProductionApi()
                                  .WithDefaultRetryPolicyOptions(retryOptions)
                                  .Build();

            Assert.Equal(deliveryOptions.DefaultRetryPolicyOptions, retryOptions);
        }
コード例 #19
0
        public void BuildWithCustomEndpointForProductionApi()
        {
            const string customEndpoint = "https://www.customProductionEndpoint.com";

            var deliveryOptions = DeliveryOptionsBuilder
                                  .CreateInstance()
                                  .WithProjectId(ProjectId)
                                  .UseProductionApi
                                  .WithCustomEndpoint(customEndpoint)
                                  .Build();

            Assert.Equal(deliveryOptions.ProductionEndpoint, customEndpoint);
        }
コード例 #20
0
        public void BuildWithZeroMaxRetryAttemps_ResilienceLogicIsDisabled()
        {
            const int maxRetryAttempts = 0;

            var deliveryOptions = DeliveryOptionsBuilder
                                  .CreateInstance()
                                  .WithProjectId(ProjectId)
                                  .UseProductionApi
                                  .WithMaxRetryAttempts(maxRetryAttempts)
                                  .Build();

            Assert.False(deliveryOptions.EnableResilienceLogic);
        }
コード例 #21
0
        public void BuildWithMaxRetryAttempts()
        {
            const int maxRetryAttempts = 10;

            var deliveryOptions = DeliveryOptionsBuilder
                                  .CreateInstance()
                                  .WithProjectId(ProjectId)
                                  .UseProductionApi
                                  .WithMaxRetryAttempts(maxRetryAttempts)
                                  .Build();

            Assert.Equal(deliveryOptions.MaxRetryAttempts, maxRetryAttempts);
        }
コード例 #22
0
        public void BuildWithCustomEndpointAsUriForProductionApi()
        {
            const string customEndpoint = "https://www.customproductionendpoint.com/";
            var          uri            = new Uri(customEndpoint, UriKind.Absolute);

            var deliveryOptions = DeliveryOptionsBuilder
                                  .CreateInstance()
                                  .WithProjectId(ProjectId)
                                  .UseProductionApi
                                  .WithCustomEndpoint(uri)
                                  .Build();

            Assert.Equal(deliveryOptions.ProductionEndpoint, customEndpoint);
        }
コード例 #23
0
        /// <summary>
        /// Registers a delegate that will be used to configure a named <see cref="IDeliveryClient"/> via <see cref="IDeliveryClientFactory"/>
        /// </summary>
        ///<param name="name">The name of the client configuration</param>
        /// <param name="services">A <see cref="ServiceCollection"/> instance for registering and resolving dependencies.</param>
        /// <param name="buildDeliveryOptions">A function that is provided with an instance of <see cref="DeliveryOptionsBuilder"/>and expected to return a valid instance of <see cref="DeliveryOptions"/>.</param>
        /// <returns>The <paramref name="services"/> instance with <see cref="IDeliveryClient"/> registered in it</returns>
        public static IServiceCollection AddDeliveryClient(this IServiceCollection services, string name, Func <IDeliveryOptionsBuilder, DeliveryOptions> buildDeliveryOptions)
        {
            if (buildDeliveryOptions == null)
            {
                throw new ArgumentNullException(nameof(buildDeliveryOptions), "The function for creating Delivery options is null.");
            }

            services.AddTransient <IConfigureOptions <DeliveryClientFactoryOptions> >(s =>
            {
                return(new ConfigureNamedOptions <DeliveryClientFactoryOptions>(name, options =>
                {
                    options.DeliveryClientsOptions.Add(() =>
                    {
                        var builder = DeliveryOptionsBuilder.CreateInstance();
                        return buildDeliveryOptions(builder);
                    });
                }));
            });

            return(services
                   .Configure <DeliveryClientFactoryOptions>(_ => { })
                   .RegisterDependencies());
        }
コード例 #24
0
        /// <summary>
        /// Builds the <see cref="DeliveryOptions"/> instance from the delegate.
        /// </summary>
        /// <param name="buildDeliveryOptions">A delegate which returns a <see cref="DeliveryOptions"/> instance.</param>
        /// <returns></returns>
        public static DeliveryOptions Build(Func <IDeliveryOptionsBuilder, DeliveryOptions> buildDeliveryOptions)
        {
            var builder = DeliveryOptionsBuilder.CreateInstance();

            return(buildDeliveryOptions(builder));
        }
コード例 #25
0
        public void ValidateOptionsBuiltWithBuilderWithEmptyProjectId()
        {
            var deliveryOptionsSteps = DeliveryOptionsBuilder.CreateInstance();

            Assert.Throws <ArgumentException>(() => deliveryOptionsSteps.WithProjectId(Guid.Empty));
        }