public void ResetDefaults_ResetsFlurlConfiguration() { OpenStackNet.Configure(); Assert.NotNull(FlurlHttp.Configuration.BeforeCall); OpenStackNet.ResetDefaults(); Assert.Null(FlurlHttp.Configuration.BeforeCall); }
public void ResetDefaults_ResetsJsonNetConfiguration() { OpenStackNet.Configure(); Assert.IsType <OpenStackContractResolver>(JsonSerializer.CreateDefault().ContractResolver); OpenStackNet.ResetDefaults(); Assert.IsType <DefaultContractResolver>(JsonSerializer.CreateDefault().ContractResolver); }
public void Serialize_WithinAClass() { var thing = new Thing {Id = Guid.NewGuid()}; var result = OpenStackNet.Serialize(thing); Assert.Equal(string.Format("{{\"Id\":\"{0}\"}}", thing.Id), result); }
public void Deserialize() { var id = new Identifier(Guid.NewGuid()); var json = OpenStackNet.Serialize(id); var result = OpenStackNet.Deserialize<Identifier>(json); Assert.Equal(id, result); }
public void Serialize() { var rawId = Guid.NewGuid(); var id = (Identifier)rawId; var result = OpenStackNet.Serialize(id); Assert.Equal(string.Format("\"{0}\"", rawId.ToString("D")), result); }
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); } }
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); } }
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); }
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 WhenResetDefaultsIsCalled_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.ResetDefaults(); // 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); }
public void Dispose() { OpenStackNet.ResetDefaults(); }
public OpenStackNetTests() { OpenStackNet.ResetDefaults(); }