Exemplo n.º 1
0
        public async Task SearchAsync_Null_ShouldThrowArgumentNullException(string emptyString)
        {
            //Arrange
            IClient client = _clientMock.Object;
            IApiKeyConfiguration apiKeyConfiguration = _apiKeyConfigurationMock.Object;
            MovieRepo            repo = new MovieRepo(client, apiKeyConfiguration);

            //Act
            Func <Task> action = async() => await repo.SearchAsync(emptyString);

            //Assert
            await Assert.ThrowsAsync <ArgumentException>(action);
        }
Exemplo n.º 2
0
        public async Task SearchAsync_ValidSearch_ShouldReturnListOfMovies(string query)
        {
            //Arrange
            IClient client = _clientMock.Object;
            IApiKeyConfiguration apiKeyConfiguration = _apiKeyConfigurationMock.Object;
            MovieRepo            repo = new MovieRepo(client, apiKeyConfiguration);

            //Act
            var result = await repo.SearchAsync(query);

            //Assert
            Assert.NotNull(result);
        }
        public MovieRepo(IClient client, IApiKeyConfiguration apiKeyConfiguration)
        {
            if (apiKeyConfiguration == null)
            {
                throw new ArgumentNullException(nameof(apiKeyConfiguration));
            }

            Client         = client ?? throw new ArgumentNullException(nameof(client));
            Client.BaseUrl = new Uri("http://www.omdbapi.com/");

            _apiKey = apiKeyConfiguration.ApiKeys?
                      .Where(kv => kv.Key == OmdbApiKeyConfigurationName)
                      .Select(kv => kv.Value)
                      .First();
        }