/// <summary>
 /// Overloaded constructor to pass configuration.
 /// </summary>
 /// <param name="configuration">Media server specific configuration.</param>
 /// <param name="httpService">Instance of static http service to use in making web requests.</param>
 /// <param name="authenticator">Instance of static http service to use in making web requests.</param>
 /// <param name="serverSettingsProvider">Instance of Plex server settings provider.</param>
 /// <param name="mediaProvider">Instance of Plex server media provider.</param>
 public PlexMediaService(PlexMediaServerConfig configuration,
                         IHttpService httpService,
                         IPlexAuthenticator authenticator,
                         IPlexServerSettingsProvider serverSettingsProvider,
                         IPlexMediaProvider mediaProvider)
 {
     Configuration = configuration
                     .ThrowIfNull(nameof(configuration))
                     .ThrowIfInvalid(nameof(configuration));
     _httpService = httpService
                    .ThrowIfNull(nameof(httpService));
     _authenticator = authenticator
                      .ThrowIfNull(nameof(authenticator));
     _serverSettingsProvider = serverSettingsProvider
                               .ThrowIfNull(nameof(serverSettingsProvider));
     _mediaProvider = mediaProvider
                      .ThrowIfNull(nameof(mediaProvider));
 }
Пример #2
0
 /// <summary>
 /// Overloaded constructor to pass configuration.
 /// </summary>
 /// <param name="configuration">Media server specific configuration.</param>
 /// <param name="httpService">Instance of static http service to use in making web requests.</param>
 /// <param name="authenticator">Instance of static http service to use in making web requests.</param>
 /// <param name="serverSettingsProvider">Instance of Plex server settings provider.</param>
 /// <param name="mediaProvider">Instance of Plex server media provider.</param>
 public PlexMediaService(PlexMediaServerConfig configuration,
                         IHttpService httpService,
                         IPlexAuthenticator authenticator,
                         IPlexServerSettingsProvider serverSettingsProvider,
                         IHeaderConstructor <PlexBasicRequestHeaders> plexBasicHeadersConstructor)
 {
     Configuration = configuration
                     .ThrowIfNull(nameof(configuration))
                     .ThrowIfInvalid(nameof(configuration));
     _httpService = httpService
                    .ThrowIfNull(nameof(httpService));
     _authenticator = authenticator
                      .ThrowIfNull(nameof(authenticator));
     _serverSettingsProvider = serverSettingsProvider
                               .ThrowIfNull(nameof(serverSettingsProvider));
     _plexBasicHeaders = plexBasicHeadersConstructor
                         .ThrowIfNull(nameof(plexBasicHeadersConstructor))
                         .ConstructRequestHeaders(configuration.BasicPlexHeaders);
 }
Пример #3
0
        public void Constructor_WithInvalidAuthenticator_ShouldThrowArgumentNullException()
        {
            // Setup
            PlexMediaServerConfig config = new PlexMediaServerConfig
            {
                ServerAddress = "http://192.168.0.5:32400",
                PlexAuthenticationRequestUser = new BasicAuth
                {
                    Username = "******",
                    Password = "******"
                }
            };
            var httpService = Substitute.For <IHttpService>();
            IPlexAuthenticator authenticator = null;
            var settingsProvider             = Substitute.For <IPlexServerSettingsProvider>();
            var mediaProvider = Substitute.For <IPlexMediaProvider>();

            // Perform
            var exception = Assert.Throws <ArgumentNullException>(() =>
                                                                  new PlexMediaService(config, httpService, authenticator, settingsProvider, mediaProvider));

            // Assert
            Assert.Equal("authenticator", exception.ParamName);
        }