Ejemplo n.º 1
0
        public virtual void TestInitialize()
        {
            this.HttpClientWrapperMock = new Mock <IHttpClientWrapper>(MockBehavior.Strict);

            var services = new ServiceCollection();

            services
            .AddFluentSpotifyClientForUnitTesting(
                this.HttpClientWrapperMock,
                pipeline => pipeline
                .AddAspNetCoreAuthorizationCodeFlow());

            this.AuthorizationFlowsHttpClientMock = new Mock <IAuthorizationFlowsHttpClient>(MockBehavior.Strict);
            services.Replace(ServiceDescriptor.Singleton(this.AuthorizationFlowsHttpClientMock.Object));

            this.AuthenticationManager = new AuthenticationManagerStub();
            services.Replace(ServiceDescriptor.Singleton <IAuthenticationManager>(this.AuthenticationManager));

            this.SystemClockMock = new Mock <ISystemClock>(MockBehavior.Strict);
            services.RegisterSingleton(this.SystemClockMock.Object);

            this.SpotifyOptionsMonitorMock = new Mock <IOptionsMonitor <SpotifyOptions> >(MockBehavior.Strict);
            this.SpotifyOptionsMonitorMock.Setup(x => x.CurrentValue).Returns(new SpotifyOptions {
                ClientId = ClientId, ClientSecret = ClientSecret, TokenEndpoint = this.tokenEndpoint
            });
            services.RegisterSingleton(this.SpotifyOptionsMonitorMock.Object);

            services.Replace(ServiceDescriptor.Singleton <ISemaphoreProvider>(new SempahoreProviderStub()));

            this.serviceProvider = services.BuildServiceProvider();

            this.FluentSpotifyClientOptions = this.serviceProvider.GetRequiredService <Microsoft.Extensions.Options.IOptionsMonitor <FluentSpotifyClientOptions> >().CurrentValue;

            this.Client = this.serviceProvider.GetRequiredService <IFluentSpotifyClient>();
        }
Ejemplo n.º 2
0
        public virtual void TestInitialize()
        {
            this.HttpClientWrapperMock = new Mock <IHttpClientWrapper>(MockBehavior.Strict);

            var services = new ServiceCollection();

            services
            .AddFluentSpotifyClientForUnitTesting(
                this.HttpClientWrapperMock,
                pipeline => pipeline
                .AddClientCredentialsFlow(o =>
            {
                o.ClientId     = "TestClientId";
                o.ClientSecret = "TestClientSecret";
            }));

            this.AuthorizationFlowsHttpClientMock = new Mock <IAuthorizationFlowsHttpClient>(MockBehavior.Strict);
            services.Replace(ServiceDescriptor.Singleton(this.AuthorizationFlowsHttpClientMock.Object));

            this.DateTimeOffsetProviderMock = new Mock <IDateTimeOffsetProvider>(MockBehavior.Strict);
            services.Replace(ServiceDescriptor.Singleton(this.DateTimeOffsetProviderMock.Object));

            this.serviceProvider = services.BuildServiceProvider();

            this.Options = this.serviceProvider.GetRequiredService <IOptionsProvider <ITokenClientOptions> >().Get();

            this.Client = this.serviceProvider.GetRequiredService <IFluentSpotifyClient>();
        }
Ejemplo n.º 3
0
        public MainViewModel(IAuthenticationManager authenticationManager, IFluentSpotifyClient fluentSpotifyClient)
        {
            this.fluentSpotifyClient = fluentSpotifyClient;

            this.CancelableActionViewModel = new CancelableActionViewModel();
            this.CancelableActionViewModel.PropertyChanged += this.CancelableActionViewModel_PropertyChanged;

            this.LoginViewModel = new LoginViewModel(authenticationManager, this.CancelableActionViewModel);
            this.LoginViewModel.PropertyChanged += this.LoginViewModel_PropertyChanged;
        }
Ejemplo n.º 4
0
 public SpotifyService(IFluentSpotifyClient fluentSpotifyClient,
                       ILogger <SpotifyService> logger,
                       IMapper mapper,
                       IMemoryCache memoryCache)
 {
     _fluentSpotifyClient = fluentSpotifyClient;
     _logger      = logger;
     _mapper      = mapper;
     _memoryCache = memoryCache;
 }
Ejemplo n.º 5
0
        public virtual void TestInitialize()
        {
            var services = new ServiceCollection();

            services.AddFluentSpotifyClientForUnitTesting();

            this.SpotifyHttpClientMock = new Mock <ISpotifyHttpClient>();
            services.Replace(ServiceDescriptor.Singleton(this.SpotifyHttpClientMock.Object));

            this.serviceProvider = services.BuildServiceProvider();

            this.Client = this.serviceProvider.GetRequiredService <IFluentSpotifyClient>();
        }
Ejemplo n.º 6
0
        public virtual void TestInitialize()
        {
            var services = new ServiceCollection();

            services.AddSingleton <ICurrentUserProvider, CurrentUserProviderStub>();

            this.MockHttp = new MockHttpMessageHandler();

            services.AddFluentSpotifyClient().ConfigureHttpClientBuilder(b => b.ConfigurePrimaryHttpMessageHandler(() => this.MockHttp));

            this.serviceProvider = services.BuildServiceProvider();

            this.Client = this.serviceProvider.GetRequiredService <IFluentSpotifyClient>();
        }
