MSDN Magazine - March 2009 - (Page 72) ASP.NET Web Part, you should create also yields more testable code; more on a class project to host your Web Part, a this in the section “Testing Code and Visual Studio Web Application projManaging Dependencies”. ect, and optionally a unit test project. There are other tools you can We have included an example of this use. Removing the dependency on setup in the Visual Studio SPTips soluSharePoint across the entire codebase is tion (included with the article’s sample Figure 4 The Web Part Export Menu Option unrealistic. Developing for SharePoint code) that you can use for off-server off server generally requires the use of Web Part development. a SharePoint instance, usually hosted in a virtual maIn the Web Part project, the default constructor chine, early in the SDLC. With the growth of Sharecontains a line that sets the ExportMode property of Point development, several tools have been created to the Web Part: Figure 5 The Web Part deal with this significant dependency. One such tool public WebPartOffServerExample() is Bamboo Solutions’ SharePoint on Vista InstallaImported into Share{ tion Helper. This tool enables the installation of WSS Point this.ExportMode = WebPartExportMode.All; } . SP or MOSS SP on Windows Vista, giving you the ability to develop SharePoint-dependent solutions withThis line allows you to generate a .webpart deployment file based on the properties you configure for the Web part, as shown out needing Windows Server. Microsoft does not support running SharePoint in this way. Howin Figure 4. ever, this approach has resonated in the SharePoint development You can then import the Web Part into SharePoint via this deployment file (Figure 5). You should not use the SharePoint community because it helps reduce the footprint that this depenbackward-compatible import file type, .dwp. The underlying XML dency on SharePoint creates. For further information, see “How schema for a .dwp isn’t as rich and requires that you reference the to install Windows SharePoint Services . SP on Vista x/x” (community.bamboosolutions.com/blogs/bambooteamblog/archive/2008/05/21/ Microsoft.SharePoint assembly early in the SDLC. Note that you can ensure the creation of .webpart de- how-to-install-windows-sharepoint-services-3-0-sp1-on-vista-x64-x86.aspx). ployment files by inheriting from the WebPart class in the System.Web.UI.WebControls.WebParts namespace rather than the 5. Testing Code and Managing Dependencies The widespread adoption of unit test frameworks and related test Microsoft.SharePoint.WebPartPages namespace. (For examples of tools has naturally made its way into SharePoint development. Unit when you might want to inherit from SharePoint’s WebPart class, tests and integration tests are two primary test categories. Both test see the source listed in the “Resources” sidebar.) Microsoft exposes a significant subset of the SharePoint object types exhibit different characteristics and require the use of differmodel through Web services. Using SharePoint Web services to ac- ent tools and techniques. When writing unit or off-server tests, it’s considered a best cess the object model allows you to develop a solution without a practice to simulate external dependencies with substitutes such as dependency on direct access to SharePoint assemblies. SharePoint hosts the Web services in the _vti_bin virtual directory on each stubs or mocks. By passing in objects that mimic external dependencies, your test becomes faster and more focused on the behavWeb Front End (WFE) server. In Visual Studio, you add SharePoint Web services to a solution ior you are testing. To be effective, this approach requires that you in the same manner as you do any Web service reference. Share- follow the principles of testable, object-oriented design, or use a specialized framework for isolating tightly coupled components Point Web service URLs have the following format: of your solution. http:// :port/[sites/][SubSite/]_vti_bin/WebService.asmx Identify the behaviors and business rules that are infrastructure where is the URL associated with the Web independent and make sure you have a strategy for testing them in application. For example: http://www.contoso.com:35000/_vti_bin/Lists.asmx isolation. To isolate interactions with SharePoint, a database, or a When you add a Web service reference, Visual Studio creates Web service, you can introduce the Repository pattern to abstract proxy classes for both the service and the data types used by the away the details of the back-end system. These repository objects service. For more information on interacting with these Web ser- can be passed into higher level components by using inversion of vices, please see “WSS SDK . Topic: Web Service Guidelines” control (IoC) and dependency injection (DI) principles. For infor(msdn.microsoft.com/library/ms458094.aspx) and “SharePoint Web Ser- mation on IoC and DI, see “Tame Your Software Dependencies for vices” (msdn.microsoft.com/library/ms479390.aspx) . More Flexible Apps” at msdn.microsoft.com/magazine/cc337885. Implementing a three-tiered architecture furthers the To increase the testability of your presentation components goal of isolating code and removing dependencies on SharePoint implement the Model-View-Presenter (MVP) pattern. For more and other outside sources. This approach can improve your ability information about testable code patterns, see “Design for Testabilto develop off server by abstracting business, data access, and UI ity” (msdn.microsoft.com/magazine/dd263069). logic from one another, enabling you to break code into manageOther major challenges that SharePoint developers face when able pieces and reduce dependencies between them. This approach unit testing deal with the SharePoint object model. Simply put, 72 msdn magazine SharePoint Best Practices http://community.bamboosolutions.com/blogs/bambooteamblog/archive/2008/05/21/how-to-install-windows-sharepoint-services-3-0-sp1-on-vista-x64-x86.aspx http://msdn.microsoft.com/library/ms458094.aspx http://msdn.microsoft.com/magazine/cc337885 http://msdn.microsoft.com/library/ms479390.aspx http://msdn.microsoft.com/magazine/dd263069
For optimal viewing of this digital publication, please enable JavaScript and then refresh the page. If you would like to try to load the digital publication without using Flash Player detection, please click here.