public async Task AuthenticateFailed_SuccessfullyTraced() { var authenticatorMock = A.Fake <IAuthenticator>(x => x.Wrapping(new BasicAuthenticator("user", "pw"))); A.CallTo(() => authenticatorMock.AuthenticateAsync(A <HttpRequestMessage> .Ignored, A <CancellationToken> .Ignored)).Returns(Task.FromResult(false)); var trace = default(string); var config = new ODataManagerConfiguration(BaseUri) { Authenticator = authenticatorMock }; config.OnTrace += (format, args) => trace += string.Format(format, args); config.OnTrace += (format, args) => output.WriteLine(format, args); var manager = new ODataManager(config); authenticatorMock.OnTrace.Invoke("Triggered trace message in " + nameof(authenticatorMock)); await manager.Client .For <Product>("Products") .Top(1) .FindEntriesAsync(); Assert.Contains("Triggered trace message in " + nameof(authenticatorMock), trace); Assert.Contains("ODataManager: Authentication not successful", trace); }
public async Task UseODataClientAndOnTraceAndConverter_Success() { var trace = default(string); var config = new ODataManagerConfiguration(BaseUri) { Authenticator = new BasicAuthenticator("user", "pw"), VersioningManager = new QueryParamVersioningManager("1.0") }; config.TypeCache.Converter.RegisterTypeConverter <Product>((IDictionary <string, object> dict) => dict.ToInstance <Product>()); config.OnTrace = (format, args) => trace = string.Format(format, args); var manager = new ODataManager(config); trace = null; var dx = ODataDynamic.Expression; IEnumerable <dynamic> entities = await manager.Client .For(dx.Products) .FindEntriesAsync(); Assert.NotEmpty(trace); Assert.Equal(11, entities.ToList().Count); trace = null; var entities2 = await manager.Client .For <Product>("Products") .FindEntriesAsync(); Assert.NotEmpty(trace); Assert.Equal(11, entities2.ToList().Count); }
public async Task ApplyVersionFailed_SuccessfullyTraced() { var versioningManagerMock = A.Fake <IVersioningManager>(x => x.Wrapping(new QueryParamVersioningManager("1.0"))); A.CallTo(() => versioningManagerMock.ApplyVersion(A <HttpRequestMessage> .Ignored)).Returns(false); var trace = default(string); var config = new ODataManagerConfiguration(BaseUri) { VersioningManager = versioningManagerMock }; config.OnTrace += (format, args) => trace += string.Format(format, args); config.OnTrace += (format, args) => output.WriteLine(format, args); var manager = new ODataManager(config); versioningManagerMock.OnTrace.Invoke("Triggered trace message in " + nameof(versioningManagerMock)); await manager.Client .For <Product>("Products") .Top(1) .FindEntriesAsync(); Assert.Contains("Triggered trace message in " + nameof(versioningManagerMock), trace); Assert.Contains("ODataManager: Applying version not successful", trace); }
public void Initialize_Configuration_DefaultCtor() { var config = new ODataManagerConfiguration(); Assert.True(config.UseAbsoluteReferenceUris); Assert.Null(config.BaseUri); Assert.Null(config.HttpClient); Assert.Null(config.Authenticator); Assert.Null(config.VersioningManager); }
public void Initialize_Configuration_UriClientCtor() { var config = new ODataManagerConfiguration(new Uri("https://localhost:5000")); Assert.True(config.UseAbsoluteReferenceUris); Assert.NotNull(config.BaseUri); Assert.Null(config.HttpClient); Assert.Null(config.Authenticator); Assert.Null(config.VersioningManager); Assert.Equal("https://localhost:5000/", config.BaseUri.ToString()); }
public void CtorWithOnlyOneApiEndpoint_Exception() { var ex = Assert.Throws <InvalidOperationException>(() => { _ = new ODataManagerConfiguration(new HttpClient { BaseAddress = new Uri("http://localhost") }) { BaseUri = new Uri("http://localhost") }; }); Assert.Equal("Unable to set BaseUri when BaseAddress is specified on HttpClient.", ex.Message); }