Esempio n. 1
0
        public async Task InitializeAsync_WithInvalidAuthResponse_ShouldReturnUnauthorised()
        {
            // Setup
            PlexMediaServerConfig config = new PlexMediaServerConfig
            {
                ServerAddress = "http://192.168.0.5:32400",
                PlexAuthenticationRequestUser = new BasicAuth
                {
                    Username = "******",
                    Password = "******"
                }
            };
            var httpService      = Substitute.For <IHttpService>();
            var authenticator    = Substitute.For <IPlexAuthenticator>();
            var settingsProvider = Substitute.For <IPlexServerSettingsProvider>();
            var mediaProvider    = Substitute.For <IPlexMediaProvider>();
            var instance         = new PlexMediaService(config, httpService, authenticator, settingsProvider, mediaProvider);

            authenticator
            .AuthenticateAsync(Arg.Any <CancellationToken>())
            .Returns(info => new UserAuthenticationResponse());

            // Perform
            InitializationStatus actual = await instance.InitializeAsync((servers) => servers.First().PublicAddress, CancellationToken.None);

            // Assert
            Assert.Equal(InitializationStatus.Unauthorised, actual);
        }
Esempio n. 2
0
        public async Task InitializeAsync_WithSettings_ShouldSetSettings()
        {
            // Setup
            PlexMediaServerConfig config = new PlexMediaServerConfig
            {
                ServerAddress = "http://192.168.0.5:32400",
                PlexAuthenticationRequestUser = new BasicAuth
                {
                    Username = "******",
                    Password = "******"
                }
            };
            var httpService      = Substitute.For <IHttpService>();
            var authenticator    = Substitute.For <IPlexAuthenticator>();
            var settingsProvider = Substitute.For <IPlexServerSettingsProvider>();
            var mediaProvider    = Substitute.For <IPlexMediaProvider>();
            var instance         = new PlexMediaService(config, httpService, authenticator, settingsProvider, mediaProvider);
            var expectedUser     = new User
            {
                Email = "*****@*****.**"
            };

            authenticator
            .GetAllServers(Arg.Any <CancellationToken>())
            .Returns(info => new List <Device>()
            {
                new Device()
            });
            authenticator
            .AuthenticateAsync(Arg.Any <CancellationToken>())
            .Returns(info => new UserAuthenticationResponse
            {
                User = expectedUser
            });
            settingsProvider
            .GetServerSettingsAsync(Arg.Any <CancellationToken>())
            .Returns(info => new ServerPreferences
            {
                Setting = new List <Setting>()
                {
                    new Setting()
                }
            });

            // Perform
            InitializationStatus actual = await instance.InitializeAsync((servers) => servers.First().PublicAddress, CancellationToken.None);

            // Assert
            Assert.True(instance.Configuration.ServerPreferences.Setting.Any());
        }
Esempio n. 3
0
        public async Task InitializeAsync_WithValidServers_ShouldSetDiscoveredServersContext()
        {
            // Setup
            PlexMediaServerConfig config = new PlexMediaServerConfig
            {
                ServerAddress = "http://192.168.0.5:32400",
                PlexAuthenticationRequestUser = new BasicAuth
                {
                    Username = "******",
                    Password = "******"
                }
            };
            var httpService      = Substitute.For <IHttpService>();
            var authenticator    = Substitute.For <IPlexAuthenticator>();
            var settingsProvider = Substitute.For <IPlexServerSettingsProvider>();
            var mediaProvider    = Substitute.For <IPlexMediaProvider>();
            var instance         = new PlexMediaService(config, httpService, authenticator, settingsProvider, mediaProvider);
            var expectedUser     = new User
            {
                Email = "*****@*****.**"
            };
            var expectedDevice = new Device
            {
                Id = "some_server"
            };

            authenticator
            .GetAllServers(Arg.Any <CancellationToken>())
            .Returns(info =>
                     new List <Device>()
            {
                expectedDevice
            });
            authenticator
            .AuthenticateAsync(Arg.Any <CancellationToken>())
            .Returns(info => new UserAuthenticationResponse
            {
                User = expectedUser
            });

            // Perform
            InitializationStatus actual = await instance.InitializeAsync((servers) => servers.First().PublicAddress, CancellationToken.None);

            // Assert
            Assert.NotNull(instance.Configuration?.DiscoveredServers);
            Assert.Equal(expectedDevice.Id, instance.Configuration.DiscoveredServers.First().Id);
        }