Пример #1
0
        public async Task DeveObterContextoHttpAsync()
        {
            var httpClientMock = new HttpClient();

            httpClientMock.BaseAddress = new Uri(AppSettings.RecursoExterno.UrlBase);

            var contextoHttp = new ContextoHttp(httpClientMock, AppSettings.RecursoExterno.Filmes);
            var contexto     = await contextoHttp.ObterContextoAsync();

            contexto.Should().NotBeNull().And.BeEquivalentTo(httpClientMock);
        }
        public ServicoUsuarioTeste()
        {
            repositorioUsuario          = new Mock <IRepositorioUsuario>();
            servicoEol                  = new Mock <IServicoEOL>();
            repositorioPrioridadePerfil = new Mock <IRepositorioPrioridadePerfil>();
            unitOfWork                  = new Mock <IUnitOfWork>();
            repositorioCache            = new Mock <IRepositorioCache>();
            var obj = new HttpContextAccessor();

            obj.HttpContext         = new DefaultHttpContext();
            repositorioAtribuicaoCj = new Mock <IRepositorioAtribuicaoCJ>();

            var context = new ContextoHttp(obj);

            servicoUsuario = new ServicoUsuario(repositorioUsuario.Object, servicoEol.Object, repositorioPrioridadePerfil.Object, unitOfWork.Object, context, repositorioCache.Object, repositorioAtribuicaoCj.Object);
        }
Пример #3
0
        public static IServiceCollection AddContextoHttp(this IServiceCollection services, [NotNull] string nomeCliente,
                                                         [NotNull] string urlRecursoApi)
        {
            if (nomeCliente == null)
            {
                throw new ArgumentNullException(nameof(nomeCliente));
            }

            if (urlRecursoApi == null)
            {
                throw new ArgumentNullException(nameof(urlRecursoApi));
            }

            services.AddSingleton(typeof(IHttpContexto), i =>
            {
                var httpClientFactory = i.GetRequiredService <IHttpClientFactory>();

                var instance = new ContextoHttp(httpClientFactory.CreateClient(nomeCliente), urlRecursoApi);
                return(instance);
            });

            return(services);
        }