Skip to content
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.

How to UnitTest the SDK? #32

Open
aramkoukia opened this issue Mar 17, 2016 · 1 comment
Open

How to UnitTest the SDK? #32

aramkoukia opened this issue Mar 17, 2016 · 1 comment

Comments

@aramkoukia
Copy link

I've been trying to UnitTest the SDK and using nsubstitute.

Have not found a way to return something i want out of the client.Users object.

The client.Users returns an IUserCollection object which I cannot create a fake object to return in the unit tests.

@duncanp-lseg
Copy link

Apologies for the delay in anyone responding to this issue. I guess by now that you've either found a solution or worked round the problem. If not, please ask a question on stackoverflow, tagging the question with one of the aad* or msgraph tags.

I assume you are referring to the Microsoft.Azure.ActiveDirectory.GraphClient library. The client object and user collection are both interfaces so you could provide your own implementations of these interfaces for test purposes. I'm not familiar with NSubstitute but the following code seems to create a dummy client and user collection:

// Create a dummy user collection
var users = Substitute.For<Microsoft.Azure.ActiveDirectory.GraphClient.IUserCollection>();
var userFetcher1 = Substitute.For<Microsoft.Azure.ActiveDirectory.GraphClient.IUserFetcher>();
users.GetByObjectId(null).ReturnsForAnyArgs(userFetcher1);

// Create a dummy client
var client = Substitute.For<Microsoft.Azure.ActiveDirectory.GraphClient.IActiveDirectoryClient>();
client.Users.Returns(users);

// Get an item from the collection
var obj = client.Users.GetByObjectId("123");

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants