1. Trang chủ
  2. » Công Nghệ Thông Tin

Pro .NET 2.0 Extreme Programming 2006 phần 10 ppsx

33 278 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 33
Dung lượng 682,67 KB

Nội dung

#endregion namespace TestLayer { public class CategoryTests { public CategoryTests() { } } } 4. Right-click the TestLayer and select Add Reference. 5. In the Add Reference dialog box, click the Browse tab. Navigate to the NUnit applica- tion’s bin directory, which is located at C:\Program Files\NUnit 2.2.2\bin (if you installed NUnit in the default location). 6. Select the following DLLs: nunit.core.dll, nunit.extensions.dll, nunit.framework.dll, nunit.uikit.dll, nunit.util.dll, and nunit-gui-runner.dll. Then click the Open button. 7. Verify that the NUnit DLLs are listed in the Browse tab, as shown in Figure A-10, and then click the OK button. Figure A-10. Adding NUnit DLL references APPENDIX A ■ PREPARING YOUR DEVELOPMENT ENVIRONMENT 287 4800AppA.qrk 5/22/06 9:04 PM Page 287 8. Change the code to look like this: #region Using directives; using System; using System.Collections.Generic; using System.Text; using NUnit.Framework; using BusinessLayer; #endregion namespace TestLayer { [TestFixture] public class CategoryTests { Category computerCategory; [SetUp] public void Init() { computerCategory = new Category(1, // Category ID "Computer", // Category Name "Computer related stuff."); // Category Description } [TearDown] public void Destroy() { computerCategory = null; } [Test] public void GetCategoryName() { string computerCategoryName = computerCategory.CategoryName; Assert.IsNotNull(computerCategoryName, "The category name was null, gasp!"); Assert.AreEqual("Computer", computerCategoryName, "Got the wrong category name, gasp!"); } } } 9. Add a C# file to the BusinessLayer project called Category.cs. APPENDIX A ■ PREPARING YOUR DEVELOPMENT ENVIRONMENT288 4800AppA.qrk 5/22/06 9:04 PM Page 288 10. Change the Category.cs file code to look like this: #region Using directives using System; using System.Collections.Generic; usinf System.Text; #endregion namespace BusinessLayer { public class Category { private int categoryID; private string categoryName; private string categoryDescription; public Category(int categoryID, string categoryName, string categoryDescription) { this.categoryID = categoryID; this.categoryName = categoryName; this.categoryDescription = categoryDescription; } public string CategoryName { get { return this.categoryName; } } } } 11. Right-click the TestLayer project and select Add Reference. 12. Click the Projects tab, select BusinessLayer from the list, and click the OK button. 13. Right-click the TestLayer project and select Set as StartUp Project. The TestLayer project name will now appear in bold. 14. Select Build ➤ Build Solution (or press Ctrl+Shift+B). 15. Select Debug ➤ Start (or press F5). This will bring up the NUnit window, as shown in Figure A-11. APPENDIX A ■ PREPARING YOUR DEVELOPMENT ENVIRONMENT 289 4800AppA.qrk 5/22/06 9:04 PM Page 289 Figure A-11. The NUnit window 16. Click the Run button. 17. If everything went correctly, you should see a green bar under the Run button, and the testing tree on the left should have all green circles, as shown in Figure A-12. Click the window’s close box to exit NUnit. Figure A-12. Results of running the test Don’t be worried if you don’t understand everything in the source code files you just created. Chapters 7, 13, and 15 explain how these files work. This example is very trivial and not optimized in any way. However, it does start to give you an idea of what a testing framework does. APPENDIX A ■ PREPARING YOUR DEVELOPMENT ENVIRONMENT290 4800AppA.qrk 5/22/06 9:04 PM Page 290 The Database Setup For this book’s examples, you also need to configure the Northwind database. This involves setting up the Open Database Connectivity (ODBC) data source and associating that data source with Visual Studio Solution Explorer. ■Note When deciding on the type of database to use in our examples, we went back and forth several times. We thought of using Microsoft SQL Server or the Microsoft SQL Server Database Engine (MSDE), but ended up using Microsoft Access because we could package the complete database in our source archive. You can find a copy of the Northwind.mdb file in the source code archive for this book at the Apress web- site (www.apress.com). Setting Up the ODBC Data Source First, you need to set up an ODBC data source that references the database. To configure an ODBC data source, follow these steps: 1. Extract and copy the Northwind.mdb database file to a local directory on your hard drive (for example, C:\xpnet\database\). ■Note In our examples, we are assuming that you are using Microsoft Windows XP. If you are not, then you will need to adjust these instructions accordingly. 2. Open Control Panel, select Administrative Tools, and launch the Data Sources (ODBC) application. You will see a dialog box similar to the one shown in Figure A-13. Figure A-13. The ODBC Data Source Administrator dialog box APPENDIX A ■ PREPARING YOUR DEVELOPMENT ENVIRONMENT 291 4800AppA.qrk 5/22/06 9:04 PM Page 291 3. Select the System DSN tab and click the Add button to open the Create New Data Source dialog box, as shown in Figure A-14. Figure A-14. The Create New Data Source dialog box 4. Select the Microsoft Access Driver and click the Finish button. 5. In the ODBC Microsoft Access dialog box, enter Northwind in the Data Source Name field, as shown in Figure A-15. Then click the Select button. Figure A-15. The ODBC Microsoft Access Setup dialog box 6. Enter the path to the location of your Northwind.mdb file and click OK. The ODBC Microsoft Access Setup dialog box will show your changes. Click OK to commit your changes. 7. The ODBC Data Source Administrator dialog box appears with the Northwind data source in the list. Click the OK button to close this dialog box. Connecting to the Database Now that you have an ODBC data source referencing the database, you can set up a new Visual Studio data connection. Follow these steps to connect to the Northwind database: APPENDIX A ■ PREPARING YOUR DEVELOPMENT ENVIRONMENT292 4800AppA.qrk 5/22/06 9:04 PM Page 292 1. Open the Northwind solution, and then open the Server Explorer, if it is not already visible. (Choose View ➤ Server Explorer or press Ctrl+Alt+S to display the Server Explorer.) 2. Right-click Data Connections in the Server Explorer and select Add Connection. 3. Click the Provider tab and select Microsoft OLE DB Provider for ODBC Drivers, as shown in Figure A-16. Figure A-16. Selecting the Microsoft OLE DB Provider for ODBC Drivers 4. Click the Connection tab and select Use Data Source Name. Select Northwind in the first drop-down list. Then click OK. If you expand the Data Connections node in the Server Explorer, you will see a connec- tion for ACCESS.C:\xpnet\database\northwind.admin. If you expand the Northwind database, you will see icons for Tables and Views, as shown in Figure A-17. These are parts of the Northwind database. Figure A-17. The Server Explorer with the new data connection APPENDIX A ■ PREPARING YOUR DEVELOPMENT ENVIRONMENT 293 4800AppA.qrk 5/22/06 9:04 PM Page 293 Browsing the Database Let’s take a quick look at the database itself. Follow these steps: 1. Open the Server Explorer and expand the ACCESS connection. You should now see new entries showing the Tables and Views nodes (see Figure A-17). 2. Expand the Tables node. A list of all the tables in the database will be displayed, as shown in Figure A-18. Figure A-18. Tables in the Northwind database 3. Right-click the Products table and select Retrieve Data from Table. This will retrieve all the data in the Products table in the Northwind database and display it in a spread- sheet form, as shown in Figure A-19. APPENDIX A ■ PREPARING YOUR DEVELOPMENT ENVIRONMENT294 4800AppA.qrk 5/22/06 9:04 PM Page 294 Figure A-19. The Products table You can add delete and change data directly from this form. You can also use this same process to view any table in the database. You now have set up your environment for the examples in this book. You created the appropriate Visual Studio solution and projects, configured NUnit, and finally configured your Microsoft Access data source, which holds the database that you will be using in the examples. APPENDIX A ■ PREPARING YOUR DEVELOPMENT ENVIRONMENT 295 4800AppA.qrk 5/22/06 9:04 PM Page 295 4800AppA.qrk 5/22/06 9:04 PM Page 296 [...]... responsibilities of team, 19–24 when not to use, 17 Extreme Programming Explained: Embrace Change (Addison-Wesley, 1999), by Kent Beck, 7 Extreme Programming Jobs mailing list, website address for joining, 306 Extreme Programming mailing list, website address for joining, 306 Extreme Programming User Groups mailing list, website address for joining, 306 Extreme Programming Wiki, website address, 305 ■ F Feature... Objects project—a generic unit testing framework used when developing NET unit tests with mock objects The current project is pretty light on documentation It should improve as the project evolves Mailing Lists You may want to join the following mailing lists: • Extreme Programming (http://groups.yahoo.com/group/extremeprogramming/): This is a Yahoo forum discussing XP practices and principles • Extreme Programming. .. second iteration, 231–237 paired programming defined, 6 for improving quality of projects, 10 rules of, 44 parameters promoting local variables to, 105 removing, 106 reordering, 106 107 Pascal letter case, defined, 298–299 planning game, as part of XP best practice, 12 planning game phase, story prioritization in, 33 process, waterfall methodology heavily focused on, 3 Process Order Request task, adding... tests for ProductTests.cs, 184–188 309 4800Index 310 5/24/06 8:48 PM Page 310 ■INDEX after invoking Extract Method, 99 100 before invoking Extract Method, 98–99 after invoking Promote Local Variable to Parameter tool, 105 before invoking Promote Local Variable to Parameter tool, 105 before invoking Remove Parameters tool, 106 after invoking Remove Parameters tool, 106 before invoking Rename tool, 100 after... down a category for testing, 180–184 program attribute, executable name specified by, 55 project organization See solution and project organization project plan, waterfall method assumption that project can be managed by, 4 project tag, NAnt build file, 54 projects, making a small initial investment in, 7 Promote Local Variable to Parameter tool, function of, 105 property tags, NAnt build file, 54 Pryce,... 305 hosting the NUnit unit testing software, 306 for information about CCNet, 84 for information about configuring CruiseControl.NET as a service, 86 for joining Extreme Programming Jobs mailing list, 306 for joining Extreme Programming mailing list, 306 for joining Extreme Programming User Groups mailing list, 306 for joining JUnit mailing list, 306 for joining NUnit mailing list, 306 The New Methodology,... of documentation, including the original C3 papers, which capture the spirit of that exciting first XP project • Extreme Programming Wiki (http://c2.com/cgi/wiki?ExtremeProgrammingRoadmap): This is Ward Cunningham’s site, which is focused on capturing and maintaining XP discussions and evolution It provides a great roadmap to just about every XP topic that you can think of, including the different practices,... XP projects, 27–35 Remove Parameters tool, function of, 106 Remove Product from Shopping Cart user story example with task owners and estimates, 144 reviewing and estimating story points for, 125 task breakdown for, 139–140 Rename tool code listing after invoking, 101 code listing before invoking, 100 renaming, a class, interface, method, or variable, 100 101 Reorder Parameters tool, function of, 106 107 ... up, 90–95 WebDashboard Properties dialog box for configuring the WebDashboard virtual directory, 93 enabling the default documents in, 94 WebDashboard site adding the mapping, 93 setting properties for, 92 website address Agile Alliance, 305 for details about NAnt, 51 for details about NUnit, 60 4800Index 5/24/06 8:48 PM Page 319 ■INDEX ■ X XP (Extreme Programming) See Extreme Programming (XP) XP business... tag, function of in CCNet, 85 exploration phase, of release planning, 27–33 Extract Interface tool, function of, 102 104 Extract Method tool code listing after invoking, 99 100 code listing before invoking, 98–99 function of, 98 100 Extreme Programming (XP) assembling your team, 19–26 assuming problems can be solved with simplicity, 7 critical path for putting the team together, 25 defined, 5–15 importance . examples. APPENDIX A ■ PREPARING YOUR DEVELOPMENT ENVIRONMENT 29 5 4 800 AppA.qrk 5 /22 /06 9 :04 PM Page 29 5 4 800 AppA.qrk 5 /22 /06 9 :04 PM Page 29 6 .NET C# Coding Conventions When all of the developers on. the system. • The test project holds all the unit tests for the application. APPENDIX B ■ .NET C# CODING CONVENTIONS 303 4 800 AppB 5/18 /06 10: 37 PM Page 303 4 800 AppB 5/18 /06 10: 37 PM Page 304 XP Resources XP. statement APPENDIX B ■ .NET C# CODING CONVENTIONS3 02 4 800 AppB 5/18 /06 10: 37 PM Page 3 02 Solution and Project Organization Every solution will have the following projects: • The business project holds only

Ngày đăng: 12/08/2014, 21:22