Ejemplo n.º 7
0
        public static void AssemblyInit(TestContext context)
        {
            // Build configuration
            var builder = new ConfigurationBuilder()
                          .AddJsonFile("secrets.json", optional: true, reloadOnChange: true);

            var config = builder.Build();

            // Setup policies
            var serviceUnavailablePolicy = Policy
                                           .Handle <SpotifyHttpResponseWithErrorCodeException>(x => x.IsRecoverable())
                                           .Or <SpotifyHttpRequestException>(x => x.InnerException is HttpRequestException)
                                           .WaitAndRetryAsync(3, i => TimeSpan.FromSeconds(5));

            var tooManyRequestsPolicy = Policy.Handle <SpotifyHttpResponseWithErrorCodeException>(e => (int)e.ErrorCode == 429 && e.Headers.RetryAfter.GetValueOrDefault() > TimeSpan.Zero)
                                        .WaitAndRetryAsync(
                retryCount: 3,
                sleepDurationProvider: (retryAttempt, retryContext) =>
            {
                if (retryContext == null || !retryContext.TryGetValue("RetryAfter", out object retryAfter))
                {
                    retryAfter = TimeSpan.FromSeconds(1);
                }

                return((TimeSpan)retryAfter);
            },
                onRetry: (exception, timespan, retryAttempt, retryContext) =>
            {
                retryContext["RetryAfter"] = (exception as SpotifyHttpResponseWithErrorCodeException).Headers.RetryAfter;
            });

            var wrapPolicy = Policy.WrapAsync(serviceUnavailablePolicy, tooManyRequestsPolicy);

            // Build services provider
            var services = new ServiceCollection();

            services.Configure <ClientCredentialsFlowOptions>(config.GetSection("ClientCredentialsFlowOptions"));

            services
            .AddFluentSpotifyClient(clientBuilder => clientBuilder
                                    .ConfigurePipeline(pipeline => pipeline
                                                       .AddDelegate((next, cancellationToken) => wrapPolicy.ExecuteAsync(next, cancellationToken))
                                                       .AddClientCredentialsFlow()));

            serviceProvider = services.BuildServiceProvider();

            Client = serviceProvider.GetRequiredService <IFluentSpotifyClient>();
        }
        public static void AssemblyInit(TestContext context)
        {
            // Build configuration
            var config = new ConfigurationBuilder()
                         .AddJsonFile("secrets.json", optional: true, reloadOnChange: true)
                         .Build();

            // Build retry policy
            var retryPolicy = HttpPolicyExtensions
                              .HandleTransientHttpError()
                              .OrResult(x => x.StatusCode == System.Net.HttpStatusCode.TooManyRequests)
                              .WaitAndRetryAsync(
                retryCount: 3,
                sleepDurationProvider: (retryCount, response, context) =>
            {
                var retryAfter = (response?.Result?.Headers?.RetryAfter?.Delta).GetValueOrDefault();
                var min        = TimeSpan.FromSeconds(1);
                return(retryAfter > min ? retryAfter : min);
            },
                onRetryAsync: (response, timespan, retryCount, context) => Task.CompletedTask);

            // Build services provider
            var services = new ServiceCollection();

            services
            .Configure <SpotifyClientCredentialsFlowOptions>(config.GetSection("SpotifyClientCredentialsFlow"));

            services
            .AddFluentSpotifyClient()
            .ConfigureHttpClientBuilder(b => b.AddPolicyHandler(retryPolicy))
            .ConfigureHttpClientBuilder(b => b
                                        .AddSpotifyClientCredentialsFlow()
                                        .ConfigureTokenHttpClientBuilder(b => b.AddPolicyHandler(retryPolicy)));

            serviceProvider = services.BuildServiceProvider();

            Client = serviceProvider.GetRequiredService <IFluentSpotifyClient>();
        }
Ejemplo n.º 9
0
 public Repository(IConfiguration configuration, IFluentSpotifyClient fluentSpotifyClient)
 {
     _configuration       = configuration;
     _fluentSpotifyClient = fluentSpotifyClient;
 }
Ejemplo n.º 10
0
 public virtual void TestInitialize()
 {
     this.Client = AssemblyInitializer.Client;
 }
 public PlaylistTrackService(IFluentSpotifyClient fluentSpotifyClient)
 {
     this.fluentSpotifyClient = fluentSpotifyClient;
 }
Ejemplo n.º 12
0
 public FixProcessor(IFluentSpotifyClient fluentSpotifyClient)
 {
     this.fluentSpotifyClient = fluentSpotifyClient;
 }
Ejemplo n.º 13
0
 public SearchService(IFluentSpotifyClient fluentSpotifyClient)
 {
     this.fluentSpotifyClient = fluentSpotifyClient;
 }
Ejemplo n.º 14
0
 public UnspotifyService(SpotifyUriParser spotifyUriParser, IFluentSpotifyClient fluentSpotifyClient)
 {
     _spotifyUriParser    = spotifyUriParser;
     _fluentSpotifyClient = fluentSpotifyClient;
 }
Ejemplo n.º 15
0
 public HomeController(IFluentSpotifyClient fluentSpotifyClient)
 {
     this.fluentSpotifyClient = fluentSpotifyClient;
 }