Exemplo n.º 1
0
        public async Task New_Busca_Heroi_FailAsync()
        {
            var mockMarvelClient       = Mock_IMarvelApiClient_Teste().Object;
            var mockIMd5Encode         = Mock_IMd5Encode_Teste().Object;
            var mockMarvelConfiguratio = new MarvelApiAdapterConfiguration()
            {
                AppKey           = publicKey,
                PrivateKey       = privateKey,
                TimeStampDefault = timestamp,
                UrlBase          = ""
            };

            var mockLog = new Mock <ILogger <MarvelApiHeroAdapter> >().Object;

            var marvelApiAdapter = new MarvelApiHeroAdapter(mockMarvelClient, mockMarvelConfiguratio, mockIMd5Encode, mockLog);

            var result = await marvelApiAdapter.BuscarHeroiAsync(nomeHeroi_zuado);

            Assert.Equal(0, result.Count);
        }
Exemplo n.º 2
0
        public async Task New_Busca_Heroi_SucessAsync()
        {
            var mockMarvelClient       = Mock_IMarvelApiClient_Teste().Object;
            var mockIMd5Encode         = Mock_IMd5Encode_Teste().Object;
            var mockMarvelConfiguratio = new MarvelApiAdapterConfiguration()
            {
                AppKey           = publicKey,
                PrivateKey       = privateKey,
                TimeStampDefault = timestamp,
                UrlBase          = ""
            };

            var mockLog = new Mock <ILogger <MarvelApiHeroAdapter> >().Object;

            var marvelApiAdapter = new MarvelApiHeroAdapter(mockMarvelClient, mockMarvelConfiguratio, mockIMd5Encode, mockLog);

            var result = await marvelApiAdapter.BuscarHeroiAsync(nomeHeroi);

            Assert.Equal(nomeHeroi, result.First().Nome);
            Assert.Single(result.First().Historias.Items);
        }
Exemplo n.º 3
0
        public static IServiceCollection AddMarvelApiAdapter(this IServiceCollection services, MarvelApiAdapterConfiguration marvelApiAdapterConfiguration)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            services.AddSingleton(marvelApiAdapterConfiguration ?? throw new ArgumentNullException(nameof(marvelApiAdapterConfiguration)));

            services.AddTransient(serviceProvider =>
            {
                var httpClient = new HttpClient()
                {
                    BaseAddress = new Uri(marvelApiAdapterConfiguration.UrlBase)
                };

                return(RestService.For <IMarvelApiClient>(httpClient));
            });

            services.AddSingleton <IMarvelApiAdapter, MarvelApiHeroAdapter>();

            return(services);
        }