2012年4月16日 星期一

使用Sandcastle工具在Visual Studio環境產生Help文件(2012)

Create a Help file with Sandcastle in Visual Studio
The FORCE studio

使用Sandcastle工具在Visual Studio環境產生Help文件
作者:JB



Sandcastle is a tool used for integrating the XML comments in Visaul Studio project.
It can help creating a Help file such as HTML Helper format. Though installing Sandcastle is not an easy task, using it is quite simple.

1         Download
.NET Framework 3.5 SP1 or above version
Sandcastle
Sandcastle Help File Builder
HTML Help WorkshopFor HtmlHelp 1.x format
HTML Help 2.x For HtmlHelp 2.x format : However it cannot be downloaded individually. You must install Visual Studio 2005 SDK or Visual Studio 2008 SDK

2         Install
Screenshot_01 shows what we download.
First we install
Sandcastle.msi and then unzip SHFBGuidedInstallation_1934.zip (Screenshot_02, the file name depends on version ). 
Click SandcastleInstaller.exe to install it. The install process will check the necessary component step by step. Sorry for skipping the install details here.

Screenshot_01
 


Screenshot_02
 

Screenshot_03 (Installing)
 

3         Create HTML Helper
3.1      Open Sandcastle Help File Builder GUI.
Click
New Project


3.2      The New Project means the new project of Sandcastle, not the project in our Visaul Studio. Choose your destination folder and type the project name.


3.3      Since we create a new Sandcastle project, Project Explorer appears on the right side of the tool.
Right click on
Documentation Source… to add a existed .NET project.
Of course, this time we choose our Visual Studio project. (*.sin)



3.4      Next, lots of options showed up in Sandcastle.
I listed some common options in step 3.5.
After we finished setting up the options, just click
Build the help file and the Help file would be created. Simple and excellent!



3.5      Common options~
Build Framework Version(skip)
Build HelpFileFormatChoose Help file format.
Help File HelpTitle The title text in Help file.
Help File HtmlHelpNameThe Help file name.
Paths OutputPathThe Help file destination path.
Show Missing Tags ShowMissingNamespacesFalse

2012年4月1日 星期日

新款運動T-Shirt !

最舒適、排汗的運動T-Shirt!

Desinged for Parkour/Free running/X games/極限運動。
Pre-order now!


[C#] TDD從無到有的程式碼

TDD從無到有的程式碼

作者:The FORCE studio




本範例為利用Visual Studio 2010的單元測試功能,實現TDD(Test Driven Develop) 程式設計。


1          建立一個新專案(此以Windows Form應用程式專案為例)


2          在此方案加入一個『單元測試』專案:

2.1          選取上層功能列【測試】→【新增測試】→【單元測試精靈】




2.2          按下【確定】後,輸入你的測試專案名稱,按下【建立】。


2.3          接下來,會出現下面的畫面,要讓您選擇要做單元測試的Function。 這時候,我們還沒有任何Function,所以按下【取消】來結束精靈,當然這個測試專案還是會產生出來,只是沒有任何TestClass




3          所以目前我們有兩個專案了,一個是原來的WinForm專案,另一個就是剛建立的單元測試專案。 接下來選擇單元測試專案,加入一個新的TestClass
【加入】→【新增測試】→【基本單元測試】




4          按下【確定】後,VS就幫我們產生一個TestClass,裡面包含了一個空的TestMethod


namespace TDD_Example01_TestProject

{

         [TestClass]

             public class UnitTest1

             {

               [TestMethod]

               public void TestMethod1()

             {

           }

         }

}



4.1       我們現在可以開始寫TDD的測試程式碼了。
例如: 我想寫一個可以統計我剛買的書本的價錢的函式,所以我先打上
Book book1 = new Book();
Book book2 = new Book();
此時因為還沒建立Book類別,所以會出現下圖的錯誤訊息。




把滑鼠游標指到Book上,按下「Ctrl+.
Smart Tag
上會出現兩個選項:
a.
產生Book的類別 : 選擇這個會直接在測試專案加入一個Book.cs
b.
產生新的型別: 可以讓使用者選擇建立的檔案名稱及專案。

所以我們選擇【產生新的型別,然後建立Book類別。






按下確定後,VS會在TDD_Example01這個專案建立一個Book.cs,裡面包含了一個空的Book類別。


4.1.1 回到原來的測試程式碼,我們想到應該要給每一本書一個代號和書名吧! 於是修改程式碼如下:
Book book1 = new Book("book01", "這一生都是你的機會");
Book book2 = new Book("book02", "終極7000單字,這本最強!");
同樣的,VS告訴我們尚未建立建構函式!
一樣帶出Smart Tag選擇:
在 你的專案 中產生建構函式】



回到Book類別,已經看到VS幫我們加入了兩個property和建構函式。
private string p;
private string p_2;

public Book(string p, string p_2)
{
  this.p = p;
 
this.p_2 = p_2;
}

我們稍微自己把它整理如下:
private String BOOK_ID;
private String BOOK_NAME;

public Book(String sBook_id, String sBook_name)
{
 
BOOK_ID = sBook_id;
 
BOOK_NAME = sBook_name;
}



4.2    寫到這邊,我們應該感覺到了,除了測試程式碼之外,基本上原始的程式碼幾乎都是VS幫我們建立的。 是不是很方便呢?
最後我們只要再指定每本書本的價錢,建立一個統計價錢的函式就可以了。
最後的測試程式碼請參考:

[TestMethod]
public void MyTestMethod()
{
  Book book1 = new Book("book01", "這一生都是你的機會");
  Book book2 = new Book("book02", "終極7000單字,這本最強!");
  book1.BOOK_PRICE = 100;

 
book2.BOOK_PRICE = 200;
 
List<Book> ListBook = new List<Book>();
 
ListBook.Add(book1);
  ListBook.Add(book2);
  Double ActualRslt = Form1.Cal_Total_Price(ListBook);
  Double ExpectedRslt = 300;
  Assert.AreEqual(ExpectedRslt, ActualRslt);
}


至於BOOK_PRICE這個propertyCal_Total_Price統計價錢的函式,就不再累述囉。


5          寫完測試和專案的程式後,最後當然是執行測試程式,如果統計價錢的函式邏輯都正確的話,最後會得到下面的畫面! (END)





6       補充:
6.1         如果您是寫好專案的類別後,自行建立測試專案,請先將該專案的dll加入參考。