Skip to content

Commit 8bc8df6

Browse files
committed
#49: Update TestSettings and GetGridPreferences method for OAuth access token support
1 parent ce8a0a6 commit 8bc8df6

8 files changed

Lines changed: 77 additions & 37 deletions

File tree

src/EssSharp.Abstractions/IEssServerFactory.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
using System.Threading.Tasks;
1+
using System;
22
using System.Threading;
3+
using System.Threading.Tasks;
34

45
using Microsoft.Extensions.Logging;
56

67
namespace EssSharp
78
{
9+
/// <summary />
810
public interface IEssServerFactory
911
{
1012
/// <summary>
@@ -17,6 +19,16 @@ public interface IEssServerFactory
1719
/// </summary>
1820
public int MaxDegreeOfParallelism { get; set; }
1921

22+
/// <summary>
23+
/// Gets or sets the tmeout of requests by any <see cref="IEssServer"/> created by this factory.
24+
/// </summary>
25+
public TimeSpan Timeout { get; set; }
26+
27+
/// <summary>
28+
/// Gets or sets the user agent of any <see cref="IEssServer"/> created by this factory.
29+
/// </summary>
30+
public string UserAgent { get; set; }
31+
2032
/// <summary>
2133
/// Creates a new server and, optionally, connects with the given credentials.
2234
/// </summary>

src/EssSharp.Integration/GetServerObjectTests.cs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public async Task Essbase_AfterReportCreation_CannotGetDrillthroughReportDetails
168168
[Fact(DisplayName = @"GetServerObjectTests - 07 - Essbase_AfterReportCreation_CanGetDefaultGridPrefernces"), Priority(07)]
169169
public async Task Essbase_AfterReportCreation_CanGetDefaultGridPrefernces()
170170
{
171-
// Get an unconnected server as a regular user.
171+
// Get an unconnected server.
172172
var server = GetEssServer();
173173

174174
var preferences = await server.GetDefaultGridPreferencesAsync();
@@ -185,7 +185,7 @@ public async Task Essbase_AfterReportCreation_CanGetDefaultGridPrefernces()
185185
[Fact(DisplayName = @"GetServerObjectTests - 08 - Essbase_AfterReportCreation_CanGetMembers"), Priority(08)]
186186
public async Task Essbase_AfterReportCreation_CanGetMembers()
187187
{
188-
// Get an unconnected server as a regular user.
188+
// Get an unconnected server.
189189
var server = GetEssServer();
190190

191191
// Get the Sample.Basic cube from the server.
@@ -225,7 +225,7 @@ public async Task Essbase_AfterReportCreation_CanGetMembers()
225225
[Fact(DisplayName = @"GetServerObjectTests - 08 - Essbase_AfterReportCreation_CanGetMembersSelected"), Priority(08)]
226226
public async Task Essbase_AfterReportCreation_CanGetMembersByAlias()
227227
{
228-
// Get an unconnected server as a regular user.
228+
// Get an unconnected server.
229229
var server = GetEssServer();
230230

231231
// Get the Sample.Basic cube from the server.
@@ -273,7 +273,7 @@ public async Task Essbase_AfterReportCreation_CanGetMembersByAlias()
273273
[Fact(DisplayName = @"GetServerObjectTests - 09 - Essbase_AfterReportCreation_CanGetMember"), Priority(09)]
274274
public async Task Essbase_AfterReportCreation_CanGetMember()
275275
{
276-
// Get an unconnected server as a regular user.
276+
// Get an unconnected server.
277277
var server = GetEssServer();
278278

279279
// Get the Sample.Basic cube from the server.
@@ -309,7 +309,7 @@ public async Task Essbase_AfterReportCreation_CanGetMember()
309309
[Fact(DisplayName = @"GetServerObjectTests - 10 - Essbase_AfterReportCreation_CanGetAncestor"), Priority(10)]
310310
public async Task Essbase_AfterReportCreation_CanGetAncestor()
311311
{
312-
// Get an unconnected server as a regular user.
312+
// Get an unconnected server.
313313
var server = GetEssServer();
314314

315315
// Get the Sample.Basic cube from the server.
@@ -337,7 +337,7 @@ public async Task Essbase_AfterReportCreation_CanGetAncestor()
337337
[Fact(DisplayName = @"GetServerObjectTests - 11 - Essbase_AfterReportCreation_CanGetDescendants"), Priority(11)]
338338
public async Task Essbase_AfterReportCreation_CanGetDescendants()
339339
{
340-
// Get an unconnected server as a regular user.
340+
// Get an unconnected server.
341341
var server = GetEssServer();
342342

343343
// Get the Sample.Basic cube from the server.
@@ -357,7 +357,7 @@ public async Task Essbase_AfterReportCreation_CanGetDescendants()
357357
[Fact(DisplayName = @"GetServerObjectTests - 12 - Essbase_AfterReportCreation_CanGetSiblings"), Priority(12)]
358358
public async Task Essbase_AfterReportCreation_CanGetSiblings()
359359
{
360-
// Get an unconnected server as a regular user.
360+
// Get an unconnected server.
361361
var server = GetEssServer();
362362

363363
// Get the Sample.Basic cube from the server.
@@ -375,7 +375,7 @@ public async Task Essbase_AfterReportCreation_CanGetSiblings()
375375
[Fact(DisplayName = @"GetServerObjectTests - 13 - Essbase_AfterReportCreation_CanGetMemberWithFields"), Priority(13)]
376376
public async Task Essbase_AfterReportCreation_CanGetMemberWithFields()
377377
{
378-
// Get an unconnected server as a regular user.
378+
// Get an unconnected server.
379379
var server = GetEssServer();
380380

381381
// Get the Sample.Basic cube from the server.
@@ -395,7 +395,7 @@ public async Task Essbase_AfterReportCreation_CanGetMemberWithFields()
395395
[Fact(DisplayName = @"GetServerObjectTests - 14 - Essbase_AfterReportCreation_CanGetMember_returnLevelNumber"), Priority(14)]
396396
public async Task Essbase_AfterReportCreation_CanGetMember_returnLevelNumber()
397397
{
398-
// Get an unconnected server as a regular user.
398+
// Get an unconnected server.
399399
var server = GetEssServer();
400400

401401
// Get the Sample.Basic cube from the server.
@@ -415,7 +415,7 @@ public async Task Essbase_AfterReportCreation_CanGetMember_returnLevelNumber()
415415
[Fact(DisplayName = @"GetServerObjectTests - 15 - Essbase_AfterReportCreation_CanGetMember_returnGenerationNumber"), Priority(15)]
416416
public async Task Essbase_AfterReportCreation_CanGetMember_returnGenerationNumber()
417417
{
418-
// Get an unconnected server as a regular user.
418+
// Get an unconnected server.
419419
var server = GetEssServer();
420420

421421
// Get the Sample.Basic cube from the server.
@@ -435,7 +435,7 @@ public async Task Essbase_AfterReportCreation_CanGetMember_returnGenerationNumbe
435435
[Fact(DisplayName = @"GetServerObjectTests - 16 - Essbase_AfterReportCreation_CanGetMemberByGen"), Priority(16)]
436436
public async Task Essbase_AfterReportCreation_CanGetMemberByGen()
437437
{
438-
// Get an unconnected server as a regular user.
438+
// Get an unconnected server.
439439
var server = GetEssServer();
440440

441441
// Get the Sample.Basic cube from the server.
@@ -451,7 +451,7 @@ public async Task Essbase_AfterReportCreation_CanGetMemberByGen()
451451
[Fact(DisplayName = @"GetServerObjectTests - 16 - Essbase_AfterReportCreation_CanGetMemberByLevel"), Priority(16)]
452452
public async Task Essbase_AfterReportCreation_CanGetMemberByLevel()
453453
{
454-
// Get an unconnected server as a regular user.
454+
// Get an unconnected server.
455455
var server = GetEssServer();
456456

457457
// Get the Sample.Basic cube from the server.
@@ -467,7 +467,7 @@ public async Task Essbase_AfterReportCreation_CanGetMemberByLevel()
467467
[Fact(DisplayName = @"GetServerObjectTests - 17 - Essbase_AfterReportCreation_CanGetDimensionMembers"), Priority(17)]
468468
public async Task Essbase_AfterReportCreation_CanGetDimensionMembers()
469469
{
470-
// Get an unconnected server as a regular user.
470+
// Get an unconnected server.
471471
var server = GetEssServer();
472472

473473
// Get the Sample.Basic cube from the server.
@@ -483,7 +483,7 @@ public async Task Essbase_AfterReportCreation_CanGetDimensionMembers()
483483
[Fact(DisplayName = @"GetServerObjectTests - 18 - Essbase_AfterReportCreation_CanGetDimensionFromMember"), Priority(18)]
484484
public async Task Essbase_AfterReportCreation_CanGetDimensionFromMember()
485485
{
486-
// Get an unconnected server as a regular user.
486+
// Get an unconnected server.
487487
var server = GetEssServer();
488488

489489
// Get the Sample.Basic cube from the server.
@@ -501,7 +501,7 @@ public async Task Essbase_AfterReportCreation_CanGetDimensionFromMember()
501501
[Fact(DisplayName = @"GetServerObjectTests - 19 - Essbase_AfterReportCreation_CanGetSameGenerationMembers"), Priority(19)]
502502
public async Task Essbase_AfterReportCreation_CanGetSameGenerationMembers()
503503
{
504-
// Get an unconnected server as a regular user.
504+
// Get an unconnected server.
505505
var server = GetEssServer();
506506

507507
// Get the Sample.Basic cube from the server.
@@ -530,8 +530,8 @@ public async Task Essbase_AfterReportCreation_CanGetSameGenerationMembers()
530530
[Fact(DisplayName = @"GetServerObjectTests - 20 - Essbase_AfterReportCreation_CanGetDynamicTimeSeriesMembersAsync"), Priority(20)]
531531
public async Task Essbase_AfterReportCreation_CanGetDynamicTimeSeriesMembersAsync()
532532
{
533-
// Get an unconnected server as a regular user.
534-
var server = GetEssServer(EssServerRole.User);
533+
// Get an unconnected server.
534+
var server = GetEssServer();
535535

536536
// Get the Sample.Basic cube from the server.
537537
var cube = await server
@@ -550,8 +550,8 @@ public async Task Essbase_AfterReportCreation_CanGetDynamicTimeSeriesMembersAsyn
550550
[Fact(DisplayName = @"GetServerObjectTests - 21 - Essbase_AfterReportCreation_CanGetDimensionsAsync"), Priority(21)]
551551
public async Task Essbase_AfterReportCreation_CanGetDimensionsAsync()
552552
{
553-
// Get an unconnected server as a regular user.
554-
var server = GetEssServer(EssServerRole.User);
553+
// Get an unconnected server.
554+
var server = GetEssServer();
555555

556556
// Get the Sample.Basic cube from the server.
557557
var cube = await server
@@ -578,8 +578,8 @@ public async Task Essbase_AfterReportCreation_CanGetDimensionsAsync()
578578
[Fact(DisplayName = @"GetServerObjectTests - 22 - Essbase_AfterReportCreation_CanGetDimensionGenerationsAsync"), Priority(22)]
579579
public async Task Essbase_AfterReportCreation_CanGetDimensionGenerationsAsync()
580580
{
581-
// Get an unconnected server as a regular user.
582-
var server = GetEssServer(EssServerRole.User);
581+
// Get an unconnected server.
582+
var server = GetEssServer();
583583

584584
// Get the Sample.Basic cube from the server.
585585
var cube = await server
@@ -605,8 +605,8 @@ public async Task Essbase_AfterReportCreation_CanGetDimensionGenerationsAsync()
605605
[Fact(DisplayName = @"GetServerObjectTests - 22 - Essbase_AfterReportCreation_CanGetDimensionLevelsAsync"), Priority(22)]
606606
public async Task Essbase_AfterReportCreation_CanGetDimensionLevelsAsync()
607607
{
608-
// Get an unconnected server as a regular user.
609-
var server = GetEssServer(EssServerRole.User);
608+
// Get an unconnected server.
609+
var server = GetEssServer();
610610

611611
// Get the Sample.Basic cube from the server.
612612
var cube = await server
@@ -632,7 +632,7 @@ public async Task Essbase_AfterReportCreation_CanGetDimensionLevelsAsync()
632632
[Fact(DisplayName = @"GetServerObjectTests - 23 - Essbase_AfterReportCreation_CanGetBottemLevelDescendants"), Priority(23)]
633633
public async Task Essbase_AfterReportCreation_CanGetBottemLevelDescendants()
634634
{
635-
// Get an unconnected server as a regular user.
635+
// Get an unconnected server.
636636
var server = GetEssServer();
637637

638638
// Get the Sample.Basic cube from the server.

src/EssSharp.Integration/Setup/IntegrationTestFactory.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,11 @@ internal static IEssServer GetEssServer( EssServerRole role = EssServerRole.Serv
213213

214214
factory ??= new EssServerFactory();
215215

216-
return factory.CreateEssServer(connection.Server, connection.Username, connection.Password, connect: false);
216+
return (connection is { AccessToken.Length: > 0 }) switch
217+
{
218+
true => factory.CreateEssServer(connection.Server, oauthToken: connection.AccessToken, connect: false),
219+
false => factory.CreateEssServer(connection.Server, username: connection.Username, password: connection.Password, connect: false)
220+
};
217221
}
218222

219223
/// <summary />

src/EssSharp.Integration/Setup/IntegrationTestSettings.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,20 @@ public class IntegrationTestSettingsConnection : ICloneable
2424
/// <summary />
2525
public string Password { get; set; }
2626

27+
/// <summary />
28+
public string AccessToken { get; set; }
29+
2730
/// <summary />
2831
public EssServerRole Role { get; set; }
2932

3033
/// <inheritdoc />
3134
public object Clone() => new IntegrationTestSettingsConnection()
3235
{
33-
Server = this.Server,
34-
Username = this.Username,
35-
Password = this.Password,
36-
Role = this.Role
36+
Server = this.Server,
37+
AccessToken = this.AccessToken,
38+
Username = this.Username,
39+
Password = this.Password,
40+
Role = this.Role
3741
};
3842
}
3943

src/EssSharp.Integration/appsettings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,21 @@
66
"Connections": [
77
{
88
"Server": "http://localhost:9000/essbase",
9+
"AccessToken": "",
910
"Username": "admin",
1011
"Password": "welcome1",
1112
"Role": "ServiceAdministrator"
1213
},
1314
{
1415
"Server": "http://localhost:9000/essbase",
16+
"AccessToken": "",
1517
"Username": "poweruser",
1618
"Password": "welcome2",
1719
"Role": "PowerUser"
1820
},
1921
{
2022
"Server": "http://localhost:9000/essbase",
23+
"AccessToken": "",
2124
"Username": "user",
2225
"Password": "welcome3",
2326
"Role": "User"

src/EssSharp/EssServer.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,7 @@ public async Task<IEssDatasource> GetDatasourceAsync (string datasourceName , Ca
698698
// Apply the base configuration settings.
699699
BasePath = Configuration.BasePath,
700700
MaxDegreeOfParallelism = Configuration.MaxDegreeOfParallelism,
701+
AccessToken = Configuration.AccessToken,
701702
Username = Configuration.Username,
702703
Password = Configuration.Password,
703704
Timeout = Configuration.Timeout,

src/EssSharp/EssServerFactory.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Threading;
1+
using System;
2+
using System.Threading;
23
using System.Threading.Tasks;
34

45
using Microsoft.Extensions.Logging;
@@ -17,6 +18,14 @@ public class EssServerFactory : IEssServerFactory
1718
/// <remarks>The default number of concurrent requests is <c>4</c>.</remarks>
1819
public int MaxDegreeOfParallelism { get; set; } = 4;
1920

21+
/// <inheritdoc />
22+
/// <remarks>The default timout is <see cref="int.MaxValue"/> milliseconds.</remarks>
23+
public TimeSpan Timeout { get; set; } = TimeSpan.FromMilliseconds(int.MaxValue);
24+
25+
/// <inheritdoc />
26+
/// <remarks>The default user agent is EssSharp/{version}.</remarks>
27+
public string UserAgent { get; set; } = @$"{nameof(EssSharp)}/{typeof(EssServer).Assembly.GetName().Version}";
28+
2029
/// <inheritdoc />
2130
/// <returns>An <see cref="EssServer" /> object.</returns>
2231
public IEssServer CreateEssServer( string server, string oauthToken, bool connect = true )
@@ -28,8 +37,10 @@ public IEssServer CreateEssServer( string server, string oauthToken, bool connec
2837
{
2938
var essServer = new EssServer(server, oauthToken);
3039
{
31-
essServer.Configuration.Logger = Logger;
40+
essServer.Configuration.Logger = Logger;
3241
essServer.Configuration.MaxDegreeOfParallelism = MaxDegreeOfParallelism;
42+
essServer.Configuration.Timeout = Timeout;
43+
essServer.Configuration.UserAgent = UserAgent;
3344
}
3445

3546
if ( connect )
@@ -49,8 +60,10 @@ public IEssServer CreateEssServer( string server, string username, string passwo
4960
{
5061
var essServer = new EssServer(server, username, password);
5162
{
52-
essServer.Configuration.Logger = Logger;
63+
essServer.Configuration.Logger = Logger;
5364
essServer.Configuration.MaxDegreeOfParallelism = MaxDegreeOfParallelism;
65+
essServer.Configuration.Timeout = Timeout;
66+
essServer.Configuration.UserAgent = UserAgent;
5467
}
5568

5669
if ( connect )

src/EssSharp/Extensions/ApiFactory.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
namespace EssSharp
77
{
8+
/// <summary />
89
internal class ApiFactory
910
{
1011
/// <summary />
@@ -13,21 +14,23 @@ internal class ApiFactory
1314
/// <param name="username" />
1415
/// <param name="password" />
1516
/// <param name="timeout" />
17+
/// <param name="userAgent" />
1618
/// <param name="callerPath" />
1719
/// <param name="callerName" />
18-
public static T GetApi<T>( string basePath, string username, string password, TimeSpan? timeout = null, [System.Runtime.CompilerServices.CallerFilePath] string callerPath = null, [System.Runtime.CompilerServices.CallerMemberName] string callerName = null ) where T : IApiAccessor, new() =>
19-
GetApiAndClient<T>(new Configuration() { BasePath = basePath, Username = username, Password = password, Timeout = timeout ?? TimeSpan.FromMilliseconds(int.MaxValue), UserAgent = "EssSharp.Client/1.0.0.0" }, null, callerPath, callerName).Api;
20+
public static T GetApi<T>( string basePath, string username, string password, TimeSpan? timeout = null, string userAgent = null, [System.Runtime.CompilerServices.CallerFilePath] string callerPath = null, [System.Runtime.CompilerServices.CallerMemberName] string callerName = null ) where T : IApiAccessor, new() =>
21+
GetApiAndClient<T>(new Configuration() { BasePath = basePath, Username = username, Password = password, Timeout = timeout ?? TimeSpan.FromMilliseconds(int.MaxValue), UserAgent = userAgent ?? $"{nameof(EssSharp)}/{typeof(EssServer).Assembly.GetName().Version}" }, null, callerPath, callerName).Api;
2022

2123
/// <summary />
2224
/// <typeparam name="T" />
2325
/// <param name="basePath" />
2426
/// <param name="username" />
2527
/// <param name="password" />
2628
/// <param name="timeout" />
29+
/// <param name="userAgent" />
2730
/// <param name="callerPath" />
2831
/// <param name="callerName" />
29-
public static (T Api, ApiClient Client) GetApiAndClient<T>( string basePath, string username, string password, TimeSpan? timeout = null, [System.Runtime.CompilerServices.CallerFilePath] string callerPath = null, [System.Runtime.CompilerServices.CallerMemberName] string callerName = null ) where T : IApiAccessor, new() =>
30-
GetApiAndClient<T>(new Configuration() { BasePath = basePath, Username = username, Password = password, Timeout = timeout ?? TimeSpan.FromMilliseconds(int.MaxValue), UserAgent = "EssSharp.Client/1.0.0.0" }, null, callerPath, callerName);
32+
public static (T Api, ApiClient Client) GetApiAndClient<T>( string basePath, string username, string password, TimeSpan? timeout = null, string userAgent = null, [System.Runtime.CompilerServices.CallerFilePath] string callerPath = null, [System.Runtime.CompilerServices.CallerMemberName] string callerName = null ) where T : IApiAccessor, new() =>
33+
GetApiAndClient<T>(new Configuration() { BasePath = basePath, Username = username, Password = password, Timeout = timeout ?? TimeSpan.FromMilliseconds(int.MaxValue), UserAgent = userAgent ?? $"{nameof(EssSharp)}/{typeof(EssServer).Assembly.GetName().Version}" }, null, callerPath, callerName);
3134

3235
/// <summary />
3336
/// <typeparam name="T" />

0 commit comments

Comments
 (0)