コード例 #1
0
        public async Task TestHttpExtensionsDefaultReadWrite()
        {
            var iniFileConfig = IniFileConfigBuilder.Create()
                                .WithApplicationName("Dapplo")
                                .WithFilename("dapplo.httpextensions")
                                .WithoutSaveOnExit()
                                .BuildApplicationConfig();

            // Important to disable the auto-save, otherwise we get test issues
            var iniConfig = new IniConfig(iniFileConfig);

            using (var testMemoryStream = new MemoryStream())
            {
                await IniConfig.Current.ReadFromStreamAsync(testMemoryStream).ConfigureAwait(false);
            }
            var httpConfiguration = await iniConfig.RegisterAndGetAsync <IHttpConfiguration>();

            Assert.NotNull(httpConfiguration);
            using (var writeStream = new MemoryStream())
            {
                await iniConfig.WriteToStreamAsync(writeStream).ConfigureAwait(false);

                writeStream.Seek(0, SeekOrigin.Begin);
                await iniConfig.ReadFromStreamAsync(writeStream).ConfigureAwait(false);

                var behaviour = new HttpBehaviour
                {
                    HttpSettings = httpConfiguration
                };
                behaviour.MakeCurrent();
                HttpClientFactory.Create();
            }
        }