<titledata-react-helmet="true">Unit Testing | SpotifyAPI-NET</title><metadata-react-helmet="true"name="docsearch:version"content="next"><metadata-react-helmet="true"name="twitter:card"content="summary_large_image"><metadata-react-helmet="true"property="og:title"content="Unit Testing | SpotifyAPI-NET"><metadata-react-helmet="true"name="description"content="The modular structure of the library makes it easy to mock the API when unit testing. Consider the following method:"><metadata-react-helmet="true"property="og:description"content="The modular structure of the library makes it easy to mock the API when unit testing. Consider the following method:"><metadata-react-helmet="true"property="og:url"content="https://johnnycrazy.github.io/SpotifyAPI-NET//docs/next/unit_testing"><linkdata-react-helmet="true"rel="shortcut icon"href="/img/favicon.ico"><linkdata-react-helmet="true"rel="canonical"href="https://johnnycrazy.github.io/SpotifyAPI-NET//docs/next/unit_testing"><linkrel="stylesheet"href="/styles.8a053330.css">
</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> // only my user id is an admin</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> return user.Id == "1122095781";</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain">}</span></div></div></div></div></div><p>Using <code>Moq</code>, this can be tested without doing any network requests:</p><divclass="mdxCodeBlock_iHAB"><divclass="codeBlockContent_32p_"><buttontype="button"aria-label="Copy code to clipboard"class="copyButton_1BYj">Copy</button><divtabindex="0"class="prism-code language-csharp codeBlock_19pQ"><divclass="codeBlockLines_2n9r"style="color:#bfc7d5;background-color:#292d3e"><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain">[Test]</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain">public async Task IsAdmin_SuccessTest()</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain">{</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> var userProfileClient = new Mock<IUserProfileClient>();</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> userProfileClient.Setup(u => u.Current()).Returns(</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> Task.FromResult(new PrivateUser</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> {</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> Id = "1122095781"</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> })</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> );</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"style="display:inline-block">