与科伯恩用例代码试验
我在写一些复杂的UI代码。 我决定采用科伯恩用例有鱼,风筝,和海平面(由Martin Fowler在他的著作“UML精粹”中讨论)。 我包裹科伯恩用例在静态C#对象,使我可以测试针对其表示在UI工作流步骤静态常量逻辑条件。 当时的想法是,你可以阅读代码,知道它在做什么,因为包装的对象和他们的公共contants通过命名空间给你的英语使用情况。
另外,我打算用反射泵出,其中包括所描述的用例的错误消息。 这个想法是,堆栈跟踪可能包括一些英文UI用例步骤....这原来是一个有趣的方式,实现了小型,伪轻质域语言而无需编写一个DSL编译器。 所以我的问题是这是否是做到这一点的好办法? 有没有人在那里做过类似的事情?
C#示例代码片段跟随
假设我们有有3个用户控件(有很多东西可点击)一些aspx页面。 用户必须在一个特定的用户控件(可能使某种选择的)点击东西,然后在UI必须在视觉线索的选择是成功的用户。 现在,在选择该项目,用户必须在其他用户控件中的一个内通过浏览一个gridview找到一个项目,然后选择一些东西。 这听起来像是一件容易的事,但管理的代码会变得非常恶劣。
在我的情况下,用户控制哪些是由主网页捕获所有发送的事件消息。 通过这种方式,页面表现得像UI事件的中央处理器,并可以跟踪,当用户点击左右会发生什么。
因此,在主aspx页面中,我们捕捉到第一个用户控件的事件。
using MyCompany.MyApp.Web.UseCases;
protected void MyFirstUserControl_SomeUIWorkflowRequestCommingIn(object sender, EventArgs e)
{
// some code here to respond and make "state" changes or whatever
//
// blah blah blah
// finally we have this (how did we know to call fish level method?? because we knew when we wrote the code to send the event in the user control)
UpdateUserInterfaceOnFishLevelUseCaseGoalSuccess(FishLevel.SomeNamedUIWorkflow.SelectedItemForPurchase)
}
protected void UpdateUserInterfaceOnFishLevelGoalSuccess(FishLevel.SomeNamedUIWorkflow goal)
{
switch (goal)
{
case FishLevel.SomeNamedUIWorkflow.NewMasterItemSelected:
//call some UI related methods here including methods for the other user controls if necessary....
break;
case FishLevel.SomeNamedUIWorkFlow.DrillDownOnDetails:
//call some UI related methods here including methods for the other user controls if necessary....
break;
case FishLevel.SomeNamedUIWorkFlow.CancelMultiSelect:
//call some UI related methods here including methods for the other user controls if necessary....
break;
// more cases...
}
}
}
//also we have
protected void UpdateUserInterfaceOnSeaLevelGoalSuccess(SeaLevel.SomeNamedUIWorkflow goal)
{
switch (goal)
{
case SeaLevel.CheckOutWorkflow.ChangedCreditCard:
// do stuff
// more cases...
}
}
}
因此,在MyCompany.MyApp.Web.UseCases命名空间,我们可能有这样的代码:
class SeaLevel...
class FishLevel...
class KiteLevel...
嵌入类工作流使用情况可能是内部类或静态方法或枚举或任何为您提供干净的命名空间。 我不记得我做过什么,但原来你得到的图片。