Merge pull request #35 from BinaryAlley/bugfix/fixes-flaky-unit-test-nested-directory-fixture

Fixes flaky unit test nested directory fixture
This commit is contained in:
BinaryAlley authored and GitHub committed 2024-10-29 21:19:02 +02:00
commit 9c279566ba
1 file changed
+9 -3
@@ -98,12 +98,18 @@ public class DirectoryFixture
private Directory CreateNestedDirectory(int currentDepth, int maxDepth, int maxChildrenPerDirectory) private Directory CreateNestedDirectory(int currentDepth, int maxDepth, int maxChildrenPerDirectory)
{ {
List<FileSystemItem> childItems = []; List<FileSystemItem> childItems = [];
// ensure we create at least one child if we haven't reached max depth
if (currentDepth < maxDepth) if (currentDepth < maxDepth)
{ {
int childCount = _faker.Random.Int(0, maxChildrenPerDirectory); // force at least 1 child, up to maxChildrenPerDirectory
int childCount = _faker.Random.Int(1, maxChildrenPerDirectory);
for (int i = 0; i < childCount; i++) for (int i = 0; i < childCount; i++)
childItems.Add(CreateNestedDirectory(currentDepth + 1, maxDepth, maxChildrenPerDirectory)); {
Directory childDirectory = CreateNestedDirectory(currentDepth + 1, maxDepth, maxChildrenPerDirectory);
ErrorOr<Updated> addResult = childDirectory.SetParent(childDirectory);
if (!addResult.IsError)
childItems.Add(childDirectory);
}
} }
return CreateDirectory(childItems: childItems); return CreateDirectory(childItems: childItems);
} }