MILY: 'Courier New'">public enum ModeState { Initializing, Running }
public enum User { Authenticated, Administrator }
public enum Password { Correct, Incorrect }
public enum LoginStatus { Success, Failure } |
接下来模拟动作:
[Feature("Login")] public static class Login { public static Map<User, LoginStatus> ActiveLoginRequests = Map<User, LoginStatus>.EmptyMap;
[Requirement("Send username and password to the server to log in.")] [Action] public static void Login_Start(User user, Password password) { if (password == Password.Correct) ActiveLoginRequests = ActiveLoginRequests.Add(user, LoginStatus.Success); else ActiveLoginRequests = ActiveLoginRequests.Add(user, LoginStatus.Failure); }
public static bool Login_StartEnabled() { return WebSiteModel.State == ModeState.Running; }
public static bool Login_StartEnabled(User user) { return !ActiveLoginRequests.ContainsKey(user) && !WebSiteModel.UsersLoggedIn.Contains(user); }
[Requirement("It should be possible to log out from any page")] [Action] public static void Logout(User user) { WebSiteModel.UsersLoggedIn = WebSiteModel.UsersLoggedIn.Remove(user); } public static bool LogoutEnabled() { return WebSiteModel.State == ModeState.Running; }
public static bool LogoutEnabled(User user) { return WebSiteModel.UsersLoggedIn.Contains(user); } } |
上面的代码稍微解释一下,标注了[Action]的函数,就是抽象出来的程序所支持的动作,例如Logout;而在动作函数名后面加上Enabled的函数,是NModel用来判定指定的动作是否可以执行,例如LogoutEnabled函数。
文章来源于领测软件测试网 https://www.ltesting.net/