(window.webpackJsonp=window.webpackJsonp||[]).push([[40],{172:function(e,t,n){"use strict";n.r(t),n.d(t,"frontMatter",(function(){returna})),n.d(t,"metadata",(function(){returnc})),n.d(t,"rightToc",(function(){returnu})),n.d(t,"default",(function(){returnl}));varr=n(2),o=n(9),i=(n(0),n(188)),a={id:"unit_testing",title:"Unit Testing"},c={id:"unit_testing",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",permalink:"/SpotifyAPI-NET/docs/next/unit_testing",editUrl:"https://github.com/JohnnyCrazy/SpotifyAPI-NET/edit/master/SpotifyAPI.Docs/docs/unit_testing.md",version:"next",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1605518005,sidebar:"docs",previous:{title:"IPlayableItem",permalink:"/SpotifyAPI-NET/docs/next/iplayableitem"},next:{title:"Introduction",permalink:"/SpotifyAPI-NET/docs/next/auth_introduction"}},u=[],s={rightToc:u};functionl(e){vart=e.components,n=Object(o.a)(e,["components"]);returnObject(i.b)("wrapper",Object(r.a)({},s,n,{components:t,mdxType:"MDXLayout"}),Object(i.b)("p",null,"The modular structure of the library makes it easy to mock the API when unit testing. Consider the following method:"),Object(i.b)("pre",null,Object(i.b)("code",Object(r.a)({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')),Object(i.b)("p",null,"Using ",Object(i.b)("inlineCode",{parentName:"p"},"Moq"),", this can be tested without doing any network requests:"),Object(i.b)("pre",null,Object(i.b)("code",Object(r.a)({parentName:"pre"},{className:"language-csharp"}),'[Test]\npublic async Task IsAdmin_SuccessTest()\n{\n var userProfileClient = new Mock<IUserProfileClient>();\n userProfileClient.Setup(u => u.Current()).Returns(\n Task.FromResult(new PrivateUser\n {\n Id = "1122095781"\n })\n );\n\n Assert.AreEqual(true, await IsAdmin(userProfileClient.Object));\n}\n')))}l.isMDXComponent=!0},188:function(e,t,n){"use strict";n.d(t,"a",(function(){returnp})),n.d(t,"b",(function(){returnb}));varr=n(0),o=n.n(r);functioni(e,t,n){returntine?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}functiona(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}functionc(e){for(vart=1;t<arguments.length;t++){varn=null!=arguments[t]?arguments[t]:{};t%2?a(Object(n),!0).forEach((function(t){i(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):a(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}returne}functionu(e,t){if(null==e)return{};varn,r,o=function(e,t){if(null==e)return{};varn,r,o={},i=Object.keys(e);for(r=0;r<i.length;r++)n=i[r],t.indexOf(n)>=0||(o[n]=e[n]);returno}(e,t);if(Object.getOwnPropertySymbols){vari=Object.getOwnPropertySymbols(e);for(r=0;r<i.length;r++)n=i[r],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}returno}vars=o.a.createContext({}),l=function(e){vart=o.a.useContext(s),n=t;returne&&(n="function"==typeofe?e(t):c({},t,{},e)),n},p=function(e){vart=l(e.components);returno.a.createElement(s.Provider,{value:t},e.children)},d={inlineCode:"code",wrapper:function(e){vart=e.children;returno.a.createElement(o.a.Fragment,{},t)}},f=Object(r.forwardRef)((function(e,t){varn=e.components,r=e.mdxType,i=e.originalType,a=e.parentName,s=u(e,["components","mdxType","originalType","parentName"]),p=l(n),f=r,b=p["".concat(a,".").concat(f)]||p[f]||d[f]||i;returnn?o.a.createElement(b,c({ref:t},s,{components:n})):o.a.createElement(b,c({ref:t},s))}));functionb(e,t){varn=arguments,r=t&&t.mdxType;if("string"==typeof