Skip to content
This repository was archived by the owner on Dec 13, 2018. It is now read-only.

Commit e2834e4

Browse files
committed
Add test for Group CDS
1 parent 3999092 commit e2834e4

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed

test/Stormpath.SDK.Tests.Integration/Async/CustomData_search_tests.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
using Shouldly;
2121
using Stormpath.SDK.Account;
2222
using Stormpath.SDK.Directory;
23+
using Stormpath.SDK.Group;
2324
using Stormpath.SDK.Tests.Common;
2425
using Stormpath.SDK.Tests.Common.Integration;
2526
using Stormpath.SDK.Tests.Common.RandomData;
@@ -390,5 +391,45 @@ public async Task Ordering_by_custom_data(TestClientProvider clientBuilder)
390391
throw result.FinalException;
391392
}
392393
}
394+
395+
[Theory]
396+
[MemberData(nameof(TestClients.GetClients), MemberType = typeof(TestClients))]
397+
public async Task Searching_for_group_by_custom_data(TestClientProvider clientBuilder)
398+
{
399+
var client = clientBuilder.GetClient();
400+
401+
// Create an account with some custom data
402+
var testGroup = client.Instantiate<IGroup>()
403+
.SetName($"CDS Group {fixture.TestRunIdentifier}");
404+
testGroup.CustomData["on_duty"] = "TK421";
405+
406+
var directory = await client.GetDirectoryAsync(this.directoryHref);
407+
await directory.CreateGroupAsync(testGroup);
408+
this.fixture.CreatedGroupHrefs.Add(testGroup.Href);
409+
410+
#pragma warning disable CS0252 // Unintended reference comparison
411+
// Retry up to 3 times if CDS infrastructure isn't ready yet
412+
var result = await Policy.Handle<ShouldAssertException>()
413+
.WaitAndRetryAsync(Delay.CustomDataRetry)
414+
.ExecuteAndCaptureAsync(async () =>
415+
{
416+
var foundGroup = await directory.GetGroups()
417+
.Where(g => g.CustomData["on_duty"] == "TK421").SingleOrDefaultAsync();
418+
419+
foundGroup.ShouldNotBeNull();
420+
foundGroup.Href.ShouldBe(testGroup.Href);
421+
});
422+
#pragma warning restore CS0252
423+
424+
// Cleanup
425+
(await testGroup.DeleteAsync()).ShouldBeTrue();
426+
this.fixture.CreatedAccountHrefs.Remove(testGroup.Href);
427+
428+
// Report
429+
if (result.Outcome == OutcomeType.Failure)
430+
{
431+
throw result.FinalException;
432+
}
433+
}
393434
}
394435
}

test/Stormpath.SDK.Tests.Integration/Sync/CustomData_search_tests.cs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using Polly;
2020
using Shouldly;
2121
using Stormpath.SDK.Account;
22+
using Stormpath.SDK.Group;
2223
using Stormpath.SDK.Sync;
2324
using Stormpath.SDK.Tests.Common;
2425
using Stormpath.SDK.Tests.Common.Integration;
@@ -393,5 +394,47 @@ public void Ordering_by_custom_data(TestClientProvider clientBuilder)
393394
throw result.FinalException;
394395
}
395396
}
397+
398+
[Theory]
399+
[MemberData(nameof(TestClients.GetClients), MemberType = typeof(TestClients))]
400+
public void Searching_for_group_by_custom_data(TestClientProvider clientBuilder)
401+
{
402+
var client = clientBuilder.GetClient();
403+
404+
// Create an account with some custom data
405+
var testGroup = client.Instantiate<IGroup>()
406+
.SetName($"CDS Group {fixture.TestRunIdentifier}");
407+
testGroup.CustomData["on_duty"] = "TK421";
408+
409+
var directory = client.GetDirectory(this.directoryHref);
410+
directory.CreateGroup(testGroup);
411+
this.fixture.CreatedGroupHrefs.Add(testGroup.Href);
412+
413+
#pragma warning disable CS0252 // Unintended reference comparison
414+
// Retry up to 3 times if CDS infrastructure isn't ready yet
415+
var result = Policy.Handle<ShouldAssertException>()
416+
.WaitAndRetry(Delay.CustomDataRetry)
417+
.ExecuteAndCapture(() =>
418+
{
419+
var foundGroup = directory.GetGroups()
420+
.Where(g => g.CustomData["on_duty"] == "TK421")
421+
.Synchronously()
422+
.SingleOrDefault();
423+
424+
foundGroup.ShouldNotBeNull();
425+
foundGroup.Href.ShouldBe(testGroup.Href);
426+
});
427+
#pragma warning restore CS0252
428+
429+
// Cleanup
430+
testGroup.Delete().ShouldBeTrue();
431+
this.fixture.CreatedAccountHrefs.Remove(testGroup.Href);
432+
433+
// Report
434+
if (result.Outcome == OutcomeType.Failure)
435+
{
436+
throw result.FinalException;
437+
}
438+
}
396439
}
397440
}

0 commit comments

Comments
 (0)