How to mock okta list APIs in .Net core?

I am creating unit test cases in .net core app and trying to mock one of the okta api which will return the groups for specific user. For ex:-

await _okta.Users.ListUserGroups(id).ToListAsync();

^ Can someone please help me to write test case through moq?

Hi @jatinderp.enest have you find solution for it?

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;
}