Beispiel #1
0
 public void ResetDefaults_ResetsFlurlConfiguration()
 {
     OpenStackNet.Configure();
     Assert.NotNull(FlurlHttp.Configuration.BeforeCall);
     OpenStackNet.ResetDefaults();
     Assert.Null(FlurlHttp.Configuration.BeforeCall);
 }
Beispiel #2
0
 public void ResetDefaults_ResetsJsonNetConfiguration()
 {
     OpenStackNet.Configure();
     Assert.IsType <OpenStackContractResolver>(JsonSerializer.CreateDefault().ContractResolver);
     OpenStackNet.ResetDefaults();
     Assert.IsType <DefaultContractResolver>(JsonSerializer.CreateDefault().ContractResolver);
 }
Beispiel #3
0
        public async void UserAgentTest()
        {
            using (var httpTest = new HttpTest())
            {
                OpenStackNet.Configure();

                await "http://api.com".GetAsync();

                var userAgent = httpTest.CallLog[0].Request.Headers.UserAgent.ToString();
                Assert.Contains("openstack.net", userAgent);
            }
        }
Beispiel #4
0
        public async void UserAgentWithApplicationSuffixTest()
        {
            using (var httpTest = new HttpTest())
            {
                OpenStackNet.Configure(configure: options => options.UserAgents.Add(new ProductInfoHeaderValue("(unittests)")));

                await "http://api.com".GetAsync();

                var userAgent = httpTest.CallLog[0].Request.Headers.UserAgent.ToString();
                Assert.Contains("openstack.net", userAgent);
                Assert.Contains("unittests", userAgent);
            }
        }
Beispiel #5
0
        public async void UserAgentOnlyListOnceTest()
        {
            using (var httpTest = new HttpTest())
            {
                OpenStackNet.Configure();
                OpenStackNet.Configure(); // Duplicate call to Configure should be ignored

                await "http://api.com".GetAsync();

                var userAgent = httpTest.CallLog[0].Request.Headers.UserAgent.ToString();
                Assert.Contains("openstack.net", userAgent);
            }
        }
        public void WhenConfigureIsCalled_GlobalJsonConfiguration_IsNotAltered()
        {
            // User makes their own tweaks to the serialization
            JsonConvert.DefaultSettings = () => new JsonSerializerSettings();

            // We configure openstack.net
            OpenStackNet.Configure();

            // We shouldn't have clobbered their settings
            var serializer = JsonSerializer.CreateDefault();

            Assert.IsNotType <OpenStackContractResolver>(serializer.ContractResolver);
        }
Beispiel #7
0
        public static Mock <IAuthenticationProvider> CreateAuthenticationProvider()
        {
            var stub = new Mock <IAuthenticationProvider>();

            OpenStackNet.Configure();

            stub.Setup(provider => provider.GetToken(It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult("mock-token"));

            stub.Setup(provider => provider.GetEndpoint(It.IsAny <IServiceType>(), It.IsAny <string>(), It.IsAny <bool>(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult("http://example.com/api"));

            return(stub);
        }
        public void WhenConfigureIsCalled_GlobalFlurlConfiguration_IsNotAltered()
        {
            // User makes their own tweaks to Flurl
            Action <HttpCall> customErrorHandler = call => Debug.WriteLine("I saw an error!");

            FlurlHttp.GlobalSettings.OnError = customErrorHandler;

            // We configure openstack.net
            OpenStackNet.Configure();

            // We shouldn't have clobbered their settings
            Assert.Null(FlurlHttp.GlobalSettings.AfterCall);
            Assert.Null(FlurlHttp.GlobalSettings.AfterCallAsync);
            Assert.Null(FlurlHttp.GlobalSettings.BeforeCall);
            Assert.Null(FlurlHttp.GlobalSettings.BeforeCallAsync);
            Assert.Equal(customErrorHandler, FlurlHttp.GlobalSettings.OnError);
        }