We can mock “TestAsyncEnumerable” to get the combination of users and groups.
Example -
public class TestAsyncEnumerable : List, IAsyncEnumerable
{
public TestAsyncEnumerable(IEnumerable enumerable) : base(enumerable) { }
public IAsyncEnumerator<T> GetAsyncEnumerator(CancellationToken cancellationToken = default) => new TestAsyncEnumerator<T>(GetEnumerator());
}
public class TestAsyncEnumerator<T> : IAsyncEnumerator<T>
{
private readonly IEnumerator<T> _inner;
public TestAsyncEnumerator(IEnumerator<T> inner)
{
_inner = inner;
}
public ValueTask<bool> MoveNextAsync() => new ValueTask<bool>(_inner.MoveNext());
public T Current => _inner.Current;
public ValueTask DisposeAsync()
{
_inner.Dispose();
return new ValueTask(Task.CompletedTask);
}
}
private static IUser UserWithGroup()
{
var user = new Mock();
user.Setup(x => x.Id).Returns(“1”);
user.Setup(x => x.Status).Returns(UserStatus.Active);
user.Setup(x => x.Credentials.Provider.Type).Returns(AuthenticationProviderType.Okta);
user.Setup(x => x.Profile).Returns(new UserProfile { Login = “email@email.com” });
user.Setup(x => x.Groups).Returns(new TestAsyncEnumerable(new List { new Group() }));
return user.Object;
}