"use strict";(self.webpackChunkspotify_api_docs=self.webpackChunkspotify_api_docs||[]).push([[6849],{3905:function(e,t,n){n.d(t,{Zo:function(){returnl},kt:function(){returnd}});varr=n(7294);functioni(e,t,n){returntine?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}functiono(e,t){varn=Object.keys(e);if(Object.getOwnPropertySymbols){varr=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){returnObject.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}returnn}functiona(e){for(vart=1;t<arguments.length;t++){varn=null!=arguments[t]?arguments[t]:{};t%2?o(Object(n),!0).forEach((function(t){i(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):o(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}returne}functions(e,t){if(null==e)return{};varn,r,i=function(e,t){if(null==e)return{};varn,r,i={},o=Object.keys(e);for(r=0;r<o.length;r++)n=o[r],t.indexOf(n)>=0||(i[n]=e[n]);returni}(e,t);if(Object.getOwnPropertySymbols){varo=Object.getOwnPropertySymbols(e);for(r=0;r<o.length;r++)n=o[r],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}returni}varu=r.createContext({}),c=function(e){vart=r.useContext(u),n=t;returne&&(n="function"==typeofe?e(t):a(a({},t),e)),n},l=function(e){vart=c(e.components);returnr.createElement(u.Provider,{value:t},e.children)},p={inlineCode:"code",wrapper:function(e){vart=e.children;returnr.createElement(r.Fragment,{},t)}},f=r.forwardRef((function(e,t){varn=e.components,i=e.mdxType,o=e.originalType,u=e.parentName,l=s(e,["components","mdxType","originalType","parentName"]),f=c(n),d=i,m=f["".concat(u,".").concat(d)]||f[d]||p[d]||o;returnn?r.createElement(m,a(a({ref:t},l),{},{components:n})):r.createElement(m,a({ref:t},l))}));functiond(e,t){varn=arguments,i=t&&t.mdxType;if("string"==typeofe||i){varo=n.length,a=newArray(o);a[0]=f;vars={};for(varuint)hasOwnProperty.call(t,u)&&(s[u]=t[u]);s.originalType=e,s.mdxType="string"==typeofe?e:i,a[1]=s;for(varc=2;c<o;c++)a[c]=n[c];returnr.createElement.apply(null,a)}returnr.createElement.apply(null,n)}f.displayName="MDXCreateElement"},1991:function(e,t,n){n.r(t),n.d(t,{frontMatter:function(){returna},contentTitle:function(){returns},metadata:function(){returnu},toc:function(){returnc},default:function(){returnp}});varr=n(3117),i=n(102),o=(n(7294),n(3905)),a={id:"unit_testing",title:"Unit Testing"},s=void0,u={unversionedId:"unit_testing",id:"unit_testing",isDocsHomePage:!1,title:"Unit Testing",description:"The modular structure of the library makes it easy to mock the API when unit testing. Consider the following method:",source:"@site/docs/unit_testing.md",sourceDirName:".",slug:"/unit_testing",permalink:"/SpotifyAPI-NET/docs/unit_testing",editUrl:"https://github.com/JohnnyCrazy/SpotifyAPI-NET/edit/master/SpotifyAPI.Docs/docs/unit_testing.md",version:"current",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1643139046,formattedLastUpdatedAt:"1/25/2022",frontMatter:{id:"unit_testing",title:"Unit Testing"},sidebar:"docs",previous:{title:"IPlayableItem",permalink:"/SpotifyAPI-NET/docs/iplayableitem"},next:{title:"Introduction",permalink:"/SpotifyAPI-NET/docs/auth_introduction"}},c=[],l={toc:c};functionp(e){vart=e.components,n=(0,i.Z)(e,["components"]);return(0,o.kt)("wrapper",(0,r.Z)({},l,n,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("p",null,"The modular structure of the library makes it easy to mock the API when unit testing. Consider the following method:"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-csharp"},'public static async Task<bool> IsAdmin(IUserProfileClient userProfileClient)\n{\n // get logged in user\n var user = await userProfileClient.Current();\n\n // only my user id is an admin\n return user.Id == "1122095781";\n}\n')),(0,o.kt)("p",null,"Using ",(0,o.kt)("inlineCode",{parentName:"p"},"Moq"),", this can be tested without doing any network requests:"),(0,o.kt)("pre",null,(0,o.kt)("code",{p