Ejemplo n.º 1
0
        public async Task GetServerSettingsAsync_WithInvalidHttpResponse_ShouldReturnNullResponse()
        {
            // Setup
            var config = new PlexMediaServerConfig
            {
                PlexAuthenticationRequestUser = new BasicAuth
                {
                    Username = "******",
                    Password = "******"
                },
                ServerAddress         = "http://192.168.0.5:32400",
                PlexAuthenticatedUser = new User
                {
                    AuthToken = "Test token"
                }
            };
            var         httpService = Substitute.For <IHttpService>();
            var         plexBasicHeadersConstructor = Substitute.For <IHeaderConstructor <PlexBasicRequestHeaders> >();
            var         instance                    = new PlexServerPreferencesProviderService(httpService, plexBasicHeadersConstructor, config);
            string      endpointUrl                 = Endpoint.ServerPreferences.Description(config.ServerAddress);
            var         httpRequestMessage          = new HttpRequestMessage(HttpMethod.Get, endpointUrl);
            HttpRequest httpRequest                 = httpRequestMessage.ToHttpRequest();
            var         expectedHttpResponse        = new HttpResponse <BasePlexResponse <ServerPreferences> >();
            var         expectedHttpResponseMessage = new HttpResponseMessage
            {
                Content = new StringContent(JsonConvert.SerializeObject(new object()))
            };

            // Mocks
            httpService
            .RequestAsync <BasePlexResponse <ServerPreferences> >(Arg.Any <HttpRequest>(), Arg.Any <CancellationToken>())
            .Returns((request) =>
            {
                // Assert the details of the request to be correct
                var requestContext = request.Args()[0] as HttpRequest;

                Assert.Equal(httpRequestMessage.RequestUri.AbsoluteUri, requestContext?.Request.RequestUri.AbsoluteUri);
                Assert.Equal(httpRequestMessage.Method, requestContext?.Request.Method);

                return(expectedHttpResponse);
            });

            await expectedHttpResponse.SetResponseAsync(httpRequest.Identifier, expectedHttpResponseMessage, CancellationToken.None);

            // Perform
            ServerPreferences actual = await instance.GetServerSettingsAsync(CancellationToken.None);

            // Assert
            httpService
            .Received()
            .RequestAsync <BasePlexResponse <ServerPreferences> >(Arg.Any <HttpRequest>(), CancellationToken.None);

            Assert.Null(actual);
        }
Ejemplo n.º 2
0
        public void Constructor_WithInvalidConfig_ShouldThrowArgumentNullException()
        {
            // Setup
            PlexMediaServerConfig config = null;
            var httpService = Substitute.For <IHttpService>();
            var plexBasicHeadersConstructor = Substitute.For <IHeaderConstructor <PlexBasicRequestHeaders> >();

            // Perform action 'Constructor'
            var exception = Assert.Throws <ArgumentNullException>(() =>
            {
                var instance = new PlexServerPreferencesProviderService(httpService, plexBasicHeadersConstructor, config);
            });

            // Assert that 'ShouldThrowArgumentNullException' = 'WithInvalidConfig'
            Assert.Equal("configuration", exception.ParamName);
        }
Ejemplo n.º 3
0
        public void Constructor_WithValidParams_ShouldConstruct()
        {
            // Setup
            var config = new PlexMediaServerConfig
            {
                PlexAuthenticationRequestUser = new BasicAuth
                {
                    Username = "******",
                    Password = "******"
                },
                ServerAddress = "http://192.168.0.5:32400"
            };
            var httpService = Substitute.For <IHttpService>();
            var plexBasicHeadersConstructor = Substitute.For <IHeaderConstructor <PlexBasicRequestHeaders> >();

            // Perform action 'Constructor'
            var instance = new PlexServerPreferencesProviderService(httpService, plexBasicHeadersConstructor, config);

            // Assert that 'ShouldThrowArgumentNullException' = 'WithInvalidConfig'
            Assert.NotNull(instance);
        }