Esempio n. 1
0
        public void ShouldBuildEvenWhenThereIsNoOptionsSet()
        {
            var simpleHttpFactory = new SimpleHttpFactory();

            simpleHttpFactory.AddClientFactory("test", _ => {});
            var client = simpleHttpFactory.GetClient("test");

            Assert.NotNull(client);
        }
Esempio n. 2
0
        public async Task ShouldBuildAHttpClientWithMessageHandlerIfAny()
        {
            var simpleHttpFactory = new SimpleHttpFactory();

            simpleHttpFactory.AddClientFactory(
                "test",
                opt => opt.MessageHandler = new TestMessageHandler()
                );
            var client = simpleHttpFactory.GetClient("test");

            var exception = await Assert.ThrowsAsync <NotImplementedException>(() => client.GetAsync("http://0.0.0.0"));

            Assert.Equal("yeah it is right", exception.Message);
        }
        public static ConfigurationExpression ConfigureSimpleHttpFactory(
            this ConfigurationExpression c
            , Action <SimpleHttpFactory> configure
            )
        {
            var httpFac = new SimpleHttpFactory();

            configure?.Invoke(httpFac);

            c.ForSingletonOf <ISimpleHttpFactory>()
            .Use(httpFac);

            return(c);
        }
Esempio n. 4
0
        RegisterSimpleHttpFactory(
            this ContainerBuilder cb
            , Action <SimpleHttpFactory> configure
            )
        {
            return(cb.Register(ctx =>
            {
                var factory = new SimpleHttpFactory();

                configure(factory);

                return factory;
            })
                   .As <ISimpleHttpFactory>()
                   .SingleInstance());
        }
Esempio n. 5
0
        public void SimpleUsageTest()
        {
            var simpleHttpFactory = new SimpleHttpFactory();
            var baseAddress       = new Uri("http://0.0.0.0:9090");
            var timeout           = TimeSpan.FromMinutes(5);

            simpleHttpFactory.AddClientFactory(
                "test",
                opt => opt.ClientConfiguration = c =>
            {
                c.BaseAddress = baseAddress;
                c.Timeout     = timeout;
            }
                );
            var client = simpleHttpFactory.GetClient("test");

            Assert.Same(baseAddress, client.BaseAddress);
            Assert.Equal(timeout, client.Timeout);
        }