<commit_before>// Copyright (c) 2014-2020 <NAME>, All Rights Reserved.
// The Apache v2. See License.txt in the project root for license information.

using System;
using System.Reflection;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Moq;
using Wangkanai.Detection.Models;
using Wangkanai.Detection.Services;
using Xunit;

namespace Wangkanai.Detection.Hosting
{
    public class ResponsiveCollectionExtensionsTests
    {
        private readonly int total = 17;

        [Fact]
        public void AddResponsive_Services()
        {
            var service = new ServiceCollection();
            var expected = service.Count + total;
            var builder = service.AddDetection();

            //Assert.Equal(expected, builder.Services.Count);
            Assert.Same(service, builder.Services);
        }

        [Fact]
        public void AddResponsive_Null_ArgumentNullException()
        {
            Assert.Throws<ArgumentNullException>(CreateResponsiveNullService);
        }

        [Fact]
        public void AddResponsive_Options_Builder_Service()
        {
            var service = new ServiceCollection();
            var expected = service.Count + total;
            var builder = service.AddDetection(options =>
                                               {
                                                   options.Responsive.DefaultTablet = Device.Desktop;
                                               });

            //Assert.Equal(expected, builder.Services.Count);
            Assert.Same(service, builder.Services);
        }

        [Fact]
        public void AddResponsive_Options_Null_ArgumentNullException()
        {
            Assert.Throws<ArgumentNullException>(CreateResponsiveNullService);
        }
        
        private readonly Func<object> CreateResponsiveNullService =
            () => ((IServiceCollection)null).AddDetection();
        
        [Fact]
        public void AddResponsive_Options_Disable_True()
        {
            var services  = new ServiceCollection();
            services.AddLogging();
            services.AddDetection(options => options.Responsive.Disable = true);
            
            var provider = services.BuildServiceProvider();

            var app = new ApplicationBuilder(provider);
            
            app.UseDetection();
            
            var service = MockService.CreateService("mobile");
            var request = app.Build();
            request.Invoke(service.Context);
        }
        
        [Fact]
        public void AddResponsive_Options_Disable_False()
        {
            var services = new ServiceCollection();
            services.AddHttpContextAccessor();
            services.AddLogging();
            services.AddDetection();
            
            var provider = services.BuildServiceProvider();
            var mock = new Mock<IServiceProvider>();

            var app = new ApplicationBuilder(provider);
            
            app.UseDetection();

            var service = MockService.CreateService("mobile");
            var request = app.Build();
            request.Invoke(service.Context);
        }
        
        [Fact]
        public void AddResponsive_Options_Disable_False_Failed()
        {
            var services = new ServiceCollection();
            services.AddHttpContextAccessor();
            services.AddLogging();
            services.AddDetection();
            
            var provider = services.BuildServiceProvider();

            var app = new ApplicationBuilder(provider);
            
            app.UseDetection();

            var service = MockService.CreateService("mobile");
            var request = app.Build();
            request.Invoke(service.Context);
        }
    }
}<commit_msg>Responsive Disable Options<commit_after>// Copyright (c) 2014-2020 <NAME>, All Rights Reserved.
// The Apache v2. See License.txt in the project root for license information.

using System;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Moq;
using Wangkanai.Detection.DependencyInjection.Options;
using Wangkanai.Detection.Models;
using Wangkanai.Detection.Services;
using Xunit;

namespace Wangkanai.Detection.Hosting
{
    public class ResponsiveCollectionExtensionsTests
    {
        private readonly int total = 17;

        [Fact]
        public void AddResponsive_Services()
        {
            var service  = new ServiceCollection();
            var expected = service.Count + total;
            var builder  = service.AddDetection();

            //Assert.Equal(expected, builder.Services.Count);
            Assert.Same(service, builder.Services);
        }

        [Fact]
        public void AddResponsive_Null_ArgumentNullException()
        {
            Assert.Throws<ArgumentNullException>(CreateResponsiveNullService);
        }

        [Fact]
        public void AddResponsive_Options_Builder_Service()
        {
            var service  = new ServiceCollection();
            var expected = service.Count + total;
            var builder  = service.AddDetection(options => { options.Responsive.DefaultTablet = Device.Desktop; });

            //Assert.Equal(expected, builder.Services.Count);
            Assert.Same(service, builder.Services);
        }

        [Fact]
        public void AddResponsive_Options_Null_ArgumentNullException()
        {
            Assert.Throws<ArgumentNullException>(CreateResponsiveNullService);
        }

        private readonly Func<object> CreateResponsiveNullService =
            () => ((IServiceCollection) null).AddDetection();

        [Fact]
        public void AddResponsive_Options_Disable_True()
        {
            var service    = MockService.CreateService("mobile");
            var options    = new DetectionOptions {Responsive = {Disable = true}};
            var device     = new DeviceService(service);
            var preference = new PreferenceService();
            var resolver   = new ResponsiveService(device, preference, options);

            var serviceProvider = new Mock<IServiceProvider>();
            serviceProvider
                .Setup(s => s.GetService(typeof(ILoggerFactory)))
                .Returns(Mock.Of<NullLoggerFactory>());
            serviceProvider
                .Setup(s => s.GetService(typeof(DetectionOptions)))
                .Returns(options);
            serviceProvider
                .Setup(s => s.GetService(typeof(IResponsiveService)))
                .Returns(resolver);
            serviceProvider
                .Setup(s => s.GetService(typeof(MarkerService)))
                .Returns(new MarkerService());

            var app = new ApplicationBuilder(serviceProvider.Object);

            app.UseDetection();

            var request = app.Build();
            request.Invoke(service.Context);
        }

        [Fact]
        public void AddResponsive_Options_Disable_False()
        {
            var service    = MockService.CreateService("mobile");
            var options    = new DetectionOptions {Responsive = {Disable = false}};
            var device     = new DeviceService(service);
            var preference = new PreferenceService();
            var resolver   = new ResponsiveService(device, preference, options);

            var serviceProvider = new Mock<IServiceProvider>();
            serviceProvider
                .Setup(s => s.GetService(typeof(ILoggerFactory)))
                .Returns(Mock.Of<NullLoggerFactory>());
            serviceProvider
                .Setup(s => s.GetService(typeof(DetectionOptions)))
                .Returns(options);
            serviceProvider
                .Setup(s => s.GetService(typeof(IResponsiveService)))
                .Returns(resolver);
            serviceProvider
                .Setup(s => s.GetService(typeof(MarkerService)))
                .Returns(new MarkerService());

            var app = new ApplicationBuilder(serviceProvider.Object);

            app.UseDetection();

            var request = app.Build();
            request.Invoke(service.Context);
        }
    }
}
{'fraction_non_alphanumeric': 0.08926841085271318, 'fraction_numerical': 0.0026647286821705426, 'mean_word_length': 1.9970961887477314, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2495278', 'n_tokens_mistral': 1986, 'n_tokens_neox': 1920, 'n_words': 410